@anvilco/anvil
Anvil API Client
Last updated 2 months ago by ralbayaty .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @anvilco/anvil 
SYNC missed versions from official npm registry.

Anvil API Client for Node

Anvil is a suite of tools for managing document-based workflows:

  1. Anvil Workflows converts your PDF forms into simple, intuitive websites that fill the PDFs and gather signatures for you.
  2. Anvil PDF Filling API allows you to fill any PDF with JSON data.

Currently, this node client only supports our PDF filling API.

Usage

yarn add @anvilco/anvil
npm install @anvilco/anvil

A basic example converting your JSON to a filled PDF, then saving the PDF to a file:

import fs from 'fs'
import Anvil from '@anvilco/anvil'

// The ID of the PDF template to fill
const pdfTemplateID = 'kA6Da9CuGqUtc6QiBDRR'
// Your API key from your Anvil organization settings
const apiKey = '7j2JuUWmN4fGjBxsCltWaybHOEy3UEtt'

// JSON data to fill the PDF
const exampleData = {
  "title": "My PDF Title",
  "fontSize": 10,
  "textColor": "#CC0000",
  "data": {
    "someFieldId": "Hello World!"
  }
}
const anvilClient = new Anvil({ apiKey })
const { statusCode, data } = await anvilClient.fillPDF(pdfTemplateID, exampleData)

console.log(statusCode) // => 200

// Data will be the filled PDF raw byes
fs.writeFileSync('output.pdf', data, { encoding: null })

API

new Anvil({ apiKey })

Creates an Anvil client instance.

  • apiKey (String) - your API key from your Anvil organization settings
const anvilClient = new Anvil({ apiKey })

Anvil::fillPDF(pdfTemplateID, payload)

Fills a PDF with your JSON data.

First, you will need to have uploaded a PDF to Anvil. You can find the PDF template's id on the API Info tab of your PDF template's page:

pdf-template-id

An example:

const pdfTemplateID = 'kA6Da9CuGqUtc6QiBDRR'
// Your API key from your Anvil organization settings
const apiKey = '7j2JuUWmN4fGjBxsCltWaybHOEy3UEtt'

// JSON data to fill the PDF
const payload = {
  "title": "My PDF Title",
  "fontSize": 10,
  "textColor": "#CC0000",
  "data": {
    "someFieldId": "Hello World!"
  }
}
const anvilClient = new Anvil({ apiKey })
const { statusCode, data } = await anvilClient.fillPDF(pdfTemplateID, payload)
  • pdfTemplateID (String) - The id of your PDF template from the Anvil UI
  • payload (Object) - The JSON data that will fill the PDF template
    • title (String) - optional Set the title encoded into the PDF document
    • fontSize (Number) - optional Set the fontSize of all filled text. Default is 10.
    • color (String) - optional Set the text color of all filled text. Default is dark blue.
    • data (Object) - The data to fill the PDF. The keys in this object will correspond to a field's ID in the PDF. These field IDs and their types are available on the API Info tab on your PDF template's page in the Anvil dashboard.
      • For example { "someFieldId": "Hello World!" } }
  • Returns a Promise that resolves to an Object
    • statusCode (Number) - the HTTP status code; 200 is success
    • data (Buffer) - The raw binary data of the filled PDF if success
    • errors (Array of Objects) - Will be present if status >= 400. See Errors
      • message (String)

Rate Limits

Our API has request rate limits in place. This API client handles 429 Too Many Requests errors by waiting until it can retry again, then retrying the request. The client attempts to avoid 429 errors by throttling requests after the number of requests within the specified time period has been reached.

See the Anvil API docs for more information on the specifics of the rate limits.

More Info

See the PDF filling API docs for more information.

Examples

Check out the example folder for running usage examples!

Development

First install the dependencies

yarn install

Running tests

yarn test
yarn test:watch

Building with babel will output in the /lib directory.

yarn test

# Watches the `src` and `test` directories
yarn test:watch

Current Tags

  • 2.0.0                                ...           latest (2 months ago)

2 Versions

  • 2.0.0                                ...           2 months ago
  • 1.0.3                                ...           4 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 2
Last Month 6
Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |