Knowledge Center

Knowledge Center > API > SOAP API > SOAP API Object Reference > Invoice > Generate an Invoice

Generate an Invoice

This article explains how to generate an invoice, update the status of an invoice, and generate an invoice PDF through SOAP API calls. Includes sample code.

Generate a New Invoice

First, generate a new Invoice. Set the following fields:

  1. Specify the AccountId to indicate which customer this invoice is for.
  2. Optionally, set filtering parameters IncludesOneTime, IncludesRecurring, and IncludesUsage to either true (default) or false.
  3. Set the InvoiceDate. This date will be shown on the invoice as the Invoice Date and, with the Payment Term, will impact the Invoice Due Date.
  4. Set the TargetDate. This date indicates what charges to include on the invoice. All charges will be included that mature on or before this date.

By default, the Status of the invoice is set to Draft.

SOAP Example

  <ns1:zObjects xsi:type="ns2:Invoice">

Update the Status of the Invoice

After generating the invoice. update the status of the new invoice. Set the following fields:

  1. Specify the invoice ID field.
  2. Set Status to Posted. (The other allowable status value is Canceled.)

Use the update() call to update the new invoice.

SOAP Example

 <ns1:zObjects xsi:type="ns2:Invoice">

Generate an Invoice PDF

Create a query object for an invoice, including the Body field.

For example:

SELECT Id, AccountId, Amount, Balance, DueDate, InvoiceDate, InvoiceNumber, Status, TargetDate, Body FROM Invoice where Id='XXYYZZ'

where XXYYZZ  is the ID of the invoice you want generate as a PDF. The Body field returned is encoded in Base64 that you must decode.

The resulting data is the PDF file of the invoice.

​Regenerate an Invoice PDF

You can regenerate the Invoice PDF after invoice generation. For example, you generate an invoice and a PDF of that invoice. Then you update a custom field value or change the invoice template. Use the update() call to regenerate the invoice's PDF file to reflect your changes.

The Invoice object has a field, RegenerateInvoicePDF, that you use with the update() call to do the regeneration. The values for the field are true and false. When the value is true, then the update() call triggers an asynchronous operation to regenerate the invoice PDF file.

You cannot use the RegenerateInvoicePDF field with other invoice fields in the update() call to update the invoice, or you receive anINVALID_VALUE error,  "When field RegenerateInvoicePDF is set to true to regenerate the invoice PDF file, changes on other fields of the invoice are not allowed."

The RegenerateInvoicePDF field is introduced in API version 40. If you use the field in earlier versions, then the field is ignored.

SOAP Example

<soapenv:Envelope xmlns:soapenv="">
      <ns1:SessionHeader soapenv:mustUnderstand="0" xmlns:ns1="">
      <ns1:update xmlns:ns1="">
         <ns1:zObjects xsi:type="ns2:Invoice" xmlns:ns2=""

Example response:

<soapenv:Envelope xmlns:soapenv="">
      <ns1:updateResponse xmlns:ns1="">
Last modified
22:54, 5 Jul 2015



(not set)