Skip to content

Instantly share code, notes, and snippets.

@georgemandis
Forked from jaredh159/lulu.js
Created July 16, 2023 23:15
Show Gist options
  • Save georgemandis/ab12706ddfd35c9376d64abf8b58590f to your computer and use it in GitHub Desktop.
Save georgemandis/ab12706ddfd35c9376d64abf8b58590f to your computer and use it in GitHub Desktop.
lulu api node.js create print order
const request = require('request');
const ClientOAuth2 = require('client-oauth2')
const clientId = 'YOUR_CLIENT_ID';
const clientSecret = 'YOUR_CLIENT_SECRET';
var luluAuth = new ClientOAuth2({
clientId,
clientSecret,
accessTokenUri: 'https://api.lulu.com/auth/realms/glasstree/protocol/openid-connect/token',
});
const podPackageId = [
'0600X0900', // page size (6"x9")
'BW', // interior color
'STD', // standard quality
'PB', // perfect bound
'060UW444', // 60# uncoated white paper with a bulk of 444 pages per inch
'G', // Glossy cover (`M`: matte)
'X', // no linen,
'X', // no foil
].join('');
(async () => {
const { accessToken } = await luluAuth.credentials.getToken()
var options = {
method: 'POST',
url: 'https://api.lulu.com/print-jobs/',
headers: {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`
},
body: {
"external_id": "8c5284e0-40a2-4afc-9aa0-9e90f09b9de7", // optional
"line_items": [
{
"external_id": "70f3fa1e-7472-4a0b-b3e4-db9eebad2261", // optional
"pod_package_id": podPackageId,
"quantity": 1,
"interior": {
"source_url": "https://site.com/book.pdf"
},
"cover": {
"source_url": "https://site.com/cover.pdf"
}
}
],
"shipping_option_level": "MAIL",
"contact_email": "me@example.com",
"shipping_address": {
"name": "John Doe",
"street1": "123 Test Street",
"city": "Testtown",
"state_code": "NC",
"country_code": "US",
"postcode": "12345",
"phone_number": "844-212-0689"
}
},
json: true,
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment