Action Configuration

By default the action label will show the method and path that is entered:

You can override the label to help describe what your custom API request is actually for:

HTTP Method

This is the method required to make the HTTP call to the Shopify API. Typically:

GET: Get one or more pieces of data.

PUT: Update an existing piece of data.

POST: Create a new piece of data.

DELETE: Delete an existing piece of data.

API Path

The Shopify API Request action type will automatically build most of the URL and required HTTP headers in order to make successful API requests. The API Path option starts with the resource type, such as:

customers

customers/{customer.id}

orders

products/{product.id}/variants

locations

You do not need a starting slash, https, or query parameters. Query parameters are talked about below.

Data (format as JSON)

Data that needs to be passed to the API request. If the request uses the GET method, the JSON is passed to the request as typical query parameters.

Example of fetching a product by handle and returning only specific fields:

Example of creating a new product and using some product tokens that we have available:

Paginated GET Requests

If you want to fetch more than 250 items in a GET request you will need to specify the limit in the Data field. A maximum of 2,500 items can be fetched at a time (this performs 10 API requests). If a limit is set over 2,500 you will get an error. Example:

{"limit": 1000}

Please note that each API request will count towards your Shopify API call limit. Performing too many API calls in a short period may result in errors.

Handling the API Response

Depending on what API call you're making you can handle the response in two different ways. If the request you're making returns one or more Shopify resources you can use the "Run the response object(s) through a workflow" option. With this option selected you must select the object type that is being returned in the response, and you can then send that data to a subworkflow.

If you select the option "Run the response JSON through a workflow", the raw JSON response is passed to a unique HTTP Response workflow.

Option: Run the response JSON through a workflow

With this option selected a new field called "Additional Data (format as JSON)" is added which allows you to pass additional data to the subworkflow. Essentially, this added data is merged with the API response and passed to the HTTP Response workflow.

Let's take a look at a real example...

Example: Track a Customer's Order Total Average

For this example workflow we want to update a customer's order total average whenever a new order is paid.

1. Create a new workflow that runs on Order / Paid.

2. Add a Shopify API Request action.

3. Make a GET request to fetch all orders for the customer:

customers/{{ order.customer.id }}/orders

4. We only need the total_price field from the order, so we can add that to the Data JSON setting:

{ "fields":"total_price"}

5. What do you want to do with the response? We want to "Run the response JSON through a workflow".

6. In the Additional Data field we want to pass the customer_id to the subworkflow. If we don't pass the information into the subworkflow we won't know which customer the order data is associated with.

{ "customer_id": "{{ order.customer.id }}"}

7. We can then click the "Create New Workflow" button to begin setting up the HTTP Response Workflow.

8. In the HTTP Response workflow we're going to add a couple of conditions. First, let's make sure the HTTP Request was successful, so we'll add a condition that HTTP Response / Success is True.

9. Next, we want to make sure we got a value back for under "orders.total_price". So we can add a condition based on a value in the response JSON object:

JSON Encoding Correctly

When sending data to Shopify formatted as JSON, some types of fields will need to be JSON-encoded to ensure they don't cause an issue.

For example, when creating a new product with the product description (body_html) filled in, we use two filters on the token, raw and to_json.

The raw filter will ensure our HTML is not encoded before sending it. It's the difference between sending the raw string <br> or the encoded string &lt;br&gt;.

The to_json filter ensures that the contents of the string are safely encoded for HTML use. For example, if our body_html token had "quotes" in it, that would cause an error with our value. By using the to_json filter the "quotes" are correctly encoded to \"quotes\".

In our boolean field, we use the to_json filter to ensure that the token renders the correct true or false JSON value.

Also, notice that in our JSON the keys and values have quotes around them. Integer and boolean values should not have quotes around them.