Handling HTTP Responses

HTTP Responses are special subworkflows in Arigato. They are added automatically during the setup process for Shopify API Request actions and the  Send a HTTP Request actions. This special workflow allows you to parse and act upon the raw JSON response from another system, such as the Shopify API or any other system.

Conditions

This workflow type has unique conditions based on the Response body, headers, status code, and JSON.

It is recommended that if you only want to act when the response comes back "OK" to add a condition for "HTTP Response / Success is True". This condition ensures the HTTP status code is between 200 to 299 (generally considered to be OK).

However, you can also handle ANY status code, so if you want to add separate condition groups with unique actions for status codes "404 Not Found" or "403 Forbidden" you can.

The Body Content conditions treats the raw body as a string. This may be a good option if the response is NOT JSON, or if you only care about parsing the raw body as a string.

JSON Condition

The JSON condition allows you make conditions based on the JSON content in the response. Let's look at an example JSON response to understand how to make conditions:

{
  "orders": [
    {"total_price":"25.99", "email":"user@domain.com"},
    {"total_price":"14.00", "email":"user2@domain.com"},
    {"total_price":"84.50", "email":""}
  ]
}

The first thing to decide is what property you want to check. The way to enter the property path is to use the syntax: "level1.level2.level3". If any of these levels are an array, such as "orders" is in our example, then the data set will be compared as an array.

So if we want to perform a check on "orders.total_price" you can think of the data being flattened into:

["25.99", "14.00", "84.50"]

Next you need to control how you want to check the array of data. Do you want the condition to match at least one value, no values, or ALL values?

Screenshot_2020-03-25_13.15.44.png

Next you'll need to select the appropriate field type for the data, which controls what condition options are available. In our example we'll select the "Number" field.

Screenshot_2020-03-25_13.23.51.png

In our example, we're going to check that at least one order in the response is over $50.00.

Screenshot_2020-03-25_13.28.27.png

JSON Token

Next, I want to parse and send some of the data from the JSON response in a Slack message. We can see in the Token Picker there is already a helper for the JSON field.

In my Slack action, I'm going to loop over the orders array to total up the "total_price" field, and send that value to me. The key is that the  http_response.json token contains the JSON response object.

{% set orders_total = 0 %}

{% for order in http_response.json.orders %}
  {% set orders_total = orders_total + order.total_price %}
{% endfor %}
Orders Total Value: ${{ orders_total | number_format(2) }}