Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 1.58 KB

README.md

File metadata and controls

78 lines (60 loc) · 1.58 KB

bigcommerce-client

Simple API client for the BigCommerce Management API

Installation

npm i bigcommerce-client

Usage

const bc_client = require('bigcommerce-client')
const store = new bc_client('storeHash', 'authToken')

Get a Resource

async function getFromSKU(sku){
    return await store.get('v3/catalog/products', {sku})
}

Get All Resources

async function getOutOfStock(sku){
    return await store.getAll('v3/catalog/products', {inventory_level:0})
}

Paginate All Resources

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'})
}

Create a Resource

async function createDigitalProduct(name, price){
    return (await store.post('v3/catalog/products', {name, price, type:'digital', weight:0})).id
}

Update Resource

async function changePrice(id, price){
    try {
        await store.put(`v3/catalog/products/${id}`, {price}))
    } catch (new Error('ID not found'))
}

Delete a Resource

async function deleteProduct(id){
    try {
        await store.delete(`v3/catalog/products/${id}`))
    } catch (new Error('ID not found'))
}

Delete All Resources

async function deleteAllProducts(){
    await store.deleteAll(`v3/catalog/products`))
}