Using the Post method

Use the Post method actions from the REST Web Service package to create new resources in the URI.

This example uses endpoints from the Swagger Petstore sample API (Petstore) to demonstrate using Post method action to add data to the Petstore database.

Procedure

  1. Create a new bot.
    1. Log in to your instance of the Control Room.
    2. On the left panel, click Automation.
    3. Click Create new > Bot.
    4. In the Create Task Bot window, enter the bot name.
    5. Accept the default folder location: \Bots\
      To change the default bot storage location, click Choose and follow the prompts.
    6. Click Create and edit.
  2. Use the Post method action to send data to a server. In this example, a new pet is added to the store.
    1. Double-click or drag the REST Web Services > Post method action.REST Web Services - Post method
    2. Enter the following URI:
      https://petstore.swagger.io/v2/store/order
    3. Proxy Configuration: Do one of the following:
      • System: Under Authentication Mode select the authentication. In this example, select No Authentication as this endpoint does not require authentication.
        Note: Typically endpoint requires authentication to ensure that only authorized applications are able to access the data. Select an appropriate authentication mechanism to allow access to the endpoint you want to access.
      • Custom: This option allows you to configure custom proxy settings within the actions of REST Web Service. For more information, see REST Web Service package .
    4. Select the Content type that indicates in which format the data is sent to. An incoming request can have an entity attached to it. The Content type determines the type of the request. Some common Content types include such as: application/x-www-form-urlencoded, JSON (application/json), and XML (application/XML). In this example, select JSON (application/json), copy and paste the following into the Custom parameters field:
      {
        "id": 0,
        "petId": 0,
        "quantity": 0,
        "shipDate": "2022-04-20T22:08:11.977Z",
        "status": "placed",
        "complete": true
      }
    5. Add substitution: Allows you to enter variables in the REST request body. A variable is a symbolic representation of data, and it enables you to access a value without having to enter it manually wherever you need it. For example, consider the following REST body request:
      {
         "name":"{{name}}",
         "email":"{{email}}",
         "status":"Active"
      }
      In the above request body, you can replace the variables enclosed within double braces by clicking Add substitution and adding the required values.
    6. Enter a time in milliseconds for the action to complete. You can leave it to the default 60,000.
    7. Create the variable Output in the Assign the output to a variable field. For more information on creating a variable, see Create a variable.
  3. Insert a Message box action to see the response body.
    1. Double-click or drag the Log to file action.
    2. In the Enter the message to display field, enter $Output{Body}$.
  4. Click Save and then click Run.
    The bot displays the response in the message box.