ccrm
Node.js library for interacting with Continuity CRM API
Use
Install from npm:
npm install --save ccrm
The export of this package is a function that takes a single argument of an object with a (usually) required config
prop and an optional logger
prop. The config is defined as: { url?: string, apiKey: string }
. The url
is optional in the sense that the default cloud hosted instance of CCRM does not require it. The API key must be provided, but for scenarios where it can't be passed in programatically, the CCRM_API_KEY
env var can be used instead. Example:
const CCRM = ; const config = apiKey: '11111-1111-1111-1111'; const ccrm = ;
ccrm
is now a configured instance of the transport client.
Functions
newPartial(partialPayload: PartialData) => Promise<OrderResponse>
newPartial
takes a single argument of type PartialData
, defined as:
and returns a Promise that resolves to the CRM response data (but camel-cased, for your convenience). The important part of the response object is the partialId
prop, which contains the id of the partial / prospect for you to save to your application for later use.
newOrder(customer: CustomerData, products: ProductData, payment: PaymentData) => Promise<OrderResponse>
newOrder
takes three arguments in order of their types, defined as:
CustomerData ProductData Array<> PaymentData
Note that if a product includes promoPrice
without the rebillDiscount
and/or discountCycleCount
properties, they will be populated for you. This function returns a Promise that resolves to the CRM response data (but camel-cased, for your convenience). See example response data:
newOrderOnPartial(partialId: string | number, products: ProductData, payment: PaymentData) => Promise<OrderResponse>
newOrderOnPartial
takes three arguments - the partialId
on which to place the order, and then the ProductData
and PaymentData
, as previously defined above (see the newOrder
function definition). The response is also nearly identical to the newOrder
response as well. The main difference is you provide the partialId
in lieu of the full set of customer data.
upsellOnOrder(orderId: string | number, products: ProductData) => Promise<OrderResponse>
upsellOnOrder
is similar to the previous functions, but takes only an existing orderId
plus a new ProductData
array. No customer data or payment data is needed, as the data saved from the previous order is reused. The response data is also nearly identical to the newOrder
response.
findOrder(options: FindOrderOptions) => Promise<OrderResponse[]>
findOrder
takes a single options property defined as:
FindOrderOptions
and returns a promise resolving to an array of OrderResponse
's similar to the example above.
getOrder(orderId: string | number) => Promise<OrderResponse[]>
getOrder
simply takes an order id and returns the appropriate OrderResponse
similar to the above examples.
getProvinces(country: string) => Promise<Subdivision[]>
getProvinces
takes a string representing a country abbreviation and returns a promise resolving to an array of Subdivision
, defined as:
Subdivision
getTaxForProduct(productId: number, country: string) => Promise<{ taxAmount: number }>
Logger
The exported function also takes an optional logger function. This is called throughout the req->res cycle and hands back various data points for you to log as you please. The shape of the object returned via this callback is:
Debugging
ccrm
uses the debug
library. Run your application with the env var DEBUG=ccrm
to get debugging information related to transport and raw responses.