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)
Make sure you have npm or yarn installed.
npm i billogram-api-client
# or
yarn add billogram-api-client
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()
.
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 })
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.'
})
}
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
})
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)
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)
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)
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