{"id":11503,"library":"ordercloud-javascript-sdk","title":"OrderCloud JavaScript SDK","description":"The OrderCloud JavaScript SDK is a modern client library designed for building robust solutions targeting the OrderCloud eCommerce API. It significantly enhances developer productivity and reduces common errors by providing a full feature parity with the underlying API, comprehensive built-in TypeScript support, and an auto-generated API reference. The SDK operates seamlessly in both browser and Node.js environments and offers an ESM module for bundlers that support tree shaking, enabling leaner project bundles. The current stable version is 12.0.0, with minor releases occurring frequently, indicating an actively maintained project. A key differentiator is its deep integration with the OrderCloud platform, offering dedicated functionalities for authentication, advanced filtering, and impersonation. It explicitly handles `axios` as a peer dependency to prevent potential version conflicts and avoid unnecessary bundle bloat.","status":"active","version":"12.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/ordercloud-api/ordercloud-javascript-sdk","tags":["javascript","ordercloud","four51","b2b","b2c","typescript","ecommerce","api"],"install":[{"cmd":"npm install ordercloud-javascript-sdk","lang":"bash","label":"npm"},{"cmd":"yarn add ordercloud-javascript-sdk","lang":"bash","label":"yarn"},{"cmd":"pnpm add ordercloud-javascript-sdk","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for all HTTP requests made by the SDK. Must be installed separately to prevent multiple axios versions in a project.","package":"axios","optional":false}],"imports":[{"note":"Recommended for browser environments to enable tree shaking, importing only the necessary API resource modules.","wrong":"const Products = require('ordercloud-javascript-sdk').Products;","symbol":"Products","correct":"import { Products } from 'ordercloud-javascript-sdk';"},{"note":"Accesses authentication methods and token utilities. This SDK uses named exports exclusively for its modules.","wrong":"import OrderCloudSDK from 'ordercloud-javascript-sdk'; // Auth is not a default export","symbol":"Auth, Tokens","correct":"import { Auth, Tokens } from 'ordercloud-javascript-sdk';"},{"note":"Standard CommonJS import for Node.js environments or projects not using ESM. All resources are accessible via `OrderCloudSDK.ResourceName`.","wrong":"import OrderCloudSDK from 'ordercloud-javascript-sdk'; // No default export for the entire SDK object","symbol":"OrderCloudSDK (full object)","correct":"const OrderCloudSDK = require('ordercloud-javascript-sdk');"}],"quickstart":{"code":"import { Auth, Tokens } from 'ordercloud-javascript-sdk';\n\n// These should ideally come from environment variables or a secure configuration store.\n// Using process.env.VAR_NAME ?? '' for illustration, replace with actual secure methods in production.\nconst username = process.env.ORDERCLOUD_USERNAME ?? 'YOUR_USERNAME';\nconst password = process.env.ORDERCLOUD_PASSWORD ?? 'YOUR_PASSWORD';\nconst clientID = process.env.ORDERCLOUD_CLIENT_ID ?? 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Sign up for free at portal.ordercloud.io/register\nconst scope = ['FullAccess']; // Array of roles, e.g., ['FullAccess', 'BuyerAdmin', 'MeAdmin']\n\nasync function authenticateAndLogToken() {\n  try {\n    const response = await Auth.Login(username, password, clientID, scope);\n    const token = response.access_token;\n    Tokens.SetAccessToken(token); // Set the token globally for subsequent API calls\n    console.log('Successfully authenticated!');\n    console.log('Access Token:', token);\n\n    // Example: After successful login, you can make other API calls\n    // import { Products } from 'ordercloud-javascript-sdk';\n    // const products = await Products.List();\n    // console.log('First 20 products:', products.Items.map(p => p.Name));\n\n  } catch (error: any) {\n    console.error('Authentication failed:', error.message);\n    if (error.response) {\n      console.error('API Error Response:', error.response.data);\n    }\n  }\n}\n\nauthenticateAndLogToken();","lang":"typescript","description":"Demonstrates how to authenticate with the OrderCloud API using a username/password flow, store the access token for subsequent API calls, and handles potential errors during the authentication process."},"warnings":[{"fix":"Always review the `MIGRATION_GUIDE.md` document in the package's GitHub repository or documentation when upgrading to a new major version to understand and apply necessary code changes.","message":"Major versions (e.g., v12.0.0) often introduce breaking changes. It is crucial to consult the `MIGRATION_GUIDE.md` for specific instructions when upgrading from older versions.","severity":"breaking","affected_versions":"<12.0.0"},{"fix":"Ensure `axios` is installed in your project: `npm install axios` or `yarn add axios`.","message":"The `axios` library is a peer dependency and is not automatically installed with the SDK. Failure to install `axios` separately will lead to runtime errors when making API calls.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use named imports (e.g., `import { Auth } from 'ordercloud-javascript-sdk';`) for ESM, or access properties on the `require`'d object (e.g., `OrderCloudSDK.Auth`) for CJS.","message":"The SDK relies exclusively on named exports for its modules. Attempting to use a default import will result in `undefined` or runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install `axios` using your package manager: `npm install axios` or `yarn add axios`.","cause":"The `axios` library, a required peer dependency, is not installed in the project.","error":"Error: Cannot find module 'axios' or its corresponding type declarations."},{"fix":"For ESM, ensure you use `import { Auth } from 'ordercloud-javascript-sdk';` and then directly call `Auth.Login(...)`. For CJS, use `const OrderCloudSDK = require('ordercloud-javascript-sdk');` and then call `OrderCloudSDK.Auth.Login(...)`.","cause":"This error typically occurs if `Auth` was not correctly imported or accessed. Common causes include trying to use `OrderCloudSDK.Auth` after a named ESM import like `import { Auth } from 'ordercloud-javascript-sdk';` or attempting to destructure `Auth` from a CommonJS `require` call without first getting the main object.","error":"TypeError: OrderCloudSDK.Auth.Login is not a function"}],"ecosystem":"npm"}