Here Data transfer from Kwizbot via send_request we figured out how to send a request using send_request send a request, now let's look at how to process the response.

We will use two services as a test API

  1. http://worldclockapi.com/api/json/est/now - The API returns a simple JSON object, we'll start with it
  2. https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5 - API returns an array of JSON objects, which is more difficult to process

This manual covers the following cases:

Processing JSON object in response

Let's make this action configuration

{
  "url": "<http://worldclockapi.com/api/json/est/now>",
  "method": "GET",
  "response_mapping": {
    "dayOfTheWeek": "today"
  }
}

And this script configuration. What came before and what will happen after the request is not very important to us, our task is to display what day of the week is today in the placeholder today.

The mapping parametr is responsible for which placeholder will be written to which parameter from the response. Everything is pretty clear here: the dayOfTheWeek parameter after the response will be available with the {{today}} placeholder.

Processing an array of objects in a response

Let's move on to getting the exchange rate. Let's make the following action configuration:

{
  "url": "<https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5>",
  "method": "GET",
  "response_mapping": {
    "list_obj": {
      "text": "{{ccy}}/{{base_ccy}}",
      "value": "{{buy}}"
    }
  },
	"save_mapped_list_obj": "currency_mapped_obj"
}

We need this script configuration:

The "list" block must be configured like this