---
title: "Set up back in stock via API"
description: "Learn how to set up Klaviyo's back in stock product notification functionality via API."
url: "https://developers.klaviyo.com/en/docs/how_to_set_up_custom_back_in_stock"
category: "Build with Klaviyo"
lastUpdated: "2026-11-06"
related: ["https://developers.klaviyo.com/en/docs/llms.txt"]
---

# Set up back in stock via API

> This is the Markdown version of https://developers.klaviyo.com/en/docs/how_to_set_up_custom_back_in_stock

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

If you want to include Klaviyo's back in stock functionality in your application or custom platform, you can accomplish this by calling the [Create Back in Stock Subscription](https://developers.klaviyo.com/en/reference/create_back_in_stock_subscription.md) or [Create Client Back in Stock Subscription](https://developers.klaviyo.com/en/reference/create_client_back_in_stock_subscription.md) 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](https://help.klaviyo.com/hc/en-us/articles/115003872251-Building-a-Back-in-Stock-Flow) to ensure that profiles who subscribe to receive back in stock emails or text messages are notified.

> [!NOTE]
> These API endpoints are valid for Shopify integrations, BigCommerce integrations, Magento 2 integrations, Square integrations, Wix integrations, Salesforce Commerce Cloud integrations, accounts using our Catalogs API, or accounts with inventory-aware custom catalog feeds (custom catalogs that contain values for the `$inventory_quantity` field).

We have an endpoint that can be used from server-side contexts as well as one that can be called directly from the client, e.g., a browser. Whether you are using our [Catalog API](https://developers.klaviyo.com/en/reference/get_catalog_items.md) or one of our supported e-commerce integrations, you can use these endpoints to subscribe your shoppers to receive notifications when catalog variants are back in stock. 

Keep in mind that these endpoints will only be used to enqueue a profile to receive back in stock notifications. 

We do not require explicit consent to be recorded in order to send email back in stock notifications. If you want to ensure that an email will be sent even if a shopper has previously unsubscribed from marketing, we recommend you also subscribe the profile to a list using [Create Client Subscription](https://developers.klaviyo.com/en/reference/create_client_subscription.md) on the client and [Subscribe Profiles](https://developers.klaviyo.com/en/reference/bulk_subscribe_profiles.md) on the server. For SMS, you must always obtain explicit consent using [Create Client Subscription](https://developers.klaviyo.com/en/reference/create_client_subscription.md) on the client and [Subscribe Profiles](https://developers.klaviyo.com/en/reference/bulk_subscribe_profiles.md) on the server to be able to send the text notifications. To learn more about how consent works in Klaviyo, please review [our guide to collecting email and SMS consent](https://developers.klaviyo.com/en/docs/collect_email_and_sms_consent_via_api.md).

## Set up back in stock with an AI agent

```prompt Add back in stock sign-up to this store
Add a back in stock sign-up to this store that subscribes shoppers to Klaviyo back in stock notifications for a catalog variant.

First read https://developers.klaviyo.com/en/docs/how_to_set_up_custom_back_in_stock.md.

Ask me for these before you change anything, unless I've already given them:
- Where the sign-up should appear, and how the code knows a variant is out of stock.
- Server or browser. The server calls `POST https://a.klaviyo.com/api/back-in-stock-subscriptions` with a private API key; the browser calls `POST https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=<public API key>`.
- Channels: `EMAIL`, `SMS` or both.
- The variant ID format, `integrationType:::catalogId:::externalId` (for example `$shopify:::$default:::<variant ID>`), and which ID in this codebase is the `externalId`.
- For SMS, the ID of the list that records consent.

Then, following this codebase's language, framework and conventions:
1. Build the trigger and form. Their look and behaviour are up to this codebase.
2. On submit, send `data.type` `back-in-stock-subscription` with `attributes.profile.data` (type `profile`, with `email` or `phone_number`), `attributes.channels`, and `relationships.variant.data` (type `catalog-variant`, the composite ID), with `Content-Type: application/json` and a `revision` header (the guide uses `2024-06-15`). Server requests also need the authorization header from https://developers.klaviyo.com/en/reference/api_overview.
3. For SMS, once the shopper agrees, also record consent: Subscribe Profiles on the server, as the guide shows, or Create Client Subscription in the browser (see https://developers.klaviyo.com/en/reference/create_client_subscription).
4. Treat a 202 as success. Show the shopper clear messages for a 400 (invalid email or phone number) and a 404 `variant_not_found`.

Read a private key from the environment, never put it in browser code, and keep keys out of source control and logs. Don't build the back in stock flow; that's done in Klaviyo.

When you're done, tell me what you changed and how to test it with a real out-of-stock variant. Remind me that shoppers aren't notified until a back in stock flow is set up in Klaviyo.
```

## Inputs

1. **profile**  
   The profile.

2. **channels**  
   The preferred channels through which the shopper wants to receive back in stock notifications. 

3. **relationships.variant**  
   The catalog variant the shopper wants to receive. The `id` on this variant is a composite ID. The format of the `id` is: `integrationType:::catalogId:::externalId`, e.g. `$magento_two:::MAGENTO_TWO_WEBSITE_ID-MAGENTO_TWO_STORE_ID:::MAGENTO_TWO_VARIANT_ID` or `$shopify:::$default:::SHOPIFY_VARIANT_ID`.
   1. `integrationType`  
      One of `$custom`, `$shopify`, `$bigcommerce`, `$magento_two`, `$sfcc`, `$square`, or `$wix`.
   2. `catalogId`  
      Most catalog types in Klaviyo only support a single catalog. For all single-catalog integrations, use `$default`. For `$magento_two`, use your website ID followed by a "-" followed by your store ID, e.g. `1-1`.  Review [this document](https://magefan.com/blog/magento-2-get-store-information-programmatically) for more details on retrieving these values.  
   3. `externalId`:  
      The ID of the catalog variant in your external system.

## Server-side request

Revision and authorization headers are required for all server-side requests, per the [API Overview](https://developers.klaviyo.com/en/reference.md).

### Email example

To send subscription information to the server-side API, send a POST request to `https://a.klaviyo.com/api/back-in-stock-subscriptions`. The endpoint description can be found here: [Create Back in Stock Subscription](https://developers.klaviyo.com/en/reference/create_back_in_stock_subscription.md).

Example:

```javascript
{
  "data": {
    "type": "back-in-stock-subscription",
    "attributes": {
      "profile": {
        "data": {
            "type": "profile",
            "attributes": {
                "email": "matt.kemp@klaviyo-demo.com"
            }
        }
      },
      "channels": ["EMAIL"],
    },
    "relationships": {
      "variant": {
        "data": {
          "type": "catalog-variant",
          "id": "$shopify:::$default:::INSERT_SHOPIFY_CATALOG_VARIANT_ID"
        }
      }
    }
  }
}
```

If you also want to subscribe the profile to a list, send a separate POST request to the [Subscribe Profiles](https://developers.klaviyo.com/en/reference/bulk_subscribe_profiles.md) endpoint.

### SMS example

To send subscription information to the server-side API, send a POST request to `https://a.klaviyo.com/api/back-in-stock-subscriptions/`.

Example:

```javascript
{
  "data": {
    "type": "back-in-stock-subscription",
    "attributes": {
      "profile": {
        "data": {
            "type": "profile",
            "attributes": {
                "phone_number": "+15005550006",
            }
        }
      },
      "channels": ["SMS"],
    },
    "relationships": {
      "variant": {
        "data": {
          "type": "catalog-variant",
          "id": "$magento_two:::2-2:::INSERT_MAGENTO_TWO_CATALOG_VARIANT_ID"
        }
      }
    }
  }
}
```

You’ll also want to obtain SMS consent for this profile so that they can receive the notification. Send an additional request to [Subscribe Profiles](https://developers.klaviyo.com/en/reference/bulk_subscribe_profiles.md).

```javascript
{
  "data": {
    "type": "profile-subscription-bulk-create-job",
    "attributes": {
      "profiles": {
        "data": [
          {
            "type": "profile",
            "attributes": {
              "phone_number": "+15005550006",
              "subscriptions": {
                "sms": {
                  "marketing": {
                    "consent": "SUBSCRIBED"
                  }
                }
              }
            }
          }
        ]
      },
      "custom_source": "Back in Stock"
    },
    "relationships": {
      "list": {
        "data": {
          "type": "list",
          "id": "Y6nRLr"
        }
      }
    }
  }
}
```

## Client-side request

### Email example

To send subscription information to the client-side API, send a POST request to `https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=PUBLIC_API_KEY`. The endpoint description can be found here: [Create Client Back in Stock Subscription](https://developers.klaviyo.com/en/reference/create_client_back_in_stock_subscription.md).

The example payload is the same as the server-side payload. Here’s an example of how you could use `fetch` to send this request:

```javascript
const payload = {
  "data": {
    "type": "back-in-stock-subscription",
    "attributes": {
      "profile": {
        "data": {
            "type": "profile",
            "attributes": {
                "email": "matt.kemp@klaviyo-demo.com",
            }
        }
      },
      "channels": ["EMAIL"],
    },
    "relationships": {
      "variant": {
        "data": {
          "type": "catalog-variant",
          "id": "$shopify:::$default:::INSERT_SHOPIFY_CATALOG_VARIANT_ID"
        }
      }
    }
  }
}

var requestOptions = {
    method: 'POST',
    headers: {
      "Content-Type": "application/json",
      "revision":"2024-06-15"
    },
    body: JSON.stringify(payload),
};

fetch("https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=PUBLIC_API_KEY",requestOptions)
    .then(result => console.log(result))
    .catch(error => console.log('error', error));
```

If you also want to subscribe the profile to a list, send a separate POST request to the [Create Client Subscription](https://developers.klaviyo.com/en/reference/create_client_subscription.md) endpoint.

### SMS example

To send subscription information to the client-side API, use a POST request to `https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=PUBLIC_API_KEY`, where `PUBLIC_API_KEY` is your public API key.

Example:

```javascript
const payload = {
  "data": {
    "type": "back-in-stock-subscription",
    "attributes": {
      "profile": {
        "data": {
            "type": "profile",
            "attributes": {
                "phone_number": "+15005550006",
            }
        }
      },
      "channels": ["SMS"],
    },
    "relationships": {
      "variant": {
        "data": {
          "type": "catalog-variant",
          "id": "$magento_two:::2-2:::INSERT_MAGENTO_TWO_CATALOG_VARIANT_ID"
        }
      }
    }
  }
}

var requestOptions = {
    method: 'POST',
    headers: {
      "Content-Type": "application/json",
      "revision":"2024-06-15"
    },
    body: JSON.stringify(payload),
};

fetch("https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=PUBLIC_API_KEY",requestOptions)
    .then(result => console.log(result))
    .catch(error => console.log('error', error));
```

You’ll also want to obtain SMS consent for this profile so that they can receive the notification. Send an additional request to the [Create Client Subscription](https://developers.klaviyo.com/en/reference/create_client_subscription.md) endpoint.

```javascript
const payload = {
  "data": {
    "type": "subscription",
    "attributes": {
      "profile": {
        "data": {
          "type": "profile",
          "attributes": {
            "phone_number": "+15005550006"
          }
        }
      },
      "custom_source": "Back in Stock"
    },
    "relationships": {
      "list": {
        "data": {
          "type": "list",
          "id": "Y6nRLr"
        }
      }
    }
  }
}

var requestOptions = {
    method: 'POST',
    headers: {
      "Content-Type": "application/json",
      "revision":"2024-06-15"
    },
    body: JSON.stringify(payload),
};

fetch("https://a.klaviyo.com/client/subscriptions/?company_id=PUBLIC_API_KEY",requestOptions)
    .then(result => console.log(result))
    .catch(error => console.log('error', error));
```

## API responses

### Success

When your request is accepted via our API, you’ll receive a 202 with no response body.

### Error cases

Invalid email address or phone number:

```json
{
    "errors": [
        {
            "id": "0dbfce59-0d68-442d-98c5-5b834b01e28c",
            "status": 400,
            "code": "invalid",
            "title": "Invalid input.",
            "detail": "Invalid email address",
            "source": {
                "pointer": "/data/attributes/email"
            },
            "meta": {}
        }
    ]
}
```

```json
{
    "errors": [
        {
            "id": "ad5299f0-0ada-4158-a7bb-10a086895c50",
            "status": 400,
            "code": "invalid",
            "title": "Invalid input.",
            "detail": "Invalid phone number format (Example of a valid format: +12345678901)",
            "source": {
                "pointer": "/data/attributes/phone_number"
            },
            "meta": {}
        }
    ]
}
```

Invalid auth, client endpoint:

```json
{
    "errors": [
        {
            "id": "c7d1ff60-bd2f-4189-be9e-9393e26b9f01",
            "status": 400,
            "code": "invalid",
            "title": "Invalid input.",
            "detail": "Invalid company ID TESTER",
            "source": {
                "pointer": "/data"
            },
            "meta": {}
        }
    ]
}
```

Invalid auth, server endpoint:

```json
{
    "errors": [
        {
            "id": "64a2bdf8-5b28-4f05-9435-cb7cd423e2b1",
            "status": 401,
            "code": "not_authenticated",
            "title": "Authentication credentials were not provided.",
            "detail": "Missing or invalid private key.",
            "source": {
                "pointer": "/data/"
            }
        }
    ]
}
```

Invalid variant ID: If an invalid variant ID is included in a request, the API will return an error response. No event will be created for the profile and the customer will not be queued to receive a back in stock message.

```json
{
    "errors": [
        {
            "id": "32227605-a762-4a9a-9787-c989c1fec07d",
            "status": 404,
            "code": "variant_not_found",
            "title": "The variant in your relationship payload does not exist",
            "detail": "The variant in your relationship payload does not exist",
            "source": {
                "pointer": "/data/relationships/variant/data/id"
            },
            "meta": {}
        }
    ]
}
```

## Duplicate subscriptions

It is not possible to submit multiple events for a profile for the same variant. If multiple requests are submitted for the same profile on the same variant, only the first will be accepted. There is no limit to the number of unique variants that a profile can subscribe to.

After an individual receives a notification  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.

> [!WARNING]
> Subscribers will not be notified when an item is restocked if you do not first set up a back in stock flow. Check out the resources below to get started.

## Additional resources

- [How to build a back in stock flow](https://help.klaviyo.com/hc/en-us/articles/115003872251)
- [How to configure back in stock alert emails](https://help.klaviyo.com/hc/en-us/articles/360051612751)
