-
Notifications
You must be signed in to change notification settings - Fork 0
NodeJS SDK CloudCore documentation
The Cloudprinter.com NodeJS SDK is a package with useful features that enable developers to easily integrate their platform with Cloudprinter.com and make requests and posts to our CloudCore API. This NodeJS SDK makes it easy to set up the integration to request instant pricing, post-print orders and more.
The CloudCore API is designed to easy integration with any application or service.
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)
- nodejs 6.0 or above
- Cloudprinter.com Print Cloud account
The CloudCore SDK package can be installed with npm. Run this command:
npm i @cloudprinter/cloudcore --save
# Or, if you prefer yarn
yarn add @cloudprinter/cloudcore
Once you have completed the installation, you could make the first call. To write an app that uses the SDK, you will create your first NodeJs script that will create a CloudCore client. Look at Authentication to know how to get an API key.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
After the CloudCore client is created, you can work with Cloudprinter.com API.
cloudCoreClient.order.getList()
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Authentication is done via a predefined CloudCore API key. The CloudCore API key is found in the Cloudprinter.com Dashboard.
Errors can happen for many reasons: an expired token, or just used an invalid argument. In these cases, the returned Promise will reject with an Error. You should catch the error and use the information it contains to decide how your app can proceed.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
const orderReference = 'order-123';
cloudCoreClient.order.getInfo(orderReference)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Request the list of all orders.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
cloudCoreClient.order.getList()
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Request detailed order info by reference.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
const orderReference = 'order-123';
cloudCoreClient.order.getInfo(orderReference)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Add a new order including one or more items, addresses, options, and files. Files should be added with a URL from where Cloudprinter.com can fetch the files when the order has been accepted. An MD5 hash of the file is not required, but if you have one it will save the time of calculation. Look for more details in Documentation.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
const data = {
"reference": "order-1234",
"email": "test@mail.com",
"addresses": [
{
"type": "delivery",
"firstname": "John",
"lastname": "Doe",
"street1": "Street1",
"zip": "1071 JA",
"city": "Amsterdam",
"country": "NL",
"email": "test@mail.com",
"phone": "+31-655-538-848"
}
],
"items": [
{
"reference": "299",
"product": "brochure_pb_a5_p_fc",
"count": 68,
"files": [
{
"type": "cover",
"url": "https://s3-eu-west-1.amazonaws.com/demo.cloudprinter.com/b52f510a5e2419f67c4925153ec0c080_v2/CP_Sample_doc_A4_Book_Cover_Textbook_80_gsm_Casewrap_v2.1.pdf",
"md5sum": "15c518d3d105ecaaab014df2456dd22b"
},
{
"type": "book",
"url": "https://s3-eu-west-1.amazonaws.com/demo.cloudprinter.com/b52f510a5e2419f67c4925153ec0c080_v2/CP_Sample_doc_A4_Book_Interior_Textbook_v2.1.pdf",
"md5sum": "15c518d3d105ecaaab014df2456dd22b"
}
],
"options": [
{
"option_reference": "cover_finish_gloss",
"count": 1
},
{
"option_reference": "pageblock_80off",
"count": 1
},
{
"option_reference": "cover_130mcg",
"count": 1
},
{
"option_reference": "total_pages",
"count": 100
}
],
"quote": "8dfd769781297bcc9f38a61207bd6dcc729b7ce4fd77ed98c5e1105efd2d3160"
}
]
}
cloudCoreClient.order.create(data)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Reorders use the regular order create method, they just require a few extra parameters. Reorders are done on the item level. Only items from a single order can be included in a reorder. Look for more details in Documentation.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
const data = {
"reference": "order-2",
"email": "test@mail.com",
"addresses": [
{
"type": "delivery",
"firstname": "John",
"lastname": "Doe",
"street1": "Street1",
"zip": "1071 JA",
"city": "Amsterdam",
"country": "NL",
"email": "test@mail.com",
"phone": "+31-655-538-848"
}
],
"items": [
{
"reference": "item-1",
"product_reference": "textbook_cw_a4_p_bw",
"count": 1,
"reorder_cause": "cause",
"reorder_desc": "description",
"reorder_order_reference": "order-1",
"reorder_item_reference": "item-1",
"files": [
{
"type": "cover",
"url": "https://s3-eu-west-1.amazonaws.com/demo.cloudprinter.com/b52f510a5e2419f67c4925153ec0c080_v2/CP_Sample_doc_A4_Book_Cover_Textbook_80_gsm_Casewrap_v2.1.pdf",
"md5sum": "15c518d3d105ecaaab014df2456dd22b"
},
{
"type": "book",
"url": "https://s3-eu-west-1.amazonaws.com/demo.cloudprinter.com/b52f510a5e2419f67c4925153ec0c080_v2/CP_Sample_doc_A4_Book_Interior_Textbook_v2.1.pdf",
"md5sum": "15c518d3d105ecaaab014df2456dd22b"
}
],
"options": [
{
"option_reference": "cover_finish_gloss",
"count": 1
},
{
"option_reference": "pageblock_80off",
"count": 1
},
{
"option_reference": "cover_130mcg",
"count": 1
},
{
"option_reference": "total_pages",
"count": 100
}
],
"quote": "*"
}
]
};
cloudCoreClient.order.create(data)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Request cancellation of a specific order by reference.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
const orderReference = 'order-123';
cloudCoreClient.order.cancel(orderReference)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Request an order log by reference.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
const orderReference = 'order-123';
cloudCoreClient.order.getLog(orderReference)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Request an order quote. Cloudprinter.com provides a quote on product prices, shipping options, and shipping prices through the quote API endpoint. Each quote request returns both product prices and shipping options with pricing. Each quote has its unique hash, which has to be included in the order. A quote hash is valid for 48 hours.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
const data = {
"country": "NL",
"items": [
{
"reference": "99",
"product": "textbook_cw_a6_p_bw",
"count": 2,
"options": [
{
"type": "cover_finish_gloss",
"count": 1
},
{
"type": "pageblock_80off",
"count": 1
},
{
"type": "cover_130mcg",
"count": 1
},
{
"type": "total_pages",
"count": 100
}
]
}
]
}
cloudCoreClient.order.quote(data)
.then(function (response) {
console.log(response.shipments[0].quotes);
})
.catch(function (error) {
console.log(error);
});
Request detailed information about a quote hash.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const quoteHash = '8dfd769781297bcc9f38a61207bd6dcc729b7ce4fd77ed98c5e1105efd2d3160';
const cloudCoreClient = new CloudCore.Client(apiKey);
cloudCoreClient.order.quoteInfo(quoteHash)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Request a list of all Cloudprinter.com products.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const cloudCoreClient = new CloudCore.Client(apiKey);
cloudCoreClient.product.getList()
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Request detailed product information.
const CloudCore = require('@cloudprinter/cloudcore');
const apiKey = '*';
const productReference = 'flyer_ss_a4_fc';
const cloudCoreClient = new CloudCore.Client(apiKey);
cloudCoreClient.product.getInfo(productReference)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
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 feature requests and bug reports
- Email us in Cloudprinter.com developer support: support@cloudprinter.com