Set up back in stock via API

Learn how to set up Klaviyo's back in stock functionality via API.

❗️

This guide refers to Klaviyo's v1/v2 legacy APIs.

We are in the process of updating these guides, please check back later! For more information about the differences between legacy and new APIs, check out the comparison chart and new API overview.

If you want to include Klaviyo's back in stock functionality in your application or custom platform, you can accomplish this by calling the Subscribe endpoint from your app. You have full control of (and responsibility for) when, where, and how the trigger button appears; the appearance, text, and behavior of the modal; and all other aspects of the feature's behavior and appearance within your application.

Once you are successfully sending back in stock events to Klaviyo, you can set up a back in stock flow to ensure that profiles who subscribe to receive back in stock emails are notified.

📘

Info

This API endpoint is only valid for Shopify integrations, BigCommerce integrations, Magento 2 integrations, or accounts with inventory-aware custom catalog feeds.

Your POST request from the app must include:

  1. a - Your public Klaviyo API Key
  2. email - The email address entered by the subscriber, correctly formatted and valid
  3. variant - The product's variant ID
  4. platform - The platform ID, such as shopify, bigcommerce, magento_two, or api

To subscribe a customer to a list as part of the Back In Stock workflow, you will need to make a separate, additional call to the List API.

API call format

curl 'https://a.klaviyo.com/api/v1/catalog/subscribe'
--data 'a=AccountID&[email protected]&variant=5000149172256&platform=shopify'

Successful call & response

curl 'https://a.klaviyo.com/api/v1/catalog/subscribe' 
--data 'a=AccountID&[email protected]&variant=44222393030&platform=shopify'
{"email": "[email protected]", "success": true}

The correct Account ID and a valid email address must be included to receive a successful response.

Magento 2 considerations

The following cURL command is an example Back in Stock API request for customers with a Magento 2 integration. To implement custom back in stock for Magento 2, we recommend you have the following:

  • Form or input field on the product page that renders when an item is out of stock. The form should collect email addresses of customers who want to be notified when an item gets restocked.
  • On form submission, send the data to Klaviyo's back in stock API. When a customer submits the form, make a call to the API, subscribing the customer to restock notifications.
  • Once the data has been communicated to the API, configure automated back in stock alert notifications.
curl -X POST 'http://a.klaviyo.com/onsite/components/back-in-stock/subscribe' \
  -F a="ACCOUNT_ID" \
  -F email="EMAIL" \
  -F variant="ID" \
  -F platform="magento_two" \
  -F store="STORE_NUMBER"
$.ajax({
    type: "POST",
    url: "https://a.klaviyo.com/onsite/components/back-in-stock/subscribe",
    data: {
        a: "ACCOUNT_ID", // Klaviyo account public token
        email: "EMAIL", // Email address entered in form
        variant: VARIANT_ID, // ID of the out of stock product variant about which customer wants to be notified.
        platform: "magento_two", 
        store: "STORE_NUMBER", // The Magento Store ID
    },
    success: function(response){
        console.log(response)
    }
})

Errors

Invalid email address

curl 'https://a.klaviyo.com/api/v1/catalog/subscribe' 
--data 'a=AccountID&[email protected]&variant=44221714950&platform=shopify'
{"errors": ["There was something wrong with your request. Please try again."], "data": {}, "success": false}

Invalid public API key

curl 'https://a.klaviyo.com/api/v1/catalog/subscribe' 
--data 'a=BadKey&[email protected]&variant=44221714950&platform=shopify'
{"errors": ["There was something wrong with your request. Please try again."], "data": {}, "success": false}

Invalid variant ID

The API does not validate variant IDs. If an invalid variant ID is included in a request, the API will return a standard success response. No event will be created for the profile and the customer will not be queued to receive a back in stock message.

Duplicate subscription requests

If multiple requests are submitted for the same email address on the same variant, only the first will be accepted. It is not possible to submit multiple events for a profile on the same variant.

There is no limit to the number of unique variants that a profile can subscribe to. A single person can sign up to be notified for hundreds or thousands of unique variants.

Clearing a subscription

After an individual receives an email notifying them that a specific variant is back in stock, their existing subscription is cleared. They are then able to sign up for another subscription on that same variant.  It is not possible to have multiple concurrent subscriptions to the same variant for a single profile.

Please note that no subscribers will be notified when an item is restocked if you do not first set up a back in stock flow.