Price Books and B2B

A common B2B use case is providing different customers with approved pricings. With Standalone Price Books, existing segments or customer groups can be used to identify which pricing the Storefront API should deliver.

The guide requires that authentication be set up and customer tokens be used when querying via the Storefront API. See Authentication Introduction for details.

Quick Start

  1. Ingestion API Setup

    Setup a custom data source for the ingestion API.

    The Ingestion API REST endpoint is https://ingest.api.nacelle.com/v1/price-book.
    To make use of it, you must provide the following headers in your requests:

    x-nacelle-space-id
    x-nacelle-source-id
    x-nacelle-ingest-token

    You can find the values of these headers on the API Details page. To get there, select a space, navigate to Space Settings, then go to the API Details tab.

    The x-nacelle-ingest-token can be generated by clicking on the Create New Key button.

  2. Create Price Book

    Use the generated ingest token to make a PUT request to the Ingest Price Book endpoint. Here is an example:

     const fetch = require('node-fetch');
    
     const url = 'https://ingest.api.nacelle.com/v1/price-book';
     const options = {
       method: 'PUT',
       headers: {
         accept: 'application/json',
         'x-nacelle-space-id': '1234',
         'x-nacelle-source-id': '1234',
         'x-nacelle-ingest-token': '1234',
         'content-type': 'application/json'
       },
       body: JSON.stringify({
         entries: [
           {
             sourceEntryId: '3858f62230ac3c915f300c664312c63g',
             createdAt: '2023-09-16T00:00:00',
             updatedAt: '2023-09-16T00:00:00',
             name: 'B2B Experience',
             key: 'b2b',
             currencyCode: 'USD',
             countryCodes: [
               'US'
             ]
           }
         ]
       })
     };
    
     fetch(url, options)
       .then(res => res.json())
       .then(json => console.log(json))
       .catch(err => console.error('error:' + err));
    
  3. Create Pricing

    Use the generated ingest token to make a PUT request to the Ingest Pricing endpoint. This will create a pricing linking it to the previously created Price Book and a variant in your system.

    The first thing to note in the following example is the added field to the first pricing, sourceSegmentId, this tells our system that this pricing will only be shown to customers that are a part of this segment, otherwise the non-segmented pricing will be shown.

     const fetch = require('node-fetch');
    
     const url = 'https://ingest.api.nacelle.com/v1/pricing';
     const options = {
       method: 'PUT',
       headers: {
         accept: 'application/json',
         'x-nacelle-space-id': '1234',
         'x-nacelle-source-id': '1234',
         'x-nacelle-ingest-token': '1234',
         'content-type': 'application/json'
       },
       body: JSON.stringify({
         entries: [
           {
             // This is the pricing for authenticated customers that have a segmentId of `vip-customers` on their generated public access token.
             sourceEntryId: '1858f62230ac3c915f300c664312c63f',
             sourcePriceBookId: '2855f62230ac3c915f300c664312c62g',
             sourceVariantId: '3352f62230ac3c915f300c664312b18a',
             sourceSegmentId: 'vip-customers',
             createdAt: '2023-09-16T00:00:00',
             updatedAt: '2023-09-16T00:00:00',
             price: {
               amount: 1000,
               currencyCode: 'USD',
               precisionDigits: 2
             }
           },
           {
             // This is the default pricing that will show for anonymous customers
             sourceEntryId: '2858f62230ac3c915f300c664312c63f',
             sourcePriceBookId: '2855f62230ac3c915f300c664312c62g',
             sourceVariantId: '3352f62230ac3c915f300c664312b18a',
             createdAt: '2023-09-16T00:00:00',
             updatedAt: '2023-09-16T00:00:00',
             price: {
               amount: 1800,
               currencyCode: 'USD',
               precisionDigits: 2
             }
           }
         ]
       })
     };
    
     fetch(url, options)
       .then(res => res.json())
       .then(json => console.log(json))
       .catch(err => console.error('error:' + err));
    
  4. Query Pricing on a Product Variant:
    You can retrieve order details anytime by using our Storefront API endpoint.

    NOTE: That an authorization header must be passed with the PUBLIC_ACCESS_TOKEN generated for a given customer, as explained here: Auth Public Access Token.

    This added header should look like this:

    {
     "Authorization": "Bearer PUBLIC_ACCESS_TOKEN"
    }
    
     query allProducts {
       allProducts {
         edges {
           node {
             sourceEntryId
             variants {
               sourceEntryId
               pricing (filter: {currencyCode: "JPY"}) {
                 price {
                   amount
                   currencyCode
                   precisionDigits
                 }
               }
             }
           }
         }
       }
     }