{"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install ordercloud-javascript-sdk"],"cli":null},"imports":["import { Products } from 'ordercloud-javascript-sdk';","import { Auth, Tokens } from 'ordercloud-javascript-sdk';","const OrderCloudSDK = require('ordercloud-javascript-sdk');"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}