A JavaScript client for BigCommerce's Management API with full TypeScript typings for all API endpoints.
To get started with the Management API client you'll need to install it, and then get credentials which will allow you to read and write data in your BigCommerce store.
npm install @space48/bigcommerce-api
Coming soon.
This library also comes with typings to use with TypeScript.
To use the BigCommerce Management API you first need to obtain the store hash and an access token from your BigCommerce store's control panel.
You can use es6 imports with the Management API:
import { Management } from "@space48/bigcommerce-api";
const bigCommerce = new Management.Client({
storeHash: 'your store hash here',
accessToken: 'your access token here',
});
The following code snippet will fetch store information from the V2 API and dump it to the console:
import { Management } from "@space48/bigcommerce-api";
const bigCommerce = new Management.Client({
storeHash: 'your store hash here',
accessToken: 'your access token here',
});
bigCommerce.v2.get('/store').then(console.dir);
Start by instantiating a client instance:
import { Management } from "@space48/bigcommerce-api";
const bigCommerce = new Management.Client({
storeHash: 'your store hash here',
accessToken: 'your access token here',
});
bigCommerce.v2.get('/store').then(
storeInfo => { // 200 -> response.body; 204, 404 -> null
console.dir(storeInfo),
}
error => { // non-2xx, non-404
console.error(error);
},
);
Note: When using the V3 client,
get()
,post()
,put()
anddelete()
return response.body.data on success whereas the equivalent V2 methods return response.body. If you require access to response.body.meta when sending a V3 request you should use theManagement.v3.send()
method.
bigCommerce.v3.get('/catalog/products/{product_id}', {
path: { product_id: 1234 },
query: { include: ['images'] }
}).then(
product => { // 200 -> response.body.data; 204, 404 -> null
console.dir(product),
}
error => { // non-2xx, non-404
console.error(error);
},
)
Note: When using the V3 client,
get()
,post()
,put()
anddelete()
return response.body.data on success whereas the equivalent V2 methods return response.body. If you require access to response.body.meta when sending a V3 request you should use theManagement.v3.send()
method.
async function printAllProducts() {
// list() sends one HTTP request at a time and only sends requests as the iterator is consumed
const products = bigCommerce.v3.list('/catalog/products', { query: { include: ['images'] } });
for await (const product of products) {
console.dir(product);
}
}
Note:
list()
is currently only available for V3 endpoints as the V2 API does not apply a standardised approach to pagination.
bigCommerce.v3.post('/customers', {
body: [
{
email: '[email protected]',
first_name: 'John',
last_name: 'Doe',
},
{
email: '[email protected]',
first_name: 'Jane',
last_name: 'Doe',
},
],
}).then(
result => { // 200 -> response.body.data; 204 -> null
console.dir(result),
}
error => { // non-2xx
console.error(error);
},
)
Note: When using the V3 client,
get()
,post()
,put()
anddelete()
return response.body.data on success whereas the equivalent V2 methods return response.body. If you require access to response.body.meta when sending a V3 request you should use theManagement.v3.send()
method.
The Client
constructor supports several options you may set to achieve the expected behavior:
import { Management } from "@space48/bigcommerce-api";
const bigCommerce = new Management.Client({
... your config here ...
});
Your BigCommerce store hash.
Your BigCommerce Management API access token.
Provide a node HTTP agent to override things like keepalive and connection pool size.
See the V2 readme for more detail on the Management V2 client methods.
See the V3 readme for more detail on the Management V3 client methods.
This library is a wrapper around BigCommerce's REST API. Visit the BigCommerce API reference to see detailed documentation of the available endpoints and parameters.