{"info":{"_postman_id":"faa98caf-a6c6-4581-ad85-9908419d422e","name":"Creating a Headless BigCommerce Cart and Checkout Flow","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[],"description":"<html><head></head><body></body></html>","owner":"45334","collectionId":"faa98caf-a6c6-4581-ad85-9908419d422e","publishedId":"SWTEbbQU","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"34313F","highlight":"4E75F8"},"publishDate":"2020-02-03T17:06:55.000Z"},"item":[{"name":"#1 Retrieve first 250 Products with variants","event":[{"listen":"test","script":{"id":"0e82b7ef-224a-4f6f-91ea-1b38e06a1c68","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":"173475fd-ecff-4044-8de0-b3ee3cf62632","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":"173475fd-ecff-4044-8de0-b3ee3cf62632"},{"name":"#2 Create a Cart","event":[{"listen":"prerequest","script":{"id":"f8f17d3f-1672-4cff-8be6-dcd099aa0214","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":"e2295928-12a3-4309-846c-734acdcecd0b","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 that', () => {","    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","    ","// Test the value before storing it","pm.test('Line Item Id is a string that is not empty', () => {","    pm.expect(lineItemId).to.be.a('string').that.is.not.empty","})","    ","// 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":"6c8a241e-cf15-47a1-bad8-5bf48a5134b8","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  \"line_items\": [\n    {\n      \"quantity\": 1,\n      \"product_id\": ,\n      \"variant_id\": ,\n      \"option_selections\": \n    }\n  ]\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":"6c8a241e-cf15-47a1-bad8-5bf48a5134b8"},{"name":"#3 Create a Consignment","event":[{"listen":"test","script":{"id":"605886ec-e387-4cbd-b158-4d53a38c9d1b","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 exactly one consignment', () => {","    pm.expect(pm.response.json().data.consignments.length).to.equal(1)","})","pm.test('Consignment includes at least one available shipping option', () => {","    pm.expect(pm.response.json().data.consignments[0].available_shipping_options.length).to.be.above(0)","})","","const checkout = pm.response.json().data","const consignmentId = checkout.consignments[0].id","const shippingOptionId = checkout.consignments[0].available_shipping_options[0].id","","// Unset any existing variables","pm.collectionVariables.unset('consignment-id')","pm.collectionVariables.unset('shipping-option-id')","","// Set new variables","pm.collectionVariables.set('consignment-id', consignmentId)","pm.collectionVariables.set('shipping-option-id', shippingOptionId)"],"type":"text/javascript"}}],"id":"1400d180-0b7a-4b24-bdc6-7b8f657bdc3c","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  {\n    \"line_items\": [\n      {\n        \"item_id\": \"\",\n        \"quantity\": 1\n      }\n    ],\n    \"shipping_address\": {\n      \"first_name\": \"John\",\n      \"last_name\": \"Doe\",\n      \"email\": \"john.doe@example.org\",\n      \"company\": \"\",\n      \"address1\": \"11305 Four Points Dr #300\",\n      \"address2\": \"\",\n      \"city\": \"Austin\",\n      \"state_or_province\": \"Texas\",\n      \"state_or_province_code\": \"TX\",\n      \"country_code\": \"US\",\n      \"postal_code\": \"78726\",\n      \"phone\": \"5128654500\"\n    }\n  }\n]"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/checkouts//consignments?includes=consignments.available_shipping_options","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","checkouts","","consignments"],"host":["api","bigcommerce","com"],"query":[{"key":"includes","value":"consignments.available_shipping_options"}],"variable":[]}},"response":[],"_postman_id":"1400d180-0b7a-4b24-bdc6-7b8f657bdc3c"},{"name":"#4 Update Consignment with Selected Shipping Option","event":[{"listen":"test","script":{"id":"8b0ab5f5-0133-496f-812f-4c78d3602e7d","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 exactly one consignment', () => {","    pm.expect(pm.response.json().data.consignments.length).to.equal(1)","})","pm.test('Selected shipping option ID matches stored shipping option ID', () => {","    pm.expect(pm.response.json().data.consignments[0].selected_shipping_option.id).to.equal(pm.collectionVariables.get('shipping-option-id'))","})"],"type":"text/javascript"}}],"id":"50c93fe6-da59-4071-be58-6e17eb52e30c","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"PUT","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  \"shipping_option_id\": \"\"\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/checkouts//consignments/","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","checkouts","","consignments",""],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"50c93fe6-da59-4071-be58-6e17eb52e30c"},{"name":"#5 Create a Billing Address","event":[{"listen":"test","script":{"id":"8e801748-ff5e-4028-9675-26e899b3d63a","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('Billing address includes an id that is a string', () => {","    pm.expect(pm.response.json().data.billing_address.id).to.be.a('string')","})","pm.test('Billing address includes an email that is a non-empty string', () => {","    pm.expect(pm.response.json().data.billing_address.email).to.be.a('string').that.is.not.empty","})","pm.test('Billing address includes a country_code that is 2 characters', () => {","    pm.expect(pm.response.json().data.billing_address.country_code).to.be.a('string').that.has.lengthOf(2)","})"],"type":"text/javascript"}}],"id":"581b3774-3d0f-4e66-9a03-7088cdb254a4","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  \"first_name\": \"John\",\n  \"last_name\": \"Doe\",\n  \"email\": \"john.doe@example.org\",\n  \"company\": \"BigCommerce\",\n  \"address1\": \"11305 Four Points Dr #300\",\n  \"address2\": \"\",\n  \"city\": \"Austin\",\n  \"state_or_province\": \"Texas\",\n  \"state_or_province_code\": \"TX\",\n  \"country_code\": \"US\",\n  \"postal_code\": \"78726\",\n  \"phone\": \"5128654500\"\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/checkouts//billing-address","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","checkouts","","billing-address"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"581b3774-3d0f-4e66-9a03-7088cdb254a4"},{"name":"#6 Create an Order","event":[{"listen":"test","script":{"id":"33eae665-0d1f-4720-8202-12d942c62543","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 numeric order ID', () => {","    pm.expect(pm.response.json().data.id).to.be.a('number')","})","","const orderId = pm.response.json().data.id","// Unset any previous variable","pm.collectionVariables.unset('order-id')","// Set the new variable","pm.collectionVariables.set('order-id', orderId)"],"type":"text/javascript"}}],"id":"df591098-266f-4cf4-8cae-2fe75c2a8e12","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/checkouts//orders","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","checkouts","","orders"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"df591098-266f-4cf4-8cae-2fe75c2a8e12"},{"name":"#7 Retrieve Accepted Payment Methods","event":[{"listen":"test","script":{"id":"9af3b807-2512-4bf6-a5d0-f4e9b1a9d551","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('At least one payment method is available', () => {","    pm.expect(pm.response.json().data.length).to.be.above(0)","})","","const methodInTestMode = pm.response.json().data.find(method => method.test_mode)","pm.test('At least one payment method is in test mode', () => {","    pm.expect(methodInTestMode).not.to.be.an('undefined')","})","","// Unset any previous variable","pm.collectionVariables.unset('payment-method-id')","// Set the new variable","pm.collectionVariables.set('payment-method-id', methodInTestMode.id)"],"type":"text/javascript"}}],"id":"998286c3-d77c-472f-812d-fd7aa6d007df","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/payments/methods?order_id=","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","payments","methods"],"host":["api","bigcommerce","com"],"query":[{"key":"order_id","value":""}],"variable":[]}},"response":[],"_postman_id":"998286c3-d77c-472f-812d-fd7aa6d007df"},{"name":"#8 Generate Payment Access Token","event":[{"listen":"test","script":{"id":"0d290389-8dd8-4fe7-b588-bdfb994d30c5","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 PAT that is a string and is not empty', () => {","    pm.expect(pm.response.json().data.id).to.be.a('string').that.is.not.empty","})","","pm.collectionVariables.unset('PAT')","pm.collectionVariables.set('PAT', pm.response.json().data.id)"],"type":"text/javascript"}}],"id":"4fc14272-0d4a-4013-805b-444a541d5bec","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\"order\": {\n\t\t\"id\": \n\t}\n}"},"url":"https://api.bigcommerce.com/stores/{{store-hash}}/v3/payments/access_tokens","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","v3","payments","access_tokens"],"host":["api","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"4fc14272-0d4a-4013-805b-444a541d5bec"},{"name":"#9 Process Payment with a Test Credit Card","event":[{"listen":"test","script":{"id":"1022f105-9a1d-427b-9848-4c9c17531213","exec":["pm.test('Response is not an error', () => {","    pm.response.to.not.be.error","    pm.response.to.not.have.jsonBody(\"errors\")","})","","pm.test('Response is JSON with data', () => {","    pm.response.to.have.jsonBody(\"data\")","})","","pm.test('Response has a transaction_type that is not an empty string', () => {","    pm.expect(pm.response.json().data.transaction_type).to.be.a('string').that.is.not.empty","})","","pm.test('Response is JSON with status that is \"pending\" or \"success\"', () => {","    pm.expect(pm.response.json().data).to.satisfy(data => data.status === 'pending' || data.status === 'success')","})","",""],"type":"text/javascript"}}],"id":"24d1726b-e81e-4739-9bc4-c51c6c7d8c8d","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Accept","value":"application/vnd.bc.v1+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"},{"key":"Authorization","value":"PAT ","type":"text"}],"body":{"mode":"raw","raw":"{\r\n  \"payment\": {\r\n    \"instrument\": {\r\n      \"type\": \"card\",\r\n      \"number\": \"4111111111111111\",\r\n      \"cardholder_name\": \"John Doe\",\r\n      \"expiry_month\": 12,\r\n      \"expiry_year\": 2027,\r\n      \"verification_value\": \"123\"\r\n    },\r\n    \"payment_method_id\": \"\"\r\n\t\t\r\n  }\r\n}"},"url":"https://payments.bigcommerce.com/stores/{{store-hash}}/payments","urlObject":{"protocol":"https","path":["stores","{{store-hash}}","payments"],"host":["payments","bigcommerce","com"],"query":[],"variable":[]}},"response":[],"_postman_id":"24d1726b-e81e-4739-9bc4-c51c6c7d8c8d"}],"event":[{"listen":"prerequest","script":{"id":"f421dd4c-bae3-4e21-b0f4-42ce6c2c0f0a","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"a8bc0105-b551-4265-9eab-4a8e53c00a31","type":"text/javascript","exec":[""]}}],"variable":[{"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":""},{"key":"consignment-id","value":""},{"key":"shipping-option-id","value":""},{"key":"order-id","value":""},{"key":"payment-method-id","value":""},{"key":"PAT","value":""}]}