Page 1 of 2

endpoint to get invoice pdfs

PostPosted: Wed Jul 13, 2022 2:28 pm
by aaron_bonntech
Hi,

Just wondering whats the endpoint to hit to get an invoice PDF from an InvoiceID?

I tried
/SalesOrders/{$InvoiceID}/Documents
/Debtors/{$DebtorID}/Documents

And both of them returned empty arrays. I know the document is there because my client can see the documents in the JIWA program.

Also this is a sandbox environment im querying against if that helps.

Re: endpoint to get invoice pdfs  Topic is solved

PostPosted: Wed Jul 13, 2022 2:48 pm
by Mike.Sheen
aaron_bonntech wrote:Hi,

Just wondering whats the endpoint to hit to get an invoice PDF from an InvoiceID?

I tried
/SalesOrders/{$InvoiceID}/Documents
/Debtors/{$DebtorID}/Documents

And both of them returned empty arrays. I know the document is there because my client can see the documents in the JIWA program.

Also this is a sandbox environment im querying against if that helps.


The/SalesOrders/{InvoiceID}/Documents and /Debtors/{DebtorID}/Documents will retrieve a binary file document attached to the sales order or debtor - that's not where you would go to get a PDF of an invoice.

What you want is to call the route to generate a report to PDF and pass the ReportID and report parameters - that route is the /Reports/{ReportID}/PDF/Download route.

You'll need to know the ReportID to use - in our demo data the invoice report has a ReportID of 8ce38d28-d320-4b82-9038-8cf2b1880ca4 - that likely will work with the sandbox you've been given, but you can get a list of reports in the system with the /Queries/SY_Report route : https://api.jiwa.com.au/Queries/SY_Repo ... e,FileName

The report parameters need to also be supplied - typically with an Invoice Report, they use the parameter Pass_SP_InvoiceHistoryID - which needs to be set to the SO_History.InvoiceHistoryID value of the snapshot of the invoice.

Here's what a complete route looks like in our demo data:

https://api.jiwa.com.au/Reports/8ce38d28-d320-4b82-9038-8cf2b1880ca4/PDF/Download?apikey=9vjoF4M5-gYVBWjoFyW9nlQieB9FhxpJkAsRJznB_Ok&ReportParameters={Name:Pass_SP_InvoiceHistoryID,Value:000000000800000000NL}
InvoicePDF_apijiwacomau.png


If you know an InvoiceID but don't know the InvoiceHistoryID, you can look at the InvoiceHistoryID's by doing a GET on /SalesOrders/{InvoiceID} and inspecting the result : https://api.jiwa.com.au/SalesOrders/000 ... ormat=json

From that you can pick out the Histories field, which is a list of History each with an InvoiceHistoryID.

Re: endpoint to get invoice pdfs

PostPosted: Wed Jul 13, 2022 4:47 pm
by SBarnes

Re: endpoint to get invoice pdfs

PostPosted: Fri Aug 26, 2022 5:33 pm
by aaron_bonntech
Hi Mike,

Sorry for re-opening this thread. When i call the endpoint, i get an error:

["ResponseStatus"]=>
array(4) {
["ErrorCode"]=>
string(12) "COMException"
["Message"]=>
string(130) "Error in File MNT30000 - Invoice 25876_12052_{C6EFC67B-EAFC-421A-B38B-F2C95B530446}.rpt:
Page header or footer longer than a page."
["StackTrace"]=>
string(539) "[ReportsPDFGETRequest: 8/19/2022 12:06:59 AM]:
[REQUEST: {ReportID:8ce38d28-d320-4b82-9038-8cf2b1880ca4}]
System.Runtime.InteropServices.COMException (0x80000237): Error in File MNT30000 - Invoice 25876_12052_{C6EFC67B-EAFC-421A-B38B-F2C95B530446}.rpt:
Page header or footer longer than a page.
at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)"
["Errors"]=>
array(0) {
}
}

Im hitting /Reports/8ce38d28-d320-4b82-9038-8cf2b1880ca4/PDF/Download with parameter: "ReportParameters" => ["Pass_SP_InvoiceHistoryID" => "99608b0907d949519af9"]

Are there more parameters i need to pass?

Re: endpoint to get invoice pdfs

PostPosted: Fri Aug 26, 2022 5:35 pm
by Scott.Pearce
Can you run the report OK in the desktop Jiwa client for that same invoice?

If you can, then can you export to PDF without error in the desktop Jiwa client?

Re: endpoint to get invoice pdfs

PostPosted: Fri Aug 26, 2022 5:39 pm
by Dean_Bonntech
Thanks Scott

The error "Page header or footer longer than a page" implies that the issue is related to pagination - not with the data.
Do we need pass any parameters to the function to specify the page size for the function? Is there a default?

Re: endpoint to get invoice pdfs

PostPosted: Fri Aug 26, 2022 5:39 pm
by Mike.Sheen
aaron_bonntech wrote:Hi Mike,

Sorry for re-opening this thread. When i call the endpoint, i get an error:

["ResponseStatus"]=>
array(4) {
["ErrorCode"]=>
string(12) "COMException"
["Message"]=>
string(130) "Error in File MNT30000 - Invoice 25876_12052_{C6EFC67B-EAFC-421A-B38B-F2C95B530446}.rpt:
Page header or footer longer than a page."
["StackTrace"]=>
string(539) "[ReportsPDFGETRequest: 8/19/2022 12:06:59 AM]:
[REQUEST: {ReportID:8ce38d28-d320-4b82-9038-8cf2b1880ca4}]
System.Runtime.InteropServices.COMException (0x80000237): Error in File MNT30000 - Invoice 25876_12052_{C6EFC67B-EAFC-421A-B38B-F2C95B530446}.rpt:
Page header or footer longer than a page.
at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)"
["Errors"]=>
array(0) {
}
}

Im hitting /Reports/8ce38d28-d320-4b82-9038-8cf2b1880ca4/PDF/Download with parameter: "ReportParameters" => ["Pass_SP_InvoiceHistoryID" => "99608b0907d949519af9"]

Are there more parameters i need to pass?


Hi aaron,

In addition to Scott's suggestions, show us the exact request you are sending - like the exact url (minus the domain name if you like) - what you said you were providing:
"ReportParameters" => ["Pass_SP_InvoiceHistoryID" => "99608b0907d949519af9"]


Is very different to the working example I provided in my earlier comment - it looks like :
ReportParameters=%7BName:Pass_SP_InvoiceHistoryID,Value:000000000800000000NL%7D


If you don't know the exact query string, use something like Fiddler to capture it on the way out.

EDIT: Or, if you have DebugMode enabled for the jiwa api, hiiting /requestlogs should show you the raw request URL's.

Re: endpoint to get invoice pdfs

PostPosted: Fri Aug 26, 2022 5:49 pm
by aaron_bonntech
Mike.Sheen wrote:
aaron_bonntech wrote:Hi Mike,

Sorry for re-opening this thread. When i call the endpoint, i get an error:

["ResponseStatus"]=>
array(4) {
["ErrorCode"]=>
string(12) "COMException"
["Message"]=>
string(130) "Error in File MNT30000 - Invoice 25876_12052_{C6EFC67B-EAFC-421A-B38B-F2C95B530446}.rpt:
Page header or footer longer than a page."
["StackTrace"]=>
string(539) "[ReportsPDFGETRequest: 8/19/2022 12:06:59 AM]:
[REQUEST: {ReportID:8ce38d28-d320-4b82-9038-8cf2b1880ca4}]
System.Runtime.InteropServices.COMException (0x80000237): Error in File MNT30000 - Invoice 25876_12052_{C6EFC67B-EAFC-421A-B38B-F2C95B530446}.rpt:
Page header or footer longer than a page.
at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)"
["Errors"]=>
array(0) {
}
}

Im hitting /Reports/8ce38d28-d320-4b82-9038-8cf2b1880ca4/PDF/Download with parameter: "ReportParameters" => ["Pass_SP_InvoiceHistoryID" => "99608b0907d949519af9"]

Are there more parameters i need to pass?


Hi aaron,

In addition to Scott's suggestions, show us the exact request you are sending - like the exact url (minus the domain name if you like) - what you said you were providing:
"ReportParameters" => ["Pass_SP_InvoiceHistoryID" => "99608b0907d949519af9"]


Is very different to the working example I provided in my earlier comment - it looks like :
ReportParameters=%7BName:Pass_SP_InvoiceHistoryID,Value:000000000800000000NL%7D


If you don't know the exact query string, use something like Fiddler to capture it on the way out.


Hi Mike and Scott, thanks for the prompt replies.

The exact url is
Code: Select all
https://japitest.cedarhospitality.com:5452/Reports/8ce38d28-d320-4b82-9038-8cf2b1880ca4/PDF/Download


Im using CURL so the request would be a GET with json string of
Code: Select all
{"query":{"ReportParameters":{"Pass_SP_InvoiceHistoryID":"99608b0907d949519af9"}}}

where 99608b0907d949519af9 is an invoice history id i got from a sales order.

Re: endpoint to get invoice pdfs

PostPosted: Fri Aug 26, 2022 5:54 pm
by Mike.Sheen
aaron_bonntech wrote:The exact url is
Code: Select all
https://japitest.cedarhospitality.com:5452/Reports/8ce38d28-d320-4b82-9038-8cf2b1880ca4/PDF/Download


Im using CURL so the request would be a GET with json string of
Code: Select all
{"query":{"ReportParameters":{"Pass_SP_InvoiceHistoryID":"99608b0907d949519af9"}}}

where 99608b0907d949519af9 is an invoice history id i got from a sales order.


Your query parameters do not match what we expect, so the generation of the report is deserialising the parameters as though no Pass_SP_InvoiceHistoryID was provided at all, so it's generating a PDF for all sales orders and that's causing your error.

You need to fix your parameters to match what we expect exactly. Refer to the working URL example I provided earlier.

Re: endpoint to get invoice pdfs

PostPosted: Fri Aug 26, 2022 5:57 pm
by Mike.Sheen
FYI - we've recognised the difficulty in providing the report parameters in a query string, so we've got an improvement in the works to support a POST operation which would allow nice request bodies - DEV-7998.