Trailpack to send physical mail with Lob API
With yo:
$ yo trails:trailpack trailpack-lob
With npm:
$ npm install --save trailpack-lob
// config/main.js
module.exports = {
packs: [
// ... other trailpacks
require('trailpack-lob')
]
}
// config/lob.js
module.exports = {
apiKey: 'Your API key',
/**
* Options to pass during lob initialisation
* @see https://github.com/lob/lob-node#options
*/
options: {},
/**
* From address used to send letters
* Can be an object or an ID
*/
from: {
name: 'Person',
address_line1: '123 Test',
address_line2: 'Unit 200',
address_city: 'Chicago',
address_state: 'IL',
address_zip: '60012',
address_country: 'US'
}
}
Native usage of lob API :
this.app.packs.lob.api.letters.create({
description: 'My First Letter',
to: {
name: 'Test Person',
address_line1: '123 Test Street',
address_line2: 'Unit 200',
address_city: 'Chicago',
address_state: 'IL',
address_zip: '60012',
address_country: 'US'
},
from: {
name: 'Test Person',
address_line1: '123 Test Street',
address_line2: 'Unit 200',
address_city: 'Chicago',
address_state: 'IL',
address_zip: '60012',
address_country: 'US'
},
file: '<html>...</html>',
data: {
name: 'Robin'
},
color: false
}).then(letter => {...})
Usage with the Trails service:
this.app.services.LobService.sendLetter(to, file, data, more).then(letter => {...})
this.app.services.LobService.sendPostcard(to, front, back, data, more).then(postcard => {...})
Hey dude! Help me out for a couple of 🍻!