Created
September 8, 2018 22:25
-
-
Save jaredh159/94e70976287ce96150ff7a542b51a32a to your computer and use it in GitHub Desktop.
lulu api node.js create print order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
})(); |
@Davo40 when you hit that auth url, you get a json object back that looks like this (this is Swift, but it should be easy to understand):
struct CredentialsResponse: Decodable {
let accessToken: String
let expiresIn: Double
}
the accessToken
is a long string, you pass as a bearer
token, as a header with the rest of your requests, like:
var headers = {
Authorization: `Bearer <your token here>`,
}
@Davo40 i used to have this all in javascript, but i've got it implemented in Swift now, but if it's helpful, you can see the basic implementation here:
https://github.com/friends-library-dev/api/tree/master/Sources/App/Integrations/Lulu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi mate really quick question on this one as im fairly new to all this. if the
Token URI = https://api.lulu.com/auth/realms/glasstree/protocol/openid-connect/token
what is the Authorisation URI =
im just having issues trying to set up this link inside make.com