0.1.3 • Published 5 years ago

billogram-api-client v0.1.3

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

Billogram API Client

A promise-based client for Billogram's API.

Example usage:

import Billogram from 'billogram-api-client'

const client = new Billogram({
  username: API_USER,
  password: API_PASSWORD
})

/* inside async function */
const billogram = await client.billograms.find(id)

How to use

Create an API user within the Billogram UI.

Import the package and create a client with your user credentials:

import Billogram from 'billogram-api-client'

const client = new Billogram({
  username: 'your-api-user',
  password: 'your-api-password',
})

All methods are namespaced under the objects they relate to: billograms, customers, and items.

All methods return the resource they are acting upon, with the exception of client.billograms.pdf().

Examples

So for example if you want to find a customer by their customer number you would use:

const customer = await client.customers.find(1)

If you wanted to create an item you would use:

const item = await client.items.create({ ...itemData })

Promise-based

Each method returns a promise so you can use either then/catch or async/await.

client.billograms
  .remind(billogramId, {
    method: 'Email',
    message: 'Please pay me.'
  })
  .then(data => console.log('Reminder sent:', data))
  .catch(error => console.error('Could not send reminder:', error))

/* or */

async function sendReminder(billogramId) {
  const billogram = await client.billograms.remind(billogramId, {
    method: 'Email',
    message: 'Please pay me.'
  })
}

If you want to use a sandbox account

Pass a config object as the second argument to the Billogram constructor with sandbox: true.

const client = new Billogram({
  username: 'sandbox-api-user',
  password: 'sandbox-api-password',
}, {
  sandbox: true
})

Available methods

Billograms

These methods map all api endpoints listed at:

client.billograms.create(data)
client.billograms.list(params)
client.billograms.find(id)
client.billograms.update(id, data)
client.billograms.send(id, data)
client.billograms.sell(id)
client.billograms.resend(id, data)
client.billograms.remind(id, data)
client.billograms.collect(id)
client.billograms.payment(id, data)
client.billograms.credit(id, data)
client.billograms.writeoff(id)
client.billograms.writedown(id)
client.billograms.revertWritedown(id)
client.billograms.respite(id, data)
client.billograms.removeRespite(id)
client.billograms.message(id, data)
client.billograms.attach(id, data)
client.billograms.pdf(id, params)

Customers

These methods map to the Customer endpoints listed here:

client.customers.create(data)
client.customers.list(params)
client.customers.find(customerNumber)
client.customers.update(customerNumber, data)

Items

These methods map to the Item endpoints listed here:

client.items.create(data)
client.items.list(params)
client.items.find(itemNumber)
client.items.update(itemNumber, data)
client.items.delete(itemNumber)

Tests

Register or login to the Sandbox.

Create a .env file in the root directory with your sandbox user credientials with the following keys:

TEST_API_USER=your-api-user
TEST_API_PASSWORD=your-api-password
TEST_API_EMAIL=your@email.com (optional)

You can optionally add your email to get the customer emails.

If you haven't already install packages npm run install and run:

npm run test