npm

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

0.0.502 • Public • Published

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);

Package Sidebar

Install

npm i brightpearl-client

Weekly Downloads

6

Version

0.0.502

License

MIT

Unpacked Size

5.68 kB

Total Files

3

Last publish

Collaborators

  • builddirectdev
  • bdplatform