Appearance
API
The API task block consists of an input and a Success and Error output. The API block has 4 configuration items:
- Contract: This is a reference to a contract asset
- Override Params: This configuration button allows overriding the default parameters in the referenced contract
- Override Body: This configuration button allows overriding the default parameters in the referenced contract
- Put Result into Variable: The result of the API call needs to be put somewhere and this configuration button allows the user to designate a mission variable.
If the input to the API block is triggered the API contract will load the configuration from the referenced contract. The block will then overwrite the contract Parameters and Body with the overrides, if they are set to something. If Override Params or Override Body are empty, they are ignored. The API block will then call the endpoint with all the settings invoked and when a response is returned, that response will be placed into the mission variable specified. If the API call resulted in an HTTP response code of 200 the Success output will be triggered. Any other code will trigger the Error output.
Examples
Here is a simple example of a mission that uses an API task block to get a JSON formatted weather report and log it to the mission log. Here is what the API contract looks like. Contracts are setup in the Contract Editor that can be found in the main menu of RobotAgentz.
Here is the example mission. The flow of this mission is to use the API block to request information from the weather api. When the response is returned either the Success or Failed output will be triggered. If the Success output is triggered, the mission flow proceeds to a mission log block which will write API Success to the mission log and then will proceed to a second mission log block to log the actual response of the API call. If the API block failed output is triggered then the mission flow triggers the log block to write API failed. Both branches than proceed to the exit block and the mission is completed.
Use Cases
The API task block is a powerful generic tool to integrate to external systems. The contract editor allows for a broad range of integrations with request types, parameter, headers and authentication types. Some examples of use cases are:
- Accessing public API's for JSON data structures that can be parse or modified by JSON modifier task blocks or RoboDocs
- Read web pages and use other task block tools to parse keywords from the raw page data.
- Access local or proprietary systems to keep critical data behind an API.
Copy / Settings / Docs
Each task block has three buttons named Copy, Settings, and Help.
- Copy: This will duplicate the task block with all the current settings.
- Settings: Settings will show a dialog that allows some added configuration for the block
- Note: This allows you to add a text note for the current block. This note will appear in the log file if the Block Loggin option is enabled.
- Transition Out Time: Each block can specify a delay in milliseconds that it will wait after an output trigger is activated. This feature is generally not used but is avilable for more granular flow control of the mission if needed.
- Block Logging: If this is enabled then the internal logging of the block is turned on and will be sent to the mission log. Each block has different amounts of internal logging which can make mission logs become large in some cases. Users generally do not enable this feature because of the limits to data storage.