Giter Club home page Giter Club logo

billogram's Introduction

Billogram API Client

npm version npm bundle size licence

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)

Installation

Make sure you have npm or yarn installed.

npm i billogram-api-client
# or
yarn add billogram-api-client

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=[email protected] (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

billogram's People

Contributors

davecalnan avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.