Billing
SDK methods for listing and reading your organisation's invoices and their line items.
The client.billing namespace reads your own organisation's invoices: GET /api/v1/billing/invoices (list) and GET /api/v1/billing/invoices/{id} (one invoice with its line items). Available in TypeScript, Python, and Go SDKs. See Invoices for the invoice lifecycle and every field.
| SDK | Install | Namespace |
|---|---|---|
| TypeScript | npm install @caldera/platformxe-sdk (1.18.0+, pending release) | client.billing |
| Python | pip install platformxe (1.14.0+, pending release) | client.billing (sync and async) |
| Go | go get github.com/calderaxe/platformxe-go (v1.14.0+, pending release) | client.Billing |
Requires the billing:read scope (not one of the scopes a self-registered or portal sign-up key starts with: a key holds it when its scope list names it or holds *, or when it has no scope list), and an organisation key: a platform key with no organisation is refused with 403 FORBIDDEN. Default rate tier (1,000 requests/hr per API key).
Money is in kobo. subtotal, tax and total, and a line item's unitPrice and total, are integer strings in kobo ("10642500" is ₦106,425.00); tax is the 7.5% VAT. Parse them as integers, never as floating point. pdfUrl is always null today. DRAFT invoices are listed.
List invoices
GET /api/v1/billing/invoices, newest first. page defaults to 1, limit to 20 (1 to 100); status filters on one of DRAFT, PENDING, PAID, OVERDUE, CANCELLED (anything else is 400 VALIDATION_ERROR).
const { invoices, pagination } = await client.billing.listInvoices({ status: 'PAID', page: 1, limit: 20 });
for (const invoice of invoices) {
const naira = Number(BigInt(invoice.total)) / 100;
console.log(invoice.id, invoice.status, invoice.periodStart, naira);
}
console.log(pagination.total, pagination.totalPages);
page = client.billing.list_invoices(status="PAID", page=1, limit=20)
for invoice in page["invoices"]:
print(invoice["id"], invoice["status"], int(invoice["total"]) / 100)
print(page["pagination"]["totalPages"])
# Async client
page = await async_client.billing.list_invoices(status="PAID")
list, err := client.Billing.ListInvoices(platformxe.ListInvoicesParams{Status: "PAID", Page: 1, Limit: 20})
if err != nil {
log.Fatal(err)
}
for _, invoice := range list.Invoices {
fmt.Println(invoice.ID, invoice.Status, invoice.Total)
}
fmt.Println(list.Pagination.TotalPages)
The answer is { invoices, pagination: { page, limit, total, totalPages } }. Each invoice is { id, status, currency, periodStart, periodEnd, subtotal, tax, total, paidAt, paidVia, pdfUrl, createdAt, updatedAt }.
Get one invoice
GET /api/v1/billing/invoices/{id}. An unknown id and another organisation's invoice are both 404 NOT_FOUND. The SDKs URL-encode the id.
const { invoice, lineItems } = await client.billing.getInvoice('inv_ck9q2w3e4r5t6y7u8i9o0p1a');
for (const line of lineItems) {
console.log(line.service, line.description, line.quantity, line.unitPrice, line.total);
}
detail = client.billing.get_invoice("inv_ck9q2w3e4r5t6y7u8i9o0p1a")
for line in detail["lineItems"]:
print(line["service"], line["description"], line["total"])
detail, err := client.Billing.GetInvoice("inv_ck9q2w3e4r5t6y7u8i9o0p1a")
if err != nil {
log.Fatal(err)
}
for _, line := range detail.LineItems {
fmt.Println(line.Service, line.Description, line.Total)
}
The answer is { invoice, lineItems }; a line item is { id, service, description, quantity, unitPrice, total }.
Errors
| Status | Code | When |
|---|---|---|
| 400 | VALIDATION_ERROR | List: unknown status |
| 401 | UNAUTHORIZED | Missing or invalid API key |
| 403 | FORBIDDEN | The key lacks billing:read; its organisation is inactive; or it is a platform key with no organisation |
| 404 | NOT_FOUND | Get: unknown id, or another organisation's invoice |
| 429 | RATE_LIMITED | Over the key's budget |
| 500 | INTERNAL_ERROR | Anything else |
Scopes required
| Method | Scope | Rate limit |
|---|---|---|
billing.listInvoices() | billing:read | Default (1,000/hr) |
billing.getInvoice() | billing:read | Default (1,000/hr) |