Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

pdffiller/pdffiller-nodejs-api-client

Repository files navigation

pdffiller-nodejs-api-client (api-v2)

NPM

PDFfiller API You can sign up for the API here.

API Docs.

Requirements

  • Node.js >= v4 but the latest stable version of NodeJS is recommended;

Installation

npm i pdffiller-nodejs-api-client --save

Quick getting started steps

You can require PDFfiller module as a singleton and use it in anywhere your app, or require constructor and create different instances:

const PDFfiller = require('pdffiller-nodejs-api-client').PDFfiller;
  
// or
  
const PDFfillerConstructor = require('pdffiller-nodejs-api-client').PDFfillerConstructor;

Or using ES6:

import { PDFfiller, PDFFillerConstructor } from 'pdffiller-nodejs-api-client';

Authentication

Access tokens will automatically initialize when you’re successfully retrieved from the given user's credentials. The second parameter auto_update when you set up it as true token will automatically update when expire

PDFfiller.auth.authorize({
    grant_type: 'password',
    client_id: 'your_client_id',
    client_secret: 'your_client_secret',
    username: 'username@mail.com',
    password: 'your_password'
}, true)
    .then(accessTokenData => console.log(accessTokenData))
    .catch(err => console.error(err));

When your authorization has been completed successfully you can use client for retrieving, creating, updating or deleting information from your profile.

Also you can set up token, for future request:

PDFfiller.auth.setAccessToken('your_access_token');

and get current access token:

PDFfiller.auth.getAccessToken();

Usage

Use a method to retrieve a list of all applications:

PDFfiller.applications.all()
  .then(applications => console.log(applications))
  .catch(err => console.error(err));

Use a method to retrieve an applications by id:

PDFfiller.applications.get(application_id)
    .then(application => console.log(application))
    .catch(err => console.error(err));

Use a method to create an application:

PDFfiller.applications.create({
    name: 'app name',
    description: 'app description',
    domain: 'http://domain.com'
})
    .then(application => console.log(application))
    .catch(err => console.error(err));

Use a method to update an application by id:

PDFfiller.applications.update(application_id, {
    name: 'app name',
    description: 'app description',
    domain: 'http://domain.com'
})
    .then(application => console.log(application))
    .catch(err => console.error(err));

Use a method to delete an application by id:

PDFfiller.applications.remove(application_id)
    .then(result => console.log(result))
    .catch(err => console.error(err));

Use a method to get application users:

PDFfiller.applications.users(application_id)
    .then(users => console.log(users))
    .catch(err => console.error(err));

All examples with other endpoints are available in the docs folder.

Working with files

We send request using request-promise library, so to send a file you can just pass a file stream, for example:

const fs = require('fs');  
 
PDFfiller.templates.create({
   file: fs.createReadStream('./file.pdf'),
   name: 'test_file_load.pdf'
})
   .then(createdTemplateInfo => console.log(createdTemplateInfo))
   .catch(err => console.error(err));

When you download files we will return Buffer object after you can save it as in example:

const fs = require('fs');
 
PDFfiller.templates.download(template_id)
   .then(templateFileBuffer => {
       fs.writeFile('./your_file_name.pdf', templateFileBuffer, (err) => {
           if (err) {
               console.log(err);
               return;
           }
           console.log('successfully saved');
       });
   })
   .catch(err => console.error(err));

Callback support

Methods provide not only Promise api, you can use callbacks if you want. You can pass callback function to all methods as last argument, in this case methods dont return a Promise:

const fs = require('fs');
  
PDFfiller.templates.create({
    file: fs.createReadStream('./file.pdf'),
    name: 'test_file_load.pdf'
}, (err, response, body) => {
    if (err) {
        console.log(err);
    }
    // YOUR CODE
    }
);
PDFfiller.auth.authorize({
    grant_type: 'password',
    client_id: 'your_client_id',
    client_secret: 'your_client_secret',
    username: 'username@mail.com',
    password: 'your_password'
}, false, (err, body) => {
    if (err) {
        console.log(err);
    }
    // YOUR CODE
    }
);

Support

If you have any problems feel free to contact us:

License

This software is licensed under the following MIT license

Contributing

See CONTRIBUTING.

Author

API Team (integrations@pdffiller.com)