JSPM

  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q38333F
  • License MIT

Brightpearl API Typescript client

Package Exports

  • brightpearl-client
  • brightpearl-client/build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (brightpearl-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Brightpearl Client

NPM

Usage

  • Setup
const privateAppParams: BrightpearlClientParams = {
     dataCenter: "use",
     account: "OrgAccount",
     headers: {
        "brightpearl-app-ref": "privateAppRef",
        "brightpearl-account-token": "privateAppToken"
    }   
}
const publicAppParams: BrightpearlClientParams = {
     dataCenter: "use",
     account: "OrgAccount",
     headers: {
        "brightpearl-dev-ref": "publicDevRef",
        "brightpearl-app-ref": "publicAppRef"
     },
     publicAppCredentials: {
        clientId: "clientId",
        clientSecret: "clientSecret",
        refreshToken: "refreshToken"
    }
}

const brightPearlClient = new BrightpearlClient(Axios, privateAppParams | publicAppParams);
  • Get Sales Order
const orders: SalesOrderInformation[] = await brightPearlClient.getSalesOrders([100743]);
  • Update multiple freeform custom fields
/*
Set cache lookups to true to reduce # of calls to Brightpearl until next instantiation
Find Purchase Order custom fields Accepted and Date Of Acceptance
 */
const customFieldHelper = new CustomField(brightPearlClient, true);
const [acceptedField, dateOfAcceptanceField] = await Promise.all<CustomFieldMetadataInformation>([
    customFieldHelper.find("Accepted", OrderType.PURCHASE_ORDER),
    customFieldHelper.find("Date Of Acceptance", OrderType.PURCHASE_ORDER)
])

// Build Requests
const acceptedFieldRequest = customFieldHelper.buildFreeformRequest<boolean>(acceptedField.code, true, CustomFieldOperation.ADD);
const dateOfAcceptanceRequest = customFieldHelper.buildFreeformRequest<string>(dateOfAcceptanceField.code, new DateTime().toISOString(), CustomFieldOperation.ADD);

// Update custom fields
await customFieldHelper.update<boolean | string>(100743, [acceptedFieldRequest, dateOfAcceptanceRequest]);
  • Update Order Status
// Set cache lookups to true to reduce # of calls to Brightpearl until next instantiation
const orderStatusHelper = new OrderStatus(brightpearlClient, true);

// Update Order Status by ID
const newWebOrderStatusId = 12;
const orderStatusRef: OrderStatusUpdateRef = {
    statusId: newWebOrderStatusId
}
await orderStatusHelper.update(10001, orderStatusRef);

// Update Order Status by name
const newWebOrderStatusName = "New Web Order";
const orderStatusRef: OrderStatusUpdateRef = {
    statusInfo: {
        name: newWebOrderStatusName,
        orderTypeCode: OrderTypeCode.SALES_ORDER
    }
}
await orderStatusHelper.update(10001, orderStatusRef);