gov-delivery-node

1.0.0 • Public • Published

gov-delivery-node

An unofficial Node.js client library for GovDelivery's APIs

  • [x] Communications Cloud
  • [ ] Script Service API
  • [ ] Targeted Messaging
  • [ ] Interactive Text

Quick start

Install

npm install --save gov-delivery-node

Usage

⚠️ While obvious to some, it is strongly recommended to store usernames, passwords and tokens in environment variables, e.g. const username = process.env.USERNAME

const { CommunicationsCloud } = require('gov-delivery-node')

const baseUrl = process.env.BASE_URL // https://stage-api.govdelivery.com
const accountCode = process.env.ACCOUNT_CODE // 'CODE'
const username = process.env.USERNAME
const password = process.env.PASSWORD

// `new` is optional; returns a new client object regardless
const client = new CommunicationsCloud({ baseUrl, accountCode, username, password })

If your prefer explicitly linking objects over using JavaScript classes:

const { CommunicationsCloud } = require('gov-delivery-node/communications-cloud')

/* ... */

const client = Object.create(CommunicationsCloud)
client.initialize({ baseUrl, accountCode, username, password })

This library is promise-based:

client.subscriptions
  .add(/* ... */)
  .then(data => {
    /* handle formatted response data... */
  })
  .catch(error => {
    /* handle error... */
  )

Or using async/await:

try {
  const data = await client.subscriptions.add(/* ... */)
} catch (error) {
  /* handle errors ... */
}

API Documentation

See the official API documentation from GovDelivery.

Package Sidebar

Install

npm i gov-delivery-node

Weekly Downloads

1

Version

1.0.0

License

CC0-1.0

Unpacked Size

10.6 kB

Total Files

9

Last publish

Collaborators

  • sbads