Skip to navigation

Salesforce Commerce Cloud

Beta

Connect a Salesforce B2C Commerce (Commerce Cloud) site, and Captain imports its online products and the orders it needs to measure search revenue. Then put Captain’s search box on the storefront.

The Salesforce Commerce Cloud integration is in beta. Captain tested it end to end against a recorded copy of Salesforce’s documented Commerce API, not yet against a live instance. Captain switches it on per tenant: ask the Captain team on Slack.

Quick start

How it works

  • The connection reads one site’s catalog and orders through the Salesforce Commerce API (SCAPI) Admin APIs, with an Account Manager API client that can only read. It never changes anything in Commerce Cloud.
  • Hourly sync, no webhooks. Salesforce offers no product or order webhooks to an API client, so Captain imports what changed on the schedule you choose (every hour at most), plus a full import daily and on Sync now.
  • The search box is Captain’s search widget. Your developers add it to the storefront code. It searches your Captain catalog with a public, scoped storefront key.

Before you start

  • A B2C Commerce instance with the Salesforce Commerce API enabled, and an Account Manager administrator for its organization.
  • Business Manager access to read the short code and organization ID.
  • A Captain Product Search tenant with Salesforce Commerce Cloud switched on.
  • An owner of your Captain organization, to create the storefront key later.

Make a read-only API client

1

Find the short code and organization ID

In Business Manager, open Administration, Site Development, Salesforce Commerce API Settings. Copy the Short Code and the Organization ID, for example f_ecom_zzxy_prd. The instance ID is the part after f_ecom_: zzxy_prd.

2

Add an API client

In Account Manager, open API Client and select Add API Client. Give it a display name such as Captain search and a password. The password is the client secret.

3

Give it access

  • Organizations: your organization.
  • Roles: Salesforce Commerce API, with this instance in its filter.
  • Allowed Scopes: sfcc.products sfcc.catalogs sfcc.orders. These are the read-only scopes. Don’t add the .rw ones: Captain refuses a client that can change the store.
  • Token Endpoint Auth Method: client_secret_basic.
  • Access Token Format: JWT.
4

Save

Select Save and copy the API Client ID.

ScopeWhy Captain needs it
sfcc.productsSearch products with their variants, site prices, stock and online flags.
sfcc.catalogsRead category names.
sfcc.ordersMeasure revenue from search.

Connect the site

1

Open the Salesforce Commerce card

In the Captain console, open Developers, then Integrations. On the Salesforce Commerce Cloud card, select Connect.

2

Name the connection and the catalog

In Name, enter a name such as the site’s name. In New catalog name, enter a name no other catalog uses, such as sfcc-products. Captain creates this catalog.

3

Choose how often to resync

In Sync every, choose 1, 6, 12 or 24 hours.

4

Paste the details

  • Short code, Instance ID and Site ID (as Administration, Sites, Manage Sites shows it, such as RefArch).
  • Client ID and Client secret from Account Manager.
  • Product page address (optional): your product page address with {id} where the product ID goes, so search results link to the product. For PWA Kit, https://www.example.com/product/{id}. For SFRA, https://www.example.com/on/demandware.store/Sites-RefArch-Site/default/Product-Show?pid={id}.

Select Connect.

Captain tests the client first: it gets a token, checks its scopes, and reads the site’s orders and one product. It refuses a client with a write scope, a missing scope, or an unknown site, in plain words. The client ID and secret are kept in AWS Secrets Manager and never shown again, logged or sent to the browser.

What syncs

Products

Captain imports the site’s products that are online and searchable on that site. A master product’s variants become one record each; an offline variant stays out. Simple products, sets and bundles are one record each.

Commerce Cloud fieldCaptain field
name (default locale)title
longDescription, else shortDescription (HTML removed)body
brandvendor
assigned category names (assignedCategories)collections
classification category nameproduct_type
pageKeywords (comma separated)tags
variation attribute display names and valuesoptions, option_values, variant_title
variant productIdthe record ID and sku
upc, else ean (simple products)barcode
site price and priceCurrencyprice, currency
ats (available to sell)inventory
orderable, else inStockavailable
image, then the large image groupimage, images
the product page address with the product IDurl
creationDate, lastModifiedcreated_at, updated_at
manufacturerName, manufacturerSku, ean, upc, unit, taxClassId, custom attributes (c_*)attributes

The Admin APIs give one effective price per site. Captain doesn’t receive a list price next to a sale price, so records carry no compare-at price.

Orders

Captain reads the site’s orders by when they last changed. It records one purchase event for each order with status new or completed: the variants, quantities and prices after discounts, the product total (before shipping, and before tax on net-taxation sites), and the currency. Created, cancelled and failed orders count zero. Captain stores no customer names, emails or addresses.

Live updates

Commerce Cloud has no webhooks for an API client, so there are no live updates. Captain imports products changed since the last import on your Sync every schedule, and a full import at least daily.

  • A price-book or inventory change that doesn’t change the product’s modified date reaches Captain at the daily full import, or right away with Sync now.
  • A product removed from the site leaves the catalog at the next full import.

Create a storefront key

Open the connection’s Manage panel. Under Storefront search, add your storefront’s domains and select Create storefront key. The panel shows a snippet with the key filled in, once. Copy it.

<script type="module"
src="https://cdn.jsdelivr.net/gh/runcaptain/captain-search@1.8.0/captain-search.js"
integrity="sha384-JE4C0r/iXcnqRePQ+XK/wsFWEWRqxIR8gTfYjlnOTnd2gUaq+Y+BYHC/IRNFy/xp"
crossorigin="anonymous"></script>
<captain-search
endpoint="https://acme.captain.dev"
index="sfcc-products"
key="YOUR_SCOPED_KEY"
placeholder="Search products"
></captain-search>

Add it to the storefront

Commerce Cloud storefronts are code, so a developer adds the snippet.

In your storefront cartridge, render the <script> tag in the page head, through the app.template.htmlHead hook or htmlHead.isml. Put the <captain-search> element in the header in place of the search form (headerSearch.isml). Keep the cartridge first on the cartridge path (Administration, Sites, Manage Sites, your site, Settings), upload it and activate the code version.

Add the <script> tag to the head in app/components/_app/index.jsx and the <captain-search> element to your header component. In app/ssr.js, add https://cdn.jsdelivr.net to script-src and your Captain endpoint to connect-src in the content security policy. Then push the bundle to production.

Search on the storefront in a private window to test.

Sync now and Disconnect

  • Sync now starts a full import at any time. It also removes products the site no longer has.
  • Disconnect stops syncing and deletes the stored client credentials. The catalog stays until you delete it. To revoke access in Salesforce too, disable or delete the API client in Account Manager.

Troubleshooting

Check the client ID and password, that the client’s Allowed Scopes hold sfcc.products sfcc.catalogs sfcc.orders, and that its Salesforce Commerce API role includes this instance. A token without that role is issued but every call answers 403.

Captain only reads. Remove the .rw scopes from the client’s Allowed Scopes and connect again.

The site ID or instance ID is wrong. Copy the site ID from Manage Sites and the organization ID from Salesforce Commerce API Settings.

Check that it’s online and searchable on this site, and that at least one of its variants is online. Then select Sync now.