Skip to main content

Billing API

This page documents the 17 gateway endpoints tagged billing in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
POST/billing/account/newCreate a billing account
POST/billing/account/updateChange a billing account
DELETE/billing/account/deleteDelete a billing account
GET/billing/account/infoShow one billing account
GET/billing/account/listList billing accounts
POST/billing/account/suspendSuspend a billing account
POST/billing/account/reinstateReinstate a billing account
GET/billing/usagePreview what an invoice would contain
POST/billing/invoice/generateGenerate a draft invoice
POST/billing/invoice/generate_allGenerate draft invoices for every account
POST/billing/invoice/issueIssue a draft invoice
POST/billing/invoice/mark_paidMark an invoice paid
POST/billing/invoice/voidVoid an unpaid invoice
GET/billing/invoice/infoShow one invoice
GET/billing/invoice/listList invoices
GET/billing/invoice/exportDownload an invoice as CSV
POST/billing/webhook/stripeReceive Stripe webhook events

Endpoints​

POST /billing/account/new​

Create a billing account

Create the billing account for a team, an organization or an end user, so its spend can be invoiced.

Each scope has at most one account, and the team, organization or end user must already exist (a 404 otherwise, a 409 when it already has an account). markup_percent is added on top of provider spend, tax_percent after markup, and grace_period_days says how long an issued invoice has before it is due. Proxy admins only, needs a license that includes billing.

Docs

Request body (application/json, schema NewBillingAccount):

FieldTypeRequiredDescription
scope_typeenum: "team", "organization", "end_user"YesScope Type
scope_idstringYesScope Id
display_namestringYesDisplay Name
billing_emailstring or nullNoBilling Email
currencystringNoCurrency
markup_percentnumberNoMarkup Percent
tax_percentnumberNoTax Percent
payment_providerenum: "manual", "stripe"NoPayment Provider
grace_period_daysintegerNoGrace Period Days
auto_suspendbooleanNoAuto Suspend
metadataobjectNoMetadata

Example request:

curl -X POST "http://localhost:4000/billing/account/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"scope_type": "team",
"scope_id": "team-nlp",
"display_name": "NLP team",
"billing_email": "nlp-finance@example.com",
"markup_percent": 10,
"payment_provider": "stripe",
"auto_suspend": true
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_BillingAccountTable
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
409Conflictapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
account_idstringYesAccount Id
scope_typeenum: "team", "organization", "end_user"YesScope Type
scope_idstringYesScope Id
display_namestringYesDisplay Name
billing_emailstring or nullNoBilling Email
currencystringYesCurrency
markup_percentnumberYesMarkup Percent
tax_percentnumberYesTax Percent
statusenum: "active", "past_due", "suspended"YesStatus
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_customer_idstring or nullNoStripe Customer Id
grace_period_daysintegerYesGrace Period Days
auto_suspendbooleanYesAuto Suspend
metadataobjectYesMetadata
created_bystringYesCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /billing/account/update​

Change a billing account

Change the pricing, payment provider or suspension terms of an account. Only the fields you send change.

The scope an account bills cannot change, so delete the account and create a new one for a different team, organization or end user. A body with nothing but account_id is a 400. Proxy admins only.

Docs

Request body (application/json, schema UpdateBillingAccount):

FieldTypeRequiredDescription
account_idstringYesAccount Id
display_namestring or nullNoDisplay Name
billing_emailstring or nullNoBilling Email
currencystring or nullNoCurrency
markup_percentnumber or nullNoMarkup Percent
tax_percentnumber or nullNoTax Percent
payment_providerenum: "manual", "stripe" or nullNoPayment Provider
grace_period_daysinteger or nullNoGrace Period Days
auto_suspendboolean or nullNoAuto Suspend
metadataobject or nullNoMetadata

Example request:

curl -X POST "http://localhost:4000/billing/account/update" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f",
"markup_percent": 12.5,
"grace_period_days": 14
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_BillingAccountTable
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
account_idstringYesAccount Id
scope_typeenum: "team", "organization", "end_user"YesScope Type
scope_idstringYesScope Id
display_namestringYesDisplay Name
billing_emailstring or nullNoBilling Email
currencystringYesCurrency
markup_percentnumberYesMarkup Percent
tax_percentnumberYesTax Percent
statusenum: "active", "past_due", "suspended"YesStatus
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_customer_idstring or nullNoStripe Customer Id
grace_period_daysintegerYesGrace Period Days
auto_suspendbooleanYesAuto Suspend
metadataobjectYesMetadata
created_bystringYesCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

DELETE /billing/account/delete​

Delete a billing account

Delete an account that has no draft or open invoice, and return the account that was removed.

Settled invoices are kept for the books. An account with a draft or open invoice is a 400, so void or settle those first. Proxy admins only.

Docs

Request body (application/json, schema BillingAccountRef):

FieldTypeRequiredDescription
account_idstringYesAccount Id

Example request:

curl -X DELETE "http://localhost:4000/billing/account/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_BillingAccountTable
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
account_idstringYesAccount Id
scope_typeenum: "team", "organization", "end_user"YesScope Type
scope_idstringYesScope Id
display_namestringYesDisplay Name
billing_emailstring or nullNoBilling Email
currencystringYesCurrency
markup_percentnumberYesMarkup Percent
tax_percentnumberYesTax Percent
statusenum: "active", "past_due", "suspended"YesStatus
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_customer_idstring or nullNoStripe Customer Id
grace_period_daysintegerYesGrace Period Days
auto_suspendbooleanYesAuto Suspend
metadataobjectYesMetadata
created_bystringYesCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

GET /billing/account/info​

Show one billing account

Return the account with account_id, or a 404 when there is none. Proxy admins and admin viewers only. Docs

Parameters:

NameInTypeRequiredDescription
account_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/billing/account/info?account_id=account_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_BillingAccountTable
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
account_idstringYesAccount Id
scope_typeenum: "team", "organization", "end_user"YesScope Type
scope_idstringYesScope Id
display_namestringYesDisplay Name
billing_emailstring or nullNoBilling Email
currencystringYesCurrency
markup_percentnumberYesMarkup Percent
tax_percentnumberYesTax Percent
statusenum: "active", "past_due", "suspended"YesStatus
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_customer_idstring or nullNoStripe Customer Id
grace_period_daysintegerYesGrace Period Days
auto_suspendbooleanYesAuto Suspend
metadataobjectYesMetadata
created_bystringYesCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

GET /billing/account/list​

List billing accounts

Page through the billing accounts, newest first, optionally only one scope_type (team, organization, end_user) or one status (active, past_due, suspended). page_size goes up to 100. Proxy admins and admin viewers only. Docs

Parameters:

NameInTypeRequiredDescription
scope_typequeryenum: "team", "organization", "end_user" or nullNo
statusqueryenum: "active", "past_due", "suspended" or nullNo
pagequeryintegerNo
page_sizequeryintegerNo

Example request:

curl -X GET "http://localhost:4000/billing/account/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json BillingAccountListResponse
403Forbiddenapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
accountsarray of Spanway_BillingAccountTableYesAccounts
totalintegerYesTotal
pageintegerYesPage
page_sizeintegerYesPage Size

POST /billing/account/suspend​

Suspend a billing account

Block the billed team, organization or end user and mark the account suspended.

Every request from that scope is refused until /billing/account/reinstate is called. Open invoices stay open. An account that is already suspended is a 400. Proxy admins only.

Docs

Request body (application/json, schema BillingAccountRef):

FieldTypeRequiredDescription
account_idstringYesAccount Id

Example request:

curl -X POST "http://localhost:4000/billing/account/suspend" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_BillingAccountTable
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
account_idstringYesAccount Id
scope_typeenum: "team", "organization", "end_user"YesScope Type
scope_idstringYesScope Id
display_namestringYesDisplay Name
billing_emailstring or nullNoBilling Email
currencystringYesCurrency
markup_percentnumberYesMarkup Percent
tax_percentnumberYesTax Percent
statusenum: "active", "past_due", "suspended"YesStatus
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_customer_idstring or nullNoStripe Customer Id
grace_period_daysintegerYesGrace Period Days
auto_suspendbooleanYesAuto Suspend
metadataobjectYesMetadata
created_bystringYesCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /billing/account/reinstate​

Reinstate a billing account

Unblock the billed scope and mark the account active, whatever invoices remain open.

This is the only way back from suspended, a payment alone never reinstates a suspended account. An account that is already active is a 400. Proxy admins only.

Docs

Request body (application/json, schema BillingAccountRef):

FieldTypeRequiredDescription
account_idstringYesAccount Id

Example request:

curl -X POST "http://localhost:4000/billing/account/reinstate" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_BillingAccountTable
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
account_idstringYesAccount Id
scope_typeenum: "team", "organization", "end_user"YesScope Type
scope_idstringYesScope Id
display_namestringYesDisplay Name
billing_emailstring or nullNoBilling Email
currencystringYesCurrency
markup_percentnumberYesMarkup Percent
tax_percentnumberYesTax Percent
statusenum: "active", "past_due", "suspended"YesStatus
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_customer_idstring or nullNoStripe Customer Id
grace_period_daysintegerYesGrace Period Days
auto_suspendbooleanYesAuto Suspend
metadataobjectYesMetadata
created_bystringYesCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

GET /billing/usage​

Preview what an invoice would contain

Show the line items and totals an invoice for the period would have, without writing anything.

The period runs from period_start (billed) to period_end (the first day not billed), so a calendar month is 2026-09-01 to 2026-10-01. Proxy admins and admin viewers only.

Docs

Parameters:

NameInTypeRequiredDescription
account_idquerystringYes
period_startquerystringYes
period_endquerystringYes

Example request:

curl -X GET "http://localhost:4000/billing/usage?account_id=account_id-123&period_start=string&period_end=string" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json UsagePreview
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Unprocessable Contentapplication/json ErrorDetail
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
account_idstringYesAccount Id
period_startstringYesPeriod Start
period_endstringYesPeriod End
currencystringYesCurrency
line_itemsarray of InvoiceLineItemYesLine Items
subtotalnumberYesSubtotal
markup_amountnumberYesMarkup Amount
tax_amountnumberYesTax Amount
totalnumberYesTotal

POST /billing/invoice/generate​

Generate a draft invoice

Build a draft invoice for one account from its daily spend in the period. Nothing is sent until it is issued.

A non-void invoice of the account that already covers any day of the period is a 409. Proxy admins only. The new draft is written to the audit log.

Docs

Request body (application/json, schema GenerateInvoiceRequest):

FieldTypeRequiredDescription
period_startstringYesPeriod Start
period_endstringYesPeriod End
account_idstringYesAccount Id

Example request:

curl -X POST "http://localhost:4000/billing/invoice/generate" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f",
"period_start": "2026-09-01",
"period_end": "2026-10-01"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_InvoiceTable
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
409Conflictapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id
account_idstringYesAccount Id
invoice_numberstringYesInvoice Number
period_startstringYesPeriod Start
period_endstringYesPeriod End
statusenum: "draft", "open", "paid", "void", "uncollectible"YesStatus
currencystringYesCurrency
subtotalnumberYesSubtotal
markup_amountnumberYesMarkup Amount
tax_amountnumberYesTax Amount
totalnumberYesTotal
line_itemsarray of InvoiceLineItemYesLine Items
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_invoice_idstring or nullNoStripe Invoice Id
hosted_invoice_urlstring or nullNoHosted Invoice Url
issued_atstring or nullNoIssued At
due_atstring or nullNoDue At
paid_atstring or nullNoPaid At
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /billing/invoice/generate_all​

Generate draft invoices for every account

Do what the monthly job does, for any period: a draft for every active account with usage that is not yet invoiced for it.

Accounts without usage, or with an invoice already covering the period, are listed in skipped_account_ids. Proxy admins only.

Docs

Request body (application/json, schema PeriodRequest):

FieldTypeRequiredDescription
period_startstringYesPeriod Start
period_endstringYesPeriod End

Example request:

curl -X POST "http://localhost:4000/billing/invoice/generate_all" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"period_start": "2026-09-01",
"period_end": "2026-10-01"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json GenerateAllResponse
403Forbiddenapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
period_startstringYesPeriod Start
period_endstringYesPeriod End
generatedarray of Spanway_InvoiceTableYesGenerated
skipped_account_idsarray of stringYesSkipped Account Ids

POST /billing/invoice/issue​

Issue a draft invoice

Move a draft to open, due after the account's grace period, and for a Stripe account create and finalize the Stripe invoice so Stripe collects payment.

The Stripe customer is created first when the account has none. An invoice that is not a draft is a 400 and a Stripe failure is a 502. Proxy admins only.

Docs

Request body (application/json, schema InvoiceRef):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id

Example request:

curl -X POST "http://localhost:4000/billing/invoice/issue" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"invoice_id": "9c0d1e2f-3a4b-4c5d-8e9f-a0b1c2d3e4f5"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_InvoiceTable
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail
502Bad Gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id
account_idstringYesAccount Id
invoice_numberstringYesInvoice Number
period_startstringYesPeriod Start
period_endstringYesPeriod End
statusenum: "draft", "open", "paid", "void", "uncollectible"YesStatus
currencystringYesCurrency
subtotalnumberYesSubtotal
markup_amountnumberYesMarkup Amount
tax_amountnumberYesTax Amount
totalnumberYesTotal
line_itemsarray of InvoiceLineItemYesLine Items
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_invoice_idstring or nullNoStripe Invoice Id
hosted_invoice_urlstring or nullNoHosted Invoice Url
issued_atstring or nullNoIssued At
due_atstring or nullNoDue At
paid_atstring or nullNoPaid At
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /billing/invoice/mark_paid​

Mark an invoice paid

Record a payment taken outside Stripe and settle the invoice.

A past_due account returns to active once none of its other open invoices is overdue. A draft, void or already paid invoice is a 400. Proxy admins only.

Docs

Request body (application/json, schema InvoiceRef):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id

Example request:

curl -X POST "http://localhost:4000/billing/invoice/mark_paid" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"invoice_id": "9c0d1e2f-3a4b-4c5d-8e9f-a0b1c2d3e4f5"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_InvoiceTable
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id
account_idstringYesAccount Id
invoice_numberstringYesInvoice Number
period_startstringYesPeriod Start
period_endstringYesPeriod End
statusenum: "draft", "open", "paid", "void", "uncollectible"YesStatus
currencystringYesCurrency
subtotalnumberYesSubtotal
markup_amountnumberYesMarkup Amount
tax_amountnumberYesTax Amount
totalnumberYesTotal
line_itemsarray of InvoiceLineItemYesLine Items
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_invoice_idstring or nullNoStripe Invoice Id
hosted_invoice_urlstring or nullNoHosted Invoice Url
issued_atstring or nullNoIssued At
due_atstring or nullNoDue At
paid_atstring or nullNoPaid At
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

POST /billing/invoice/void​

Void an unpaid invoice

Cancel an unpaid invoice, in Stripe too when it was issued there, and free its period to be invoiced again.

A paid invoice is a 400 and a Stripe failure is a 502. Proxy admins only.

Docs

Request body (application/json, schema InvoiceRef):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id

Example request:

curl -X POST "http://localhost:4000/billing/invoice/void" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"invoice_id": "9c0d1e2f-3a4b-4c5d-8e9f-a0b1c2d3e4f5"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_InvoiceTable
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail
502Bad Gatewayapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id
account_idstringYesAccount Id
invoice_numberstringYesInvoice Number
period_startstringYesPeriod Start
period_endstringYesPeriod End
statusenum: "draft", "open", "paid", "void", "uncollectible"YesStatus
currencystringYesCurrency
subtotalnumberYesSubtotal
markup_amountnumberYesMarkup Amount
tax_amountnumberYesTax Amount
totalnumberYesTotal
line_itemsarray of InvoiceLineItemYesLine Items
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_invoice_idstring or nullNoStripe Invoice Id
hosted_invoice_urlstring or nullNoHosted Invoice Url
issued_atstring or nullNoIssued At
due_atstring or nullNoDue At
paid_atstring or nullNoPaid At
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

GET /billing/invoice/info​

Show one invoice

Return the invoice with invoice_id, line items included, or a 404 when there is none. Proxy admins and admin viewers only. Docs

Parameters:

NameInTypeRequiredDescription
invoice_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/billing/invoice/info?invoice_id=invoice_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json Spanway_InvoiceTable
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
invoice_idstringYesInvoice Id
account_idstringYesAccount Id
invoice_numberstringYesInvoice Number
period_startstringYesPeriod Start
period_endstringYesPeriod End
statusenum: "draft", "open", "paid", "void", "uncollectible"YesStatus
currencystringYesCurrency
subtotalnumberYesSubtotal
markup_amountnumberYesMarkup Amount
tax_amountnumberYesTax Amount
totalnumberYesTotal
line_itemsarray of InvoiceLineItemYesLine Items
payment_providerenum: "manual", "stripe"YesPayment Provider
stripe_invoice_idstring or nullNoStripe Invoice Id
hosted_invoice_urlstring or nullNoHosted Invoice Url
issued_atstring or nullNoIssued At
due_atstring or nullNoDue At
paid_atstring or nullNoPaid At
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At

GET /billing/invoice/list​

List invoices

Page through the invoices, newest first, optionally only one account_id or one status (draft, open, paid, void, uncollectible). page_size goes up to 100. Proxy admins and admin viewers only. Docs

Parameters:

NameInTypeRequiredDescription
account_idquerystring or nullNo
statusqueryenum: "draft", "open", "paid", "void", "uncollectible" or nullNo
pagequeryintegerNo
page_sizequeryintegerNo

Example request:

curl -X GET "http://localhost:4000/billing/invoice/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json InvoiceListResponse
403Forbiddenapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
invoicesarray of Spanway_InvoiceTableYesInvoices
totalintegerYesTotal
pageintegerYesPage
page_sizeintegerYesPage Size

GET /billing/invoice/export​

Download an invoice as CSV

Download the line items of an invoice as a CSV file named after the invoice number.

Proxy admins and admin viewers only, and an unknown invoice_id is a 404.

Docs

Parameters:

NameInTypeRequiredDescription
invoice_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/billing/invoice/export?invoice_id=invoice_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The invoice line items as CSVtext/csv string
403Forbiddenapplication/json ErrorDetail
404Not Foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500Internal Server Errorapplication/json ErrorDetail

POST /billing/webhook/stripe​

Receive Stripe webhook events

Stripe calls this without a Spanway key. The signature over the raw body is the only authentication, so an unsigned or badly signed request is a 400. Invoice events need the billing feature and Cloud checkout, subscription, top-up and customer events need the cloud feature. A signed event whose feature is not licensed is a 403 so Stripe retries it once the license allows it. Events for invoices Stripe did not learn from us are acknowledged and ignored so Stripe stops retrying them.

Parameters:

NameInTypeRequiredDescription
stripe-signatureheaderstring or nullNo

Request body (application/json, object):

FieldTypeRequiredDescription
idstringYesId
typestringYesType
dataobjectYesData

Example request:

curl -X POST "http://localhost:4000/billing/webhook/stripe" \
-H "Content-Type: application/json" \
-d '{
"id": "evt_1",
"type": "checkout.session.completed",
"data": {
"object": {
"id": "cs_1",
"customer": "cus_1"
}
}
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json WebhookResponse
400Bad Requestapplication/json ErrorDetail
403Forbiddenapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
receivedtrueNoReceived
handledbooleanYesHandled
eventstring or nullNoEvent