Skip to main content

Generate an invoice using SOAP API

Zuora

Generate an invoice using SOAP API

This article walks you through the process of generating an invoice with the SOAP API. This process uses the generate() call and the Invoice object. Generating a new invoice with the SOAP API is similar to the process of creating an ad hoc invoice in the Zuora UI. This article gives you some examples on how to generate a new invoice and how to regenerate a PDF version of the invoice. 

How to Use this Walkthrough

This walkthrough uses a fictitious company as a case study. Substitute your own values when you use these steps and examples.

Start all of your processes by creating your SOAP envelope, and put your code inside. Don't forget to pass your session ID and URL with your SOAP calls.

This walkthrough assumes that you are using the latest version of the WSDL. If you are using an older version of the WSDL, some of the fields, calls, and objects are not available. For example, if your WSDL version is older than version 40.0, then you cannot regenerate an invoice PDF.

Generate a new invoice

Lucia from Widget Wiki needs to generate an invoice for a specific customer whose account number is 8a8ae4b122561fc00122562fbc3d0002. The invoice needs to include all charges through July 31, 2016. She wants to look at the invoice before posting it, so the invoice needs to be in Draft status upon generation. 

Lucia sets the following fields and values:

  • AccountId: 8a8ae4b122561fc00122562fbc3d0002
  • IncludesOneTime: true
  • IncludesRecurring: true
  • IncludesUsage: true
  • InvoiceDate: 2016-08-01
  • TargetDate: 2016-07-31

If Lucia wants to post it now, she can use an update() call.

Example Request

<ns1:generate>
  <ns1:zObjects xsi:type="ns2:Invoice">
    <ns2:AccountId>4028e485225d1d5f0122662fd6b249c8</ns2:AccountId>
    <ns2:IncludesOneTime>true</ns2:IncludesOneTime>
    <ns2:IncludesRecurring>true</ns2:IncludesRecurring>
    <ns2:IncludesUsage>true</ns2:IncludesUsage>
    <ns2:InvoiceDate>2016-08-01</ns2:InvoiceDate>
    <ns2:TargetDate>2016-07-31</ns2:TargetDate>
  </ns1:zObjects>
</ns1:generate>

The response returns an invoice to Lucia in Draft status and indicates Success: true.

Regenerate a PDF Version of the invoice

Lucia made some changes that affect an invoice she generated. She can use the update() call with the RegenerateInvoicePDF field to regenerate a PDF version of this invoice. The value for this field can be set to true or false. Note that when you set the RegenerateInvoicePDF field to true, you cannot update any other fields in the same update() call. Otherwise, you will receive the following INVALID_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.

Lucia sets the following fields and values:

  • Id: 8a8ae4b122561fc00122562fbc3d0002
  • RegenerateInvoicePDF: true  

 Example Request

<ns1:update xmlns:ns1="http://api.zuora.com/">
    <ns1:zObjects xsi:type="ns2:Invoice" xmlns:ns2="http://object.api.zuora.com/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <ns2:Id>8a8ae4b122561fc00122562fbc3d0002</ns2:Id>
        <ns2:RegenerateInvoicePDF>true</ns2:RegenerateInvoicePDF>
    </ns1:zObjects>
</ns1:update>

The response returns a new invoice PDF to Lucia in Draft status and indicates Success: true.