---
schema_version: "1"
id: 8e5f22afe288619eb7cb973099b7dca52159f29c3e39b383ec0fb9cadd93c2db
title: "Quick Start: B2C Commerce API and SDK"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/commerce-cloud/commerce-api/guides/api-and-sdk-demo.md
canonical_url: https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/api-and-sdk-demo.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6d281f36eea8799aeb4dd1d091d94e7fe1f87b45ffc9f2520a9059f2b06b11d9
products:
  - Composable Storefront
  - Salesforce APIs
---
# Quick Start\: B2C Commerce API and SDK

Make your first request to the B2C Commerce API using the Salesforce Commerce SDK.

For working with on-demand sandboxes, see [Develop With an On-Demand Sandbox](https://developer.salesforce.com/docs/commerce/b2c-commerce/guide/b2c-develop-with-on-demand-sandbox.html).

Our demonstration uses the Shopper Search API to search for dresses in the catalog of an example storefront.

## Create a Test Project

Start by creating a test project and installing the SDK as a package dependency.

Open a terminal and run the following commands:

```bash
mkdir test-commerce-sdk
cd test-commerce-sdk
npm init -y
npm install commerce-sdk
```

## Demo Code

Create a file called `get-dresses.js` and open it in a text editor.

Copy the following demo code, and paste it in the file.

```javascript
const { ShopperSearch, ShopperLogin, slasHelpers } = require("commerce-sdk");

const SLAS_CLIENT_ID = "da422690-7800-41d1-8ee4-3ce983961078";
// WARNING: Secret is provided here for convenience only. Do not include secrets in your code!
const SLAS_CLIENT_SECRET = "D*HHUrgO2%qADp2JTIUi";
// const SLAS_CLIENT_SECRET = process.env.SLAS_CLIENT_SECRET
const ORG_ID = "f_ecom_zzte_053";
const SHORT_CODE = "kv7kzm78";
const SITE_ID = "RefArch";

// Client configuration parameters
const clientConfig = {
  headers: {},
  parameters: {
    clientId: SLAS_CLIENT_ID,
    organizationId: ORG_ID,
    shortCode: SHORT_CODE,
    siteId: SITE_ID,
  },
};

/**
 * Get the shopper or guest JWT/access token, along with a refresh token, using client credentials
 * using the Shopper Login API directly. See below for an example of using the slasHelpers utility function instead.
 * @returns guest user authorization token
 */
async function getGuestUserAuthToken() {
  const credentials = `${SLAS_CLIENT_ID}:${SLAS_CLIENT_SECRET}`;
  const base64data = Buffer.from(credentials).toString("base64");
  const headers = { Authorization: `Basic ${base64data}` };
  const client = new ShopperLogin(clientConfig);

  return await client.getAccessToken({
    headers,
    body: {
      grant_type: "client_credentials",
      channel_id: SITE_ID,
    },
  });
}

// Get a JWT to use with Shopper API clients
async function run() {
  let tokenData;
  try {
    tokenData = await getGuestUserAuthToken();

    // Or use the slasHelpers utility function:
    
    // const client = new ShopperLogin(clientConfig);
    // tokenData = await slasHelpers.loginGuestUserPrivate({
    //   slasClient: client,
    //   credentials: {
    //     clientSecret: SLAS_CLIENT_SECRET,
    //   }
    // })
  } catch (e) {
    console.error(e);
    console.error(await e.response.text());
    return;
  }

  // Add the token to the client configuration
  clientConfig.headers["authorization"] = `Bearer ${tokenData.access_token}`;

  // Search for dresses
  const searchClient = new ShopperSearch(clientConfig);
  const limit = 3;
  const searchResults = await searchClient.productSearch({
    parameters: { q: "dress", limit: limit },
  });

  if (searchResults.total) {
    for (i = 0; i < limit; i++) {
      const result = searchResults.hits[i];
      console.log(`💃 ${result.productId} ${result.productName}`);
    }
  } else {
    console.log("No results for search");
  }
}

run();
```

## Run Your Example

Go back to the terminal and run the demo code:

```bash
node get-dresses.js
```

The output of `get-dresses.js` looks like this:

```bash
💃 25592581M Floral Dress
💃 25593727M V-Neck Dress
💃 25589753M Pack-And-Go Dress
```

For more sample code, see the [examples directory](https://github.com/SalesforceCommerceCloud/commerce-sdk/tree/master/examples) in the Commerce SDK repository.

## Next Steps

In this demo, we’ve already taken care of the following setup tasks for you:

- Created a demo sandbox with demo data, including example products.
- Created a demo API client with both a client ID and client secret.
- Configured SLAS to work with the demo sandbox and demo API client.

To use the API and SDK with _your own_ B2C Commerce instances, you must complete these setup tasks for yourself. These tasks are covered in the following guides: [Base URL and Request Formation](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/base-url.md) and [Authorization for Shopper APIs](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/authorization-for-shopper-apis.md).

After you’ve completed the setup tasks, explore the SDK’s [README](https://github.com/SalesforceCommerceCloud/commerce-sdk) and the API specifications in the [API Reference](/docs/commerce/commerce-api/references/about-commerce-api/about.html).
