{"info":{"_postman_id":"a4731716-12b5-4848-8fe9-ef17a2533e3a","name":"BC Embedded Checkout Demo","description":"<html><head></head><body><h2 id=\"overview\">Overview</h2>\n<p>This collection is used as part of the Embedded Checkout POC demo. Complete the requests in the Register the Channel folder to register a channel, a site, and routes for links that appear on the checkout page.</p>\n<p><em>Note: If you are hosting the embedded checkout POC app on a domain other than localhost, you must update the Create a Site request with your domain</em></p>\n<p>The Cart + Embedded Redirect collection will retrieve a product from the catalog, create a cart, then create a redirect URL for that cart. Copy that redirect URL into the embedded checkout POC React app to demonstrate the embedded checkout.</p>\n<h2 id=\"environment\">Environment</h2>\n<p>Configure your environment in Postman with the following variables:</p>\n<ul>\n<li>store-hash: <em>The store hash for your BigCommerce store</em></li>\n<li>client-id: <em>The client ID for your API credentials on your BigCommerce store</em></li>\n<li>token: <em>The API token corresponding to the client-id for your BigCommerce store</em></li>\n</ul>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[],"owner":"45334","collectionId":"a4731716-12b5-4848-8fe9-ef17a2533e3a","publishedId":"SWT5jLpM","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"34313F","highlight":"4E75F8"},"publishDate":"2020-01-20T20:08:28.000Z"},"item":[{"name":"Register the Channel","item":[{"name":"#1 Create a Channel","event":[{"listen":"test","script":{"id":"ca5ffde4-5e7c-4479-a328-a6795917f688","exec":["pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","const res = pm.response.json()","","pm.test('Channel ID is a number', () => {","    pm.expect(res.data.id).to.be.a('number')","})","","pm.collectionVariables.set('channel-id', res.data.id)"],"type":"text/javascript"}}],"id":"f48ab202-4933-4bcf-b70e-132a151f38de","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"body":{"mode":"raw","raw":"{\n    \"type\": \"storefront\",\n    \"platform\": \"custom\",\n    \"name\": \"My React Site\"\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/channels","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","channels"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"f48ab202-4933-4bcf-b70e-132a151f38de"},{"name":"#2 Create a Site","event":[{"listen":"test","script":{"id":"fe072be4-7e59-4270-9489-31eea1d7364c","exec":["pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","const res = pm.response.json()","","pm.test('Site ID is a number', () => {","    pm.expect(res.data.id).to.be.a('number')","})","","pm.collectionVariables.set('site-id', res.data.id)"],"type":"text/javascript"}}],"id":"0a3e18ca-38a0-450b-8570-b7954b1382e3","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"body":{"mode":"raw","raw":"{\n    \"url\": \"https://localhost\"\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/channels//site","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","channels","","site"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"0a3e18ca-38a0-450b-8570-b7954b1382e3"},{"name":"#3 Create a Cart Route","event":[{"listen":"test","script":{"id":"6b8a7e48-3d9a-442a-b200-6c182992c55d","exec":["pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","const res = pm.response.json()","","pm.test('Cart Route ID is a number', () => {","    pm.expect(res.data.id).to.be.a('number')","})"],"type":"text/javascript"}}],"id":"c5e09b71-13ad-417a-9e94-393775ea6e4e","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"body":{"mode":"raw","raw":"{ \n\t\"type\": \"cart\",\n\t\"matching\": \"\",\n\t\"route\": \"/demo/cart\"\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/sites/{{site-id}}/routes","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","sites","{{site-id}}","routes"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"c5e09b71-13ad-417a-9e94-393775ea6e4e"},{"name":"#4 Create a Forgot Password Route","event":[{"listen":"test","script":{"id":"41608edd-c099-4b38-b7fd-be014860443d","exec":["pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","const res = pm.response.json()","","pm.test('Forgot Password Route ID is a number', () => {","    pm.expect(res.data.id).to.be.a('number')","})"],"type":"text/javascript"}}],"id":"767d56ed-40ca-40f6-8acc-f4f6024c57b9","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"body":{"mode":"raw","raw":"{ \n\t\"type\": \"forgot_password\",\n\t\"matching\": \"\",\n\t\"route\": \"/routes/password_reset\"\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/sites/{{site-id}}/routes","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","sites","{{site-id}}","routes"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"767d56ed-40ca-40f6-8acc-f4f6024c57b9"},{"name":"#5 Create a Create Account Route","event":[{"listen":"test","script":{"id":"88223033-58a4-4015-aa86-476265957381","exec":["pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","const res = pm.response.json()","","pm.test('Create Account Route ID is a number', () => {","    pm.expect(res.data.id).to.be.a('number')","})"],"type":"text/javascript"}}],"id":"e322eb0d-ec73-4b89-ba2f-ab3d48e0edf6","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"body":{"mode":"raw","raw":"{ \n\t\"type\": \"create_account\",\n\t\"matching\": \"\",\n\t\"route\": \"/routes/create-account\"\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/sites/{{site-id}}/routes","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","sites","{{site-id}}","routes"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"e322eb0d-ec73-4b89-ba2f-ab3d48e0edf6"}],"id":"5d1213e5-1900-477b-8ed6-3aa486334af6","_postman_id":"5d1213e5-1900-477b-8ed6-3aa486334af6","description":""},{"name":"Cart + Embedded Redirect","item":[{"name":"#1: Retrieve First 250 Products with Variants","event":[{"listen":"test","script":{"id":"0f781efd-1444-4a6a-82d7-282c343b3534","exec":["pm.test('Response is not an error', () => {","    pm.response.to.not.be.error","    pm.response.to.not.have.jsonBody(\"error\")","})","","pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","pm.test('Response includes at least one product', () => {","    pm.expect(pm.response.json().data.length).to.be.above(0)","})","","","const products = pm.response.json().data","const firstSaleableProduct = products.find(product => {","    if (product.availability !== 'disabled')","        if (product.inventory_tracking !== 'none')","            return product.inventory_level > 0","        else return true","})","","const firstSaleableVariant = firstSaleableProduct.inventory_tracking !== 'variant'","    ? firstSaleableProduct.variants[0]","    : firstSaleableProduct.variants.find(variant => variant.inventory_level > 0)","","// Test values before storing them","pm.test('Found a saleable product with a product ID', () => {","    pm.expect(firstSaleableProduct.id).to.be.a('number')","})","","pm.test('Found a saleable variant with a variant ID', () => {","    pm.expect(firstSaleableVariant.id).to.be.a('number')","})","","pm.test('Saleable variant\\'s option values is an array', () => {","    pm.expect(firstSaleableVariant.option_values).to.be.a('array')","})","","// Clear any previously stored collection variables","pm.collectionVariables.unset('product-id')","pm.collectionVariables.unset('variant-id')","pm.collectionVariables.unset('option-values')","","// Store new collection variables","pm.collectionVariables.set('product-id', firstSaleableProduct.id)","pm.collectionVariables.set('variant-id', firstSaleableVariant.id)","pm.collectionVariables.set('option-values', JSON.stringify(firstSaleableVariant.option_values))",""],"type":"text/javascript"}}],"id":"5878758b-fffd-4b86-be1a-a890e9b52f80","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/catalog/products?limit=250&include=variants","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","catalog","products"],"host":["api","bigcommerce","com"],"query":[{"key":"limit","value":"250"},{"key":"include","value":"variants"}],"variable":[]}},"response":[],"_postman_id":"5878758b-fffd-4b86-be1a-a890e9b52f80"},{"name":"#2: Create a Cart","event":[{"listen":"prerequest","script":{"id":"f45533cb-99f3-41dd-9e45-2eb956e173c3","exec":["const optionValues = JSON.parse(pm.collectionVariables.get('option-values'))","","const optionSelections = optionValues.map(value => ({","    option_id: value.option_id,","    option_value: value.id","}))","","// unset any previous variable","pm.collectionVariables.unset('option-selections')","","// set the new option selections","pm.collectionVariables.set('option-selections', JSON.stringify(optionSelections))"],"type":"text/javascript"}},{"listen":"test","script":{"id":"1a0fa06c-8b60-4da4-b496-646a7c0f924a","exec":["pm.test('Response is not an error', () => {","    pm.response.to.not.be.error","    pm.response.to.not.have.jsonBody(\"error\")","})","","pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","pm.test('Response includes a cart ID', () => {","    pm.expect(pm.response.json().data.id).to.be.a('string')","})","","const cart = pm.response.json().data","const cartId = cart.id","// Check both physical_items and digital_items","const lineItemId = cart.line_items.physical_items.length","    ? cart.line_items.physical_items[0].id","    : cart.line_items.digital_items[0].id","    ","// Unset any previous variables","pm.collectionVariables.unset('cart-id')","pm.collectionVariables.unset('line-item-id')","","// Set the new variables","pm.collectionVariables.set('cart-id', cartId)","pm.collectionVariables.set('line-item-id', lineItemId)"],"type":"text/javascript"}}],"id":"fde9a8a8-d620-45ae-acff-5e437d1556ea","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"body":{"mode":"raw","raw":"{\r\n  \"channel_id\": ,\r\n  \"line_items\": [\r\n    {\r\n      \"quantity\": 1,\r\n      \"product_id\": ,\r\n      \"variant_id\": ,\r\n      \"option_selections\": \r\n    }\r\n  ]\r\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/carts","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","carts"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"fde9a8a8-d620-45ae-acff-5e437d1556ea"},{"name":"#3 Create Cart Redirect URL","id":"0df0f0fd-555e-4318-b971-273e68390db8","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/json","type":"text"},{"key":"Content-Type","value":"application/json","type":"text"},{"key":"X-Auth-Client","value":"{{client-id}}","type":"text"},{"key":"X-Auth-Token","value":"{{token}}","type":"text"}],"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/carts//redirect_urls","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","carts","","redirect_urls"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"0df0f0fd-555e-4318-b971-273e68390db8"}],"id":"fa9db249-f97e-427d-8a6a-98f45ce38dfa","_postman_id":"fa9db249-f97e-427d-8a6a-98f45ce38dfa","description":""}],"event":[{"listen":"prerequest","script":{"id":"9d429b76-f270-43ff-ae85-9829fd9416b6","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"c48cb1d6-a4e6-4be3-8493-acd5fb88e93e","type":"text/javascript","exec":[""]}}],"variable":[{"key":"channel-id","value":""},{"key":"option-values","value":""},{"key":"product-id","value":""},{"key":"variant-id","value":""},{"key":"option-selections","value":""},{"key":"cart-id","value":""},{"key":"line-item-id","value":""}]}