Create an API Task
- Updated: 2024/08/19
Create an API Task
You can create an API Task with various packages that are supported on Automation Anywhere Control Room.
Prerequisites
Procedure
- Log in to your instance of the Automation Anywhere Control Room as a Bot creator.
-
Create a new API Task:
- From the left pane, click Automation.
- Click Create new > API Task.
- In the Create API Task window, enter the API Task name.
-
Accept the default folder location: \Bots\.
To change where your API Task is stored, click Choose and follow the prompts.
- Click Create & edit.
- Create a ZipCode variable as an input that will be used in the ZIP code URL.
-
Use the Get method
action to retrieve the place and state of a ZIP
code.
Note: Pre-built packages are available for most common enterprise applications. For a list of supported packages, see Table 1.
-
Double-click or drag the REST Web Services > Get method
action.
-
Enter the following URI. $ZipCode$ in the URI is the input
variable created in Step 3.
https://api.zippopotam.us/us/$ZipCode$
Note:You can call multiple APIs within a single API Task. This can simplify your automation and reduce the need for multiple separate tasks. For instance, you can call API 1 to fetch product data, API 2 to fetch pricing data, and then API 3 to create a quotation within the same API Task.
-
In the Authentication Mode drop-down list, select
No Authentication because this endpoint does not
require authentication.
Note: Typically, endpoints require authentication to ensure that only authorized applications can access the data. Select an appropriate authentication mechanism to allow access to the endpoint you want to access.
-
Create the variable
pDictZipCodeApiResponse
in the Assign the output to a variable field. For more information on creating a variable, see Create a variable.Note:- The complete API JSON response is assigned to this dictionary
variable:
pDictZipCodeApiResponse
. - The following variable types are not supported for API Tasks: File, Window, and Form.
- The complete API JSON response is assigned to this dictionary
variable:
-
Double-click or drag the REST Web Services > Get method
action.
-
From the Actions pane, drag the JSON > Start session action and drop it into the canvas below the REST Web
Services action.
-
In the Data Source field, select
Text and
enter
$pDictZipCodeApiResponse{Body}$
. -
In the JSON Object session field, selection
Local session and enter
Default
.
You now have the entire Body. The next task is to extract the required fields from the body. The following shows a sample JSON Body:{ "post code": "90210", "country": "United States", "country abbreviation": "US", "places": [ { "place name": "Beverly Hills", "longitude": "-118.4065", "state": "California", "state abbreviation": "CA", "latitude": "34.0901" } ] }
-
In the Data Source field, select
Text and
enter
-
Extract the
place name
from the JSON.- From the Actions pane, drag the Json > Get node value action and drop it into the canvas below the Json > State session action.
-
Specify the nodes to be extracted. For example, to extract the place, you can
use
places[0].["place name"]
- Create a variable Place and assign the output to this variable.
-
Extract the
state
from the JSON.- From the Actions pane, drag the Json > Get node value action and drop it into the canvas below the Json > State session action.
-
Specify the nodes to be extracted. For example, to extract the place, you can
use
places[0].["state"]
- Create a variable State and assign the output to this variable.
-
Click Save.
To test the API Task, click the Debugger. While debugging, the local device is used to execute the API Task. The API Task created in this sample retrieves the Place and State for any ZIP code inputs.