Skip to content

🎢 A client application that makes it a breeze to interact with salesforce open commerce api (OCAPI).

License

Notifications You must be signed in to change notification settings

BrinsilElias/sfcc-ocapi-client

Repository files navigation

Logo

SFCC OCAPI Client

A node package that let's you work with salesforce OCAPI like a breeze.

· Report Bug · Request Feature · Read Docs

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

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.

Features

  • Simplified API connection setup with custom configurations.
  • Pre-configured methods for different API endpoints like Products, Promotions, and Customers.
  • Custom error handling and response parsing.

Built With

  • Node.js
  • Axios
  • AJV
  • ESLint
  • Babel
  • Rollup.js
  • Jest
  • Prettier

(back to top)

⛳ Getting Started

Prerequisites

Please ensure you have Node.js installed on your machine, version 18 or greater. You can download it from the official website NodeJs.

Setup

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

(back to top)

⚒️ Usage

Try it out

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 😄

Configuration

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 resources
  • timeout: The timeout duration for each api call
  • headers: The headers to include in the api request
const config = {
  baseURL: 'https://instance/s/siteId/dw/resource/ocapi-version',
  clientId: 'aaaaaaaaaaaaaaaaaaaaaaaaaaa',
  ocapiVersion: 'v24_1'
};

(back to top)

🚧 Roadmap

See the open issues for a list of proposed features (and known issues).

(back to top)

🤝 Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

Distributed under the MIT License. See LICENSE for more information.

📫 Contact

Brinsil Elias - @BrinsilE

Project Link: https://github.com/BrinsilElias/sfcc-ocapi-client

Acknowledgements

About

🎢 A client application that makes it a breeze to interact with salesforce open commerce api (OCAPI).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published