Node.js library

Reference3 min read

The official library for Node.js 18 and later. It has no dependencies.

npm install @notriv/node

Set up

import Notriv from '@notriv/node'
const notriv = new Notriv(process.env.NOTRIV_SECRET_KEY, {
  maxRetries: 2,      // retries network errors, 429 and 5xx
  timeoutMs: 60_000,
})

Methods

MethodEndpoint
envelopes.create(params)POST /v1/envelopes (pass file as a Buffer to upload)
envelopes.retrieve(id)GET /v1/envelopes/{id}
envelopes.list(query)GET /v1/envelopes
envelopes.send(id)POST /v1/envelopes/{id}/send
envelopes.void(id, reason)POST /v1/envelopes/{id}/void
envelopes.remind(id)POST /v1/envelopes/{id}/remind
envelopes.signingUrl(id, role)POST /v1/envelopes/{id}/signing_url
envelopes.download(id, kind)Downloads signed, audit_trail or original as bytes
templates.create / retrieve / list / update / del/v1/templates
webhookEndpoints.create / retrieve / list / update / del/v1/webhook_endpoints
events.list / retrieve/v1/events
account.retrieve() / balance.retrieve()/v1/account, /v1/balance
testHelpers.envelopes.complete(id)Test mode: sign for everyone
Notriv.webhooks.constructEvent(body, header, secret)Verifies and parses a webhook

Go through every page

for await (const envelope of notriv.list('/envelopes', { template: 'tmpl_purchase_agreement' })) {
  console.log(envelope.id, envelope.status)
}

Handle errors

import Notriv, { NotrivError } from '@notriv/node'

try {
  await notriv.envelopes.create(params)
} catch (error) {
  if (error instanceof NotrivError && error.code === 'missing_data') {
    console.log('Fill in:', error.raw.missing_keys)
  } else {
    throw error
  }
}

NotrivError has status, type, code, param, requestId and raw (the full error body).

Was this page helpful?