Simple API client for the BigCommerce Management API
npm i bigcommerce-client
const bc_client = require('bigcommerce-client')
const store = new bc_client('storeHash', 'authToken')
async function getFromSKU(sku){
return await store.get('v3/catalog/products', {sku})
}
async function getOutOfStock(sku){
return await store.getAll('v3/catalog/products', {inventory_level:0})
}
async function updateOutOfStock(sku){
await store.paginate('v3/catalog/products', async (products)=>{
await store.put('v3/catalog/products', products.map((product)=>{
product.inventory_level = 1
return product
}))
}, {limit:10, inventory_level:0, include_fields:'inventory_level'})
}
async function createDigitalProduct(name, price){
return (await store.post('v3/catalog/products', {name, price, type:'digital', weight:0})).id
}
async function changePrice(id, price){
try {
await store.put(`v3/catalog/products/${id}`, {price}))
} catch (new Error('ID not found'))
}
async function deleteProduct(id){
try {
await store.delete(`v3/catalog/products/${id}`))
} catch (new Error('ID not found'))
}
async function deleteAllProducts(){
await store.deleteAll(`v3/catalog/products`))
}