HTML Diff
20 added 20 removed
Original 2026-01-01
Modified 2026-03-10
1 <p><em>Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers &amp; technically-advanced users.</em></p>
1 <p><em>Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers &amp; technically-advanced users.</em></p>
2 - <p><strong><em>Note:</em></strong><em>We do our best to make sure any code and API references are accurate and current when this is published, but you might need to update code and it’s always a best practice to leverage our</em><a><em>latest API versions</em></a><em>. If you have questions, feel free to hop over to our</em><a><em>Developer Community</em></a><em>.</em></p>
2 + <p><em><strong>Note:</strong>We do our best to make sure any code and API references are accurate and current when this is published, but you might need to update code and it’s always a best practice to leverage our<a>latest API versions</a>. If you have questions, feel free to hop over to our<a>Developer Community</a>.</em></p>
3 <p>What you’ll learn</p>
3 <p>What you’ll learn</p>
4 <p>How to use Google Sheets to backfill Back in Stock subscribers to Klaviyo as part of an onboarding or migration project.</p>
4 <p>How to use Google Sheets to backfill Back in Stock subscribers to Klaviyo as part of an onboarding or migration project.</p>
5 <p>Why it matters</p>
5 <p>Why it matters</p>
6 <p>Back in Stock subscribers have explicitly allowed you to contact them when a product that they want to purchase is available to buy. You do not want to lose these leads when migrating to Klaviyo. This guide will outline how easy it is to migrate the data.</p>
6 <p>Back in Stock subscribers have explicitly allowed you to contact them when a product that they want to purchase is available to buy. You do not want to lose these leads when migrating to Klaviyo. This guide will outline how easy it is to migrate the data.</p>
7 <p>Level of sophistication</p>
7 <p>Level of sophistication</p>
8 <p>Moderate</p>
8 <p>Moderate</p>
9 <h2>Introduction</h2>
9 <h2>Introduction</h2>
10 <p>Back in Stock notifications are hugely important in today’s retail environment as they signify that your product is in such demand that people want to be notified as soon as they are able to purchase it.</p>
10 <p>Back in Stock notifications are hugely important in today’s retail environment as they signify that your product is in such demand that people want to be notified as soon as they are able to purchase it.</p>
11 <p>Due to the importance of these subscriber lists, it is imperative that we handle them with care. During any transformation project, be it migration to a new platform, or introduction of new markets or changes to the data model, data consistency is key.</p>
11 <p>Due to the importance of these subscriber lists, it is imperative that we handle them with care. During any transformation project, be it migration to a new platform, or introduction of new markets or changes to the data model, data consistency is key.</p>
12 - <p>Here we will look at how to create a Google Script to push data from a Google Sheet of Back in Stock subscribers into Klaviyo by utilising the <a>Back in Stock API</a>.</p>
12 + <p>Here we will look at how to create a Google Script to push data from a Google Sheet of Back in Stock subscribers into Klaviyo by utilising the<a>Back in Stock API</a>.</p>
13 <h2>Background</h2>
13 <h2>Background</h2>
14 <p>In order to import BiS (Back in Stock) into Klaviyo, it is important to understand how BiS works and its components:</p>
14 <p>In order to import BiS (Back in Stock) into Klaviyo, it is important to understand how BiS works and its components:</p>
15 <h3>Custom catalog</h3>
15 <h3>Custom catalog</h3>
16 - <p>Within Klaviyo, <a>custom catalog</a> items are stored as either ‘products’ or ‘variants’, depending on your integration method. The catalog becomes ‘inventory aware’ once <a>inventory data is added to the catalog feed</a>.</p>
16 + <p>Within Klaviyo,<a>custom catalog</a>items are stored as either ‘products’ or ‘variants’, depending on your integration method. The catalog becomes ‘inventory aware’ once<a>inventory data is added to the catalog feed</a>.</p>
17 <h3>Back in Stock settings</h3>
17 <h3>Back in Stock settings</h3>
18 - <p>When the inventory level changes for a the subscribed item, a trigger is fired, and the flow will be initiated for that item. This in turn will then follow the rules defined in the <a>Back in Stock settings</a> for your Klaviyo account.</p>
18 + <p>When the inventory level changes for a the subscribed item, a trigger is fired, and the flow will be initiated for that item. This in turn will then follow the rules defined in the<a>Back in Stock settings</a>for your Klaviyo account.</p>
19 <h3>Subscribing to Back in Stock via API</h3>
19 <h3>Subscribing to Back in Stock via API</h3>
20 - <p>Typically, BiS subscribers are subscribed to the variant item, as this is the physical item that will maintain inventory. The subscription event occurs through an <a>API call</a>:</p>
20 + <p>Typically, BiS subscribers are subscribed to the variant item, as this is the physical item that will maintain inventory. The subscription event occurs through an<a>API call</a>:</p>
21 curl 'https://a.klaviyo.com/api/v1/catalog/subscribe' --data 'a=AccountID&amp;email=test@klaviyo.com&amp;variant=5000149172256&amp;platform=api'<h2>Scenarios</h2>
21 curl 'https://a.klaviyo.com/api/v1/catalog/subscribe' --data 'a=AccountID&amp;email=test@klaviyo.com&amp;variant=5000149172256&amp;platform=api'<h2>Scenarios</h2>
22 <h3>Scenario 1 - The migration to Klaviyo</h3>
22 <h3>Scenario 1 - The migration to Klaviyo</h3>
23 <p>The business is looking to migrate to Klaviyo and has amassed a list of Back in Stock subscribers for their products. The business wants to bring these Back in Stock subscribers into Klaviyo to utilise Klaviyo’s powerful BiS flow based upon stock changes.</p>
23 <p>The business is looking to migrate to Klaviyo and has amassed a list of Back in Stock subscribers for their products. The business wants to bring these Back in Stock subscribers into Klaviyo to utilise Klaviyo’s powerful BiS flow based upon stock changes.</p>
24 <h3>Scenario 2 - Product restructuring</h3>
24 <h3>Scenario 2 - Product restructuring</h3>
25 <p>The business has recently undertaken a product restructuring exercise, and as a result, many product and variant SKUs have changed. Given that the existing list of BiS subscribers are subscribed to now ‘defunct’ SKUs, the business would like to migrate them to the new SKU structure so they can ensure uninterrupted delivery.</p>
25 <p>The business has recently undertaken a product restructuring exercise, and as a result, many product and variant SKUs have changed. Given that the existing list of BiS subscribers are subscribed to now ‘defunct’ SKUs, the business would like to migrate them to the new SKU structure so they can ensure uninterrupted delivery.</p>
26 <h2>Ingredients</h2>
26 <h2>Ingredients</h2>
27 <ul><li>A catalog synced to Klaviyo with an inventory field</li>
27 <ul><li>A catalog synced to Klaviyo with an inventory field</li>
28 <li>Google Sheets</li>
28 <li>Google Sheets</li>
29 <li>Google Scripts</li>
29 <li>Google Scripts</li>
30 </ul><h2>Instructions</h2>
30 </ul><h2>Instructions</h2>
31 <h3>Step 1 - Organise your subscriber data</h3>
31 <h3>Step 1 - Organise your subscriber data</h3>
32 <p>As mentioned above, profiles are typically subscribed to the physical variant item, the one that maintains the inventory levels.</p>
32 <p>As mentioned above, profiles are typically subscribed to the physical variant item, the one that maintains the inventory levels.</p>
33 <p>Within your Google Sheet, the following columns will be required:</p>
33 <p>Within your Google Sheet, the following columns will be required:</p>
34 <ul><li>email</li>
34 <ul><li>email</li>
35 <li>variant</li>
35 <li>variant</li>
36 <li>synced</li>
36 <li>synced</li>
37 - </ul><p>Now, you will need to rename the Sheet tab from <em>Sheet 1</em> to <em>BackInStock.</em></p>
37 + </ul><p>Now, you will need to rename the Sheet tab from<em>Sheet 1</em>to<em>BackInStock.</em></p>
38 <p>Finally, you’ll need to add all your subscribers.</p>
38 <p>Finally, you’ll need to add all your subscribers.</p>
39 <h3>Step 2 - Prepare your catalog feed</h3>
39 <h3>Step 2 - Prepare your catalog feed</h3>
40 - <p>Assuming that you are using a custom catalog feed, the variant items will need to ensure that they are <a>inventory-aware</a>.</p>
40 + <p>Assuming that you are using a custom catalog feed, the variant items will need to ensure that they are<a>inventory-aware</a>.</p>
41 <p>You will need to ensure that there is an inventory quantity, and an inventory policy flag set for each item.</p>
41 <p>You will need to ensure that there is an inventory quantity, and an inventory policy flag set for each item.</p>
42 <p>The inventory quantity will contain the stock level</p>
42 <p>The inventory quantity will contain the stock level</p>
43 - <p>The inventory policy flag determines how Klaviyo will handle out of stock items. A <em>1</em> means that the item will not appear until the product is back in stock, even when out of stock, whereas a <em>2</em> means that Klaviyo can still use the item in product blocks and recommendations.</p>
43 + <p>The inventory policy flag determines how Klaviyo will handle out of stock items. A<em>1</em>means that the item will not appear until the product is back in stock, even when out of stock, whereas a<em>2</em>means that Klaviyo can still use the item in product blocks and recommendations.</p>
44 <h3>Step 3 - Map the catalog data within Klaviyo</h3>
44 <h3>Step 3 - Map the catalog data within Klaviyo</h3>
45 <p>Now that you’ve added these new attributes, you will need to adjust your catalog feed mapping within Klaviyo.</p>
45 <p>Now that you’ve added these new attributes, you will need to adjust your catalog feed mapping within Klaviyo.</p>
46 <p>It’s important that these new fields are mapped to the correct Klaviyo attributes so that they can be utilised for BiS.</p>
46 <p>It’s important that these new fields are mapped to the correct Klaviyo attributes so that they can be utilised for BiS.</p>
47 - <p>To do this, you will need to navigate to <strong>Products -&gt; Custom Catalog Sources</strong>, then locate your feed, and select <strong>Update</strong>.</p>
47 + <p>To do this, you will need to navigate to<strong>Products -&gt; Custom Catalog Sources</strong>, then locate your feed, and select<strong>Update</strong>.</p>
48 - <p>One the subsequent mapping screen, you will need to map your newly created attributes with the attributes <em>$inventory_quantity</em> &amp; <em>$inventory_policy</em>.</p>
48 + <p>One the subsequent mapping screen, you will need to map your newly created attributes with the attributes<em>$inventory_quantity</em>&amp;<em>$inventory_policy</em>.</p>
49 <p>Once updated, hit save and re-sync the feed.</p>
49 <p>Once updated, hit save and re-sync the feed.</p>
50 <h3>Step 4 - Configure BiS trigger and flow rate</h3>
50 <h3>Step 4 - Configure BiS trigger and flow rate</h3>
51 - <p><a>Klaviyo’s Back in Stock Settings</a> allows you to adjust under what level of stock the BiS will trigger, and the flow rate at which people should be notified.</p>
51 + <p><a>Klaviyo’s Back in Stock Settings</a>allows you to adjust under what level of stock the BiS will trigger, and the flow rate at which people should be notified.</p>
52 - <p>This can configured within <strong>Settings -&gt; BiS settings</strong>.</p>
52 + <p>This can configured within<strong>Settings -&gt; BiS settings</strong>.</p>
53 <h3>Step 5 - Add a Google Script to push the subscriber data to Klaviyo</h3>
53 <h3>Step 5 - Add a Google Script to push the subscriber data to Klaviyo</h3>
54 - <p>In your BackInStock sheet, select <strong>Extensions -&gt; Apps Script</strong></p>
54 + <p>In your BackInStock sheet, select<strong>Extensions -&gt; Apps Script</strong></p>
55 <p>Now paste the following script:</p>
55 <p>Now paste the following script:</p>
56 - //Pull environment variables const public_key = "PUBLIC_KEY"; function seedBackInStock(){ const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('BackInStock'); const data = sheet.getDataRange().getValues(); const headers = data[0]; const emailIndex = headers.indexOf("email"); const variantIndex = headers.indexOf("variant"); const syncIndex = headers.indexOf("synced"); //Throttle that can be lowered if you're getting errors with large volume of subscribers. const reqsPerSecond = 50; //Restricting to 20,000 URL Requests/day as per https://developers.google.com/apps-script/guides/services/quotas. If you have a Workspace account, this can be increased to 100,000. const maxHTTPrequests = 20000; const numRows = data.length-1 if(numRows&gt;maxHTTPrequests){ alertMessage('Too many rows. This script supports up to 20,000 rows'); }else{ data.slice(1).forEach(function (row, index) { if(row[syncIndex]!="synced"){ Utilities.sleep(1000/reqsPerSecond); subscribeBis(row[emailIndex], row[variantIndex]); let cell = columnToLetter(syncIndex+1)+(index+2); sheet.getRange(cell).setValue('synced'); } }); } } function subscribeBis(email, variant){ const options = { 'method': 'POST', 'payload': { 'a':public_key, 'email':email, 'variant':variant, 'platform':'api' } } UrlFetchApp.fetch('https://a.klaviyo.com/api/v1/catalog/subscribe', options) } function columnToLetter(column){ let temp, letter = ''; while (column &gt; 0){ temp = (column - 1) % 26; letter = String.fromCharCode(temp + 65) + letter; column = (column - temp - 1) / 26; } return letter; } function alertMessage(message) { SpreadsheetApp.getUi().alert(message); }<p>Replacing <em>PUBLIC_KEY</em> with your accounts Public Key</p>
56 + //Pull environment variables const public_key = "PUBLIC_KEY"; function seedBackInStock(){ const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('BackInStock'); const data = sheet.getDataRange().getValues(); const headers = data[0]; const emailIndex = headers.indexOf("email"); const variantIndex = headers.indexOf("variant"); const syncIndex = headers.indexOf("synced"); //Throttle that can be lowered if you're getting errors with large volume of subscribers. const reqsPerSecond = 50; //Restricting to 20,000 URL Requests/day as per https://developers.google.com/apps-script/guides/services/quotas. If you have a Workspace account, this can be increased to 100,000. const maxHTTPrequests = 20000; const numRows = data.length-1 if(numRows&gt;maxHTTPrequests){ alertMessage('Too many rows. This script supports up to 20,000 rows'); }else{ data.slice(1).forEach(function (row, index) { if(row[syncIndex]!="synced"){ Utilities.sleep(1000/reqsPerSecond); subscribeBis(row[emailIndex], row[variantIndex]); let cell = columnToLetter(syncIndex+1)+(index+2); sheet.getRange(cell).setValue('synced'); } }); } } function subscribeBis(email, variant){ const options = { 'method': 'POST', 'payload': { 'a':public_key, 'email':email, 'variant':variant, 'platform':'api' } } UrlFetchApp.fetch('https://a.klaviyo.com/api/v1/catalog/subscribe', options) } function columnToLetter(column){ let temp, letter = ''; while (column &gt; 0){ temp = (column - 1) % 26; letter = String.fromCharCode(temp + 65) + letter; column = (column - temp - 1) / 26; } return letter; } function alertMessage(message) { SpreadsheetApp.getUi().alert(message); }<p>Replacing<em>PUBLIC_KEY</em>with your accounts Public Key</p>
57 <p>Give it a name, and save it.</p>
57 <p>Give it a name, and save it.</p>
58 <h3>Step 6 - Run the script</h3>
58 <h3>Step 6 - Run the script</h3>
59 - <p>Ensure that the <em>seedBackInStock</em> function is selected, then hit <strong>Run</strong>.</p>
59 + <p>Ensure that the<em>seedBackInStock</em>function is selected, then hit<strong>Run</strong>.</p>
60 <p>If this is your first time running this script, you will be asked to provide the Script permission to access your Google Sheet.</p>
60 <p>If this is your first time running this script, you will be asked to provide the Script permission to access your Google Sheet.</p>
61 - <p>Select <strong>Review permissions</strong> and login to the correct account and grant access.</p>
61 + <p>Select<strong>Review permissions</strong>and login to the correct account and grant access.</p>
62 <p>After this, the script will complete.</p>
62 <p>After this, the script will complete.</p>
63 <p>When you return to the Google Sheet, you should see ‘synced’ status appear in the ‘synced’ column:</p>
63 <p>When you return to the Google Sheet, you should see ‘synced’ status appear in the ‘synced’ column:</p>
64 <p>That’s it!</p>
64 <p>That’s it!</p>
65 <h2>BONUS - Make a button!</h2>
65 <h2>BONUS - Make a button!</h2>
66 <p>To make this a bit more re-usable, you can create a button to run the script.</p>
66 <p>To make this a bit more re-usable, you can create a button to run the script.</p>
67 - <p>To do this, click <strong>Insert -&gt; Drawing</strong></p>
67 + <p>To do this, click<strong>Insert -&gt; Drawing</strong></p>
68 <p>Then create a Button shaped object, and add some text:</p>
68 <p>Then create a Button shaped object, and add some text:</p>
69 - <p>Next, assign the <em>seedBackInStock</em> script to this button by tapping on the three dots when hovering over the button image:</p>
69 + <p>Next, assign the<em>seedBackInStock</em>script to this button by tapping on the three dots when hovering over the button image:</p>
70 - <p>And enter <em>seedBackInStock</em></p>
70 + <p>And enter<em>seedBackInStock</em></p>
71 <p>That’s it. You can now tap this button, and it will perform the sync!</p>
71 <p>That’s it. You can now tap this button, and it will perform the sync!</p>
72 <h2>Learn more</h2>
72 <h2>Learn more</h2>
73 - <p>If you’re interested in learning more about Klaviyo’s developer experience and capabilities, check out <a>developers.klaviyo.com</a>!</p>
73 + <p>If you’re interested in learning more about Klaviyo’s developer experience and capabilities, check out<a>developers.klaviyo.com</a>!</p>
74  
74