![Logo](/BrinsilElias/sfcc-ocapi-client/raw/main/docs/public/logo.png)
A node package that let's you work with salesforce OCAPI like a breeze.
·
Report Bug
·
Request Feature
·
Read Docs
Table of Contents
sfcc-ocapi-client
is a node/npm package designed to streamline your integration with Salesforce's Open Commerce API, offering easy-to-use methods to interact with various endpoints.
- Simplified API connection setup with custom configurations.
- Pre-configured methods for different API endpoints like
Products
,Promotions
, andCustomers
. - Custom error handling and response parsing.
Please ensure you have Node.js installed on your machine, version 18 or greater. You can download it from the official website NodeJs.
To begin using the sfcc-ocapi-client
, choose your preferred package manager from the options below to install it in your project.
- Using npm
$ npm install sfcc-ocapi-client
- Using pnpm
$ pnpm add sfcc-ocapi-client
- Using yarn:
$ yarn add sfcc-ocapi-client
Congratulations! You've successfully set up sfcc-ocapi-client 🎉. Let’s make your first API call to see it in action:
const { getShopApi } = require('sfcc-ocapi-client');
// Read below to know about the configuration object
const config = require('./config');
const shopApi = getShopApi(config);
const productApi = shopApi.Products;
(async () => {
try {
const product = await productApi.getProductById('product-id');
console.log(product);
} catch (error) {
console.log(error);
}
})();
Note
This package supports both cjs (common js) and esm (es module) syntax. If you are using esm syntax in your project you can use import and export statements with this package.
import { getShopApi } from 'sfcc-ocapi-client';
(async () => {
try {
const product = await productApi.getProductById('product-id');
console.log(product);
} catch (error) {
console.log(error);
}
})();
This will also work 😄
To utilize sfcc-ocapi-client, you need to pass a configuration object when creating an instance. This configuration is crucial as it defines how the client will interact with Salesforce's OCAPI.
Here’s what typically goes into the config object:
baseURL
: The base URL of the Salesforce API you wish to connect to.clientId
: Your Salesforce client ID.ocapiVersion
: The ocapi version for accessing resourcestimeout
: The timeout duration for each api callheaders
: The headers to include in the api request
const config = {
baseURL: 'https://instance/s/siteId/dw/resource/ocapi-version',
clientId: 'aaaaaaaaaaaaaaaaaaaaaaaaaaa',
ocapiVersion: 'v24_1'
};
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are extremely appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Brinsil Elias - @BrinsilE
Project Link: https://github.com/BrinsilElias/sfcc-ocapi-client