Перейти до вмісту

Generate invoices

Цей контент ще не доступний вашою мовою.

generateInvoice renders an invoice of an account for a period you choose, the same as Generate Invoice in the account’s Billing menu. validateInvoiceTemplate fills an invoice template with sample data, so you can check a template, or show a preview of it, before you use it. Both return the PDF as a base64 string.

Both methods support trusted mode with i_customer.

Renders an invoice of an account with the account’s invoice template.

Name Type Required Description
i_account int yes ID of the account
period_begin string yes Start of the period, in UTC, in the format HH:MM:SS.000 GMT Ddd Mmm DD YYYY, for example 00:00:00.000 GMT Thu Jan 01 2026
period_end string yes End of the period, in the same format
i_billing_plan int no Service plan to bill the period with. Default: the account’s current service plan
Name Type Description
result string OK
pdf string The invoice as a PDF file, base64-encoded
request
import base64
res = call("generateInvoice", {
"i_account": 3092,
"period_begin": "00:00:00.000 GMT Thu Jan 01 2026",
"period_end": "00:00:00.000 GMT Sun Feb 01 2026",
})
with open("invoice-3092-2026-01.pdf", "wb") as f:
f.write(base64.b64decode(res["pdf"]))
response
{"result": "OK", "pdf": "JVBERi0xLjQK…"}

Fills a template with sample data and checks that it renders. With return_pdf it also returns the rendered PDF as a preview.

Name Type Required Description
template string yes The HTML of the template, base64-encoded
template_css string no The CSS of the template, base64-encoded
converter_options string no Extra options for the PDF converter. The panel sends an empty string
return_pdf boolean no True returns the rendered preview in pdf. Default: False
Name Type Description
result string OK when the template renders
pdf string The preview as a PDF file, base64-encoded; only with return_pdf

A template that cannot be rendered returns a fault. The panel shows it as Wrong Invoice Template parameters. when you save a template.

request
import base64
def b64(path):
with open(path, "rb") as f:
return base64.b64encode(f.read()).decode()
call("validateInvoiceTemplate", {
"template": b64("invoice.html"),
"template_css": b64("invoice.css"),
"converter_options": "",
"return_pdf": True,
})
response
{"result": "OK", "pdf": "JVBERi0xLjQK…"}