applidok
v1.0.4
Published
Client API for Applidok PDF templating
Downloads
4
Maintainers
Readme
Node.js client API for Applidok
This Node.js API allows to call PDF templating features exposed by Applidok.
Get started
This package can be installed as NPM package: npm install applidok
Then applidok
module can be required in your Node.js code: var applidok = require("applidok")
The main function to merge data (e.g. form submission) with PDF template managed on Applidok is applidok.merge
:
var applidok = require("applidok");
applidok.merge(options/* see details bellow */);
Example
Some examples using this module are available in the repository: see simple example.
var applidok = require("applidok");
applidok.merge({
// Mandatory options
token:"a610e9b1048499110433bb790489303a07182aac"/*replace by your token*/,
template:"ca62e08d-2082-4cd4-837c-d46a362091e3"/*replace by your template*/,
success: function(res){ // Success handler
console.log("Will save merged document as document.pdf file");
res.pipe(fs.createWriteStream("document.pdf"));
},
error: function(httpStatus){ // Optional, custom error handler
console.error("Oups! Got an error: " + httpStatus)
},
parameters: { // Name-value pairs corresponding to template areas
'firstName': "First name"
}
});
API reference
The module is exposing following Applidok functions.
merge
.merge(options)
: Merge values with specified template;
Object options
is expecting following properties.
token
: Applidok application token (string
).template
: ID of Applidok template (string
).parameters
: Name/value pairs to be merged with areas (object
).success
: Success callback, is given a HTTP response as argument; Optional function, if undefined default handler (console.log
) is used.error
: Error callback, is given HTTP error code (int) as argument; Optional function, if undefined default handler (console.error
) is used.
Application token and template ID are visible in Integration tab on Template screen of Applidok management.
See code sample
auth
.auth(options)
: Authenticate and get the administration token to be able to manage the corresponding Applidok account.
email
: Applidok login (string
).password
: Applidok password (string
, cleartext)success
: Success callback, is given the admin token as argument; Optional, if undefined default handler (console.log) is used.- error: Error callback, is given error details as argument (e.g.
{'code':123, 'cause':"Error cause"}
; Optional, if undefined default handler (console.error) is used.
See code sample
Template list
.templateList(options)
: List the templates of Applidok account specified by the given administration token.
var dok = require("applidok");
dok.templateList({
// replace by your admin token, see `dok.auth`
token: "c64ca212064c8588b9c5f4a2d9165399b99aa83c",
success: function(res){ // Success handler
// res = http://nodejs.org/api/http.html#http_event_response
console.log("List of Applidok templates: " + JSON.stringify(res));
},
error: function(httpStatus){ // Optional, custom error handler
console.error("Oups! Got an error: " + httpStatus)
}
});
The success handler is given an object with following properties.
```javascript
{
"token": "app_token",
"activePlan": { "credits":1 },
"templates": [
{ "id": "tmpl-1", "name": "Template #1", "expiration":1418833775372 },
{ "id": "tmpl-2", "name": "Second template" },
{ "id": "tmpl-3", "name": "The third one" },
{ "id": "tmpl-4", "name": "Template #4",
"expiration":1418228986489, "trial":true }
]
}