bigcommerce-client
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i bigcommerce-client

Weekly Downloads

1

Version

1.4.0

License

ISC

Unpacked Size

15.3 kB

Total Files

4

Last publish

Collaborators

  • hunter.shaw