Happy Business Starts Here

Honor Student

How to get invoice PDF and display to user

Short question: Using the get_invoices endpoint, when I try to access the URL from the InvoiceFiles.pdfFileUrl response, it pops up a api.zuora login form. I need my customers to be able to access these PDFs.

enter image description here

If I enter my Zuora creds, it will display the invoice, but of course my customers don't have Zuora creds.

 

Is there some sort of setting to allow customers to view PDFs from the URL?

 

Long Question:

The get_invoices endpoint returns 2 items of interest.

body is the REST URL of the invoice PDF file.

and

InvoiceFiles returns

  1. id ID of the invoice PDF file. This is the ID for the file object and different from the file handle id in the pdfFileUrl field. To open a file, you need to use the file handle ID.
  2. versionNumber Version number of the invoice PDF file
  3. pdfFileUrl REST URL for the invoice PDF file. Click the URL to open the invoice PDF file.

Is there a difference between what is returned by body and InvoiceFiles.pdfFileUrl, and how do I use them correctly?

 

The pdfFileUrl can return multiple files. Each time the invoice is update (the customer pays etc) it generates another file. The most recent is the at index 0.

 

However trying to access any of the URLs, I get a api.zuora login form. If I enter my Zuora creds, it will display the invoice, but of course my customers don't have Zuora creds.

 

The example on the endpoint page - https://knowledgecenter.zuora.com/DC_Developers/C_REST_API/B_REST_API_reference/Transactions/GET_inv... has both the body and the pdfFiles return as blank so that doesn't help much.

 

Searched through the community for a while, couldn't find anything remotely similar to my issue. Thanks!

5 REPLIES 5
Support SME

Re: How to get invoice PDF and display to user

As my understanding, the invoice PDF could only be sent to end user through email.

(It would be very unsafe if any end user could acccess to any PDF without be asking for credential.)

So if you'd like to get the invoice PDF through URL, you will have to provide the credential

 

In the response of Get Invoices through REST API, we could use the id in "body" to get the latest invoice PDF

Screen Shot 2017-03-21 at 09.45.58.png

or we could use the ids in "pdfFileUrl" to get the history invoice PDF

Screen Shot 2017-03-21 at 09.45.50.png

 

And when getting the files, we could either use REST request as below

https://rest.apisandbox.zuora.com/v1/files/2c92c08a58199cf6015822c9b036160d

(accessing above URL in browser would also work)

 

or just with the URL as below

https://apisandbox.zuora.com/apps/api/file/2c92c08a58199cf6015822c9b036160d

 

 

But either way, creadential to connect to zuora tenant would be required.






If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Honor Student

Re: How to get invoice PDF and display to user

Hi Yolanda, thanks for the reply!

We are able to get the PDF URL as you showed in your answer. The problem is displaying that to the user. 

 

Only the users with authority to view the PDF will be able to see the URL. But we can't put it behind a Zuora login, as our customers do not have a Zuora login. 

 

What can we do to show the PDF to our users? 

Highlighted
Honor Student

Re: How to get invoice PDF and display to user

Finally found the correct way to do this. 

 

First step was to call "/transactions/invoices/accounts/{accountId}" to get a list of invoices.


Second, pick the invoice out of the list that matched the invoice number we were trying to view.


On that object is a list called "invoiceFiles" - if it was non-empty, grab the first item.


Use the "pdfFileUrl" property on that item as the URL to fetch the PDF from, but in the GET request, include headers "apiAccessKeyId" and "apiSecretAccessKey" with the values set to our applicable api key. This eliminates the auth problem, but also makes it so you have to do this on your backend to avoid exposing your apiAccessKeyId and Secret. 


Assuming the request for the PDF coming into us was authenticated, we'd do a pipe command on the response coming back from Zuora onto the outgoing response we are currently handling on our server: zuoraResponse.pipe(ourOutgoingResponseObj)

 

This will display the PDF directly to the user. 

Community Manager

Re: How to get invoice PDF and display to user

Thanks for sharing the solution@joshdance! It'll definitely be helpful to other users who might run into the same issue.


Lana Lee | Senior Community Manager and Strategist
"A little consideration, a little thought for others, makes all the difference." —A. A. Milne
Savvy Scholar vuh
Savvy Scholar

Re: How to get invoice PDF and display to user

Has the gETTransactionInvoice API changed since the OP posted? Now, it returns invoice objects whose field invoiceFiles is just a string; not an object. Here's an example:

accountId:"2c92c0fb6a07403b016d0972cd4c29c2"
accountName:"Test Cloud Services"
accountNumber:"98396194"
amount:26.76
balance:26.76
body:null
createdBy:"2c92c0f8692450a10169259ef33061da"
creditBalanceAdjustmentAmount:0
dueDate:"2019-05-11"
id:"2c92c0946a072fa4016a0d3fc94612ca"
invoiceDate:"2019-05-11"
invoiceFiles:"/v1/invoices/2c92c0946a072fa4016a0d3fc94612ca/files"
invoiceItems:"/v1/invoices/2c92c0946a072fa4016a0d3fc94612ca/items"

 

I don't think we can use the URL that is in invoiceFiles.

 

So, to get the PDF files, I'd have to:

  • Call gETInvoiceFiles. This returns something like:

id:"66674858177d40be91905de87b84c38b"
pdfFileUrl:"/v1/files/2c92c08c6a073477016a0d3fcca4037a"
versionNumber:1555000445985

 

  • Then call gETFiles on each of the fileIds (without the /v1/files/ portion).

Can someone at Zuora confirm that this is the new way of getting PDF files?