Headless Usage

This is an advanced piece of documentation for developers.

To follow this article you may need experience using JavaScript, CSS and Liquid.

published February 27, 2020 | updated February 27, 2020

You can use Stockbot in a ‘headless’ manner, in this case you would have your own code to collect email addresses and phone numbers.

Sample Request

You will want to make a POST request of the following form. You must set your store’s myshopify.com domain in a X-Shopify-Domain header so we know where your request originates from.

Here we are using CURL but you could also make requests from any language of your choice.

curl https://stockbot.oostapps.com/api/public/v1/watches
    -X POST \
    -H "X-Shopify-Domain: example.myshopify.com" \
    -H "Accept: application/json"

The body of your request should be as follows.

{
    "email": "[email protected]",
    "product_id": 1111111111,
    "variant_id": 1111111111,
    "phone": "+44155 555 555",
    "newsletter": true
}

Field Descriptions

You must provide all required fields, and should only include optional values when they have a valid value.

Field Type Required Description
email string yes The email address to subscribe for email notifications
product_id integer yes Product ID to make the subscription to
variant_id integer yes Specific variant ID that is out of stock, required even if there in only one variant
phone string no Optional phone number to subscribe to receive SMS notifications, the number must include country code
newsletter string no Has the customer agreed to accept newsletter marketing? Defaults to false if omitted

Sample Response

We validate data you provide and return an appropriate response. Note that if you provide incorrect product or variant ID you will still get a 200 response because we check against the Shopify API asynchronously.

200 Response

The data you sent was valid and we will attempt to subscribe the customer.

200 Done

400 Response

If you do not provide the X-Shopify-Domain header you will receive a 400 Bad Request response.

400 Bad Request
{
  "message": "You did not provide a shopify domain",
  "errors": {
    "X-Shopify-Domain": [
      "You must provide a X-Shopify-Domain header"
    ]
  }
}

404 Response

If you provide a shopify domain that does not have stockbot installed you will receive a 404 Not Found response.

404 Not Found
{
  "message": "Shop not found"
}

422 Response

A 422 will be returned if the data provided does not match against our required formats, or a field is missing.

422 Unprocessible Entity
{
    "message": "The given data was invalid.",
    "errors" {
        "product_id": [
            "The product id field is required."
        ],
        "variant_id": [
            "The variant id field is required."
        ],
        "phone": [
            "The phone number is not a valid phone number, remember to include the country code"
        ],
        "email": [
            "The email field is required"
        ]
    }
}

If you still need help please contact us.

Related Articles

Facebook Messenger Integration

Stockbot Messenger integration allows you to send back in stock notifications to customers straight to their Facebook Messenger inbox. This provides better open rates than email as well as opening a conversation with the customer for you to manually send messages to them. Requirements The only requirements for the integration are that your company has a Facebook page, and you have management access to that page. Setup To setup your Facebook page there are two simple steps you must complete.

Headless Usage

You can use Stockbot in a ‘headless’ manner, in this case you would have your own code to collect email addresses and phone numbers. Sample Request You will want to make a POST request of the following form. You must set your store’s myshopify.com domain in a X-Shopify-Domain header so we know where your request originates from. Here we are using CURL but you could also make requests from any language of your choice.

Integrations

Currently we support Mailchimp integration which allows you to add customers to a selected audience in Mailchimp if they choose to when signing up for email notifications. Mailchimp To connect your Mailchimp account you can follow the steps outlined here. Note that your audience cannot have any required fields apart from email address. If you do integration will not work because we only collect the email address from your customers.

Installation

First Installation 1. Copy the installation code You will need to add this code to your theme so our app will know where to display the signup form for customers. {% capture the_snippet_content %}{% include 'oost_stockbot_inline_settings' %}{% endcapture %} {% unless the_snippet_content contains "Liquid error" %}{% include 'oost_stockbot_inline_settings' %} {% endunless %} 2. Add the code to your product form The code must be added to the template that displays the product form.