-
Notifications
You must be signed in to change notification settings - Fork 0
NodeJS SDK CloudSignal documentation
The Cloudprinter.com CloudSignal NodeJS SDK is a package that helps your app respond to events from Cloudprinter.com
We at Cloudprinter.com have connected 150+ printers to print & ship print products in almost any country in the world. Whether this is around the corner or on the other side of the globe, we've got you covered: we can deliver 500+ different products in more than 100 countries currently.
Our platform makes use of smart routing algorithms to route any print job to the most local and qualified printer. Based on location, performance, price and production options, your print job is routed by these algorithms to the nearest printing facility near your delivery address to help you save on transit times and costs.
Visit our website for more information on all the products and services that we offer.
- npm (for installation)
- node 6.0 or above
- Cloudprinter.com Print API account
The CloudSignal SDK package can be installed with npm. Run this command:
npm i @cloudprinter/cloudsignal --save
Or, if you prefer yarn:
yarn add @cloudprinter/cloudsignal
Once you have completed the installation, you could write an app that uses the SDK, you will create your first NodeJs script that will create a CloudSignal event handler. Look at CloudSignal Api Key to learn how to get an API key.
const CloudSignal = require('@cloudprinter/cloudsignal');
// The port the server is going to listen on. Defaults to 8100.
const port = 8100;
const cloudSignalApiKey = '*';
const eventHandler = new CloudSignal.EventHandler(cloudSignalApiKey, port);
After that you can handle signals:
eventHandler.on('ItemCanceled', (signalData) => {
// handle
});
Each client can have one RESTful API endpoint for use with CloudSignal Webhooks. You need a public URL where the app can begin receiving events. To register this URL need to the Cloudprinter.com Dashboard.
Each account is associated with an API key, which is used as authentication in all API calls. Each webhook request includes a Webhook API key, which is different from the account API key. This Webhook API key should be validated on each request. It can be found in the Cloudprinter.com Dashboard.
In case an error is thrown inside a listener, it must be handled, to prevent your application from terminating unexpectedly. This event handler allows you to define an error handler for catching errors thrown inside any of the listeners, using the .on(‘error’, handlerFn) method. It is best practice to log any errors.
eventHandler.on('error', (errorData) => {
// handle
});
Order received and validated by Cloudprinter.com.
eventHandler.on('CloudprinterOrderValidated', (signalData) => {
// handle
});
Order canceled by Cloudprinter.com.
eventHandler.on('CloudprinterOrderCanceled', (signalData) => {
// handle
});
Item received and validated by the production.
eventHandler.on('ItemValidated', (signalData) => {
// handle
});
Production has started for an item.
eventHandler.on('ItemProduce', (signalData) => {
// handle
});
Production completed for item.
eventHandler.on('ItemProduced', (signalData) => {
// handle
});
Item has been packed.
eventHandler.on('ItemPacked', (signalData) => {
// handle
});
Item has been shipped. The tracking code for the packet is included in this signal.
eventHandler.on('ItemShipped', (signalData) => {
// handle
});
Item has a problem or an error. This could be due to a print error or failure in the quality check etc.
eventHandler.on('ItemError', (signalData) => {
// handle
});
Confirmation that an item has been canceled in production and in Cloudprinter.com. Cancel requests are normally based on a request by the client.
eventHandler.on('ItemCanceled', (signalData) => {
// handle
});
It can be useful when you want to handle more than one event in one function.
eventHandler.onAny(['ItemShipped', 'ItemCanceled'], (signalData) => {
// handle
});
If you get stuck, we're here to help. The following are the best ways to get assistance working through your issue:
- Issue Tracker for questions, feature requests and bug reports
- Email us in Cloudprinter.com developer support: support@cloudprinter.com