Create an API Task (API Task in form)

Create an API Task with the packages available in the Control Room in the API Task editor. You can create an API Task with actions from packages that are supported on Automation 360 Cloud.

Prerequisites

You must have a Bot Creator license.
This topic describes how to create an API Task by using an API that takes a ZIP code in the USA as input and returns the place and state name as output. You can create an API Task with the actions that are specific to your use case.

Procedure

  1. Log in to your instance of the Automation Anywhere Control Room as a Bot creator.
  2. Create a new API Task:
    1. From the left pane, click Automation.
    2. Click Create new > API Task.
    3. In the Create API Task window, enter the API Task name.
    4. Accept the default folder location: \Bots\.
      To change where your API Task is stored, click Choose and follow the prompts.
    5. Click Create & edit.
  3. Create a ZipCode variable as an input that will be used in the ZIP code URL.
  4. 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.
    1. Double-click or drag the REST Web Services > Get method action.
      Rest Web Services - Get method
    2. 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.

    3. 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.
    4. 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.
  5. From the Actions pane, drag the JSON > Start session action and drop it into the canvas below the REST Web Services action.
    1. In the Data Source field, select Text and enter$pDictZipCodeApiResponse{Body}$.
    2. In the JSON Object session field, selection Local session and enter Default.

      API Task Dictionary
      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"
              }
          ]
      }
  6. Extract the place name from the JSON.
    1. From the Actions pane, drag the Json > Get node value action and drop it into the canvas below the Json > State session action.
    2. Specify the nodes to be extracted. For example, to extract the place, you can use places[0].["place name"]
    3. Create a variable Place and assign the output to this variable.
  7. Extract the state from the JSON.
    1. From the Actions pane, drag the Json > Get node value action and drop it into the canvas below the Json > State session action.
    2. Specify the nodes to be extracted. For example, to extract the place, you can use places[0].["state"]
    3. Create a variable State and assign the output to this variable.
  8. 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.