xero-node icon indicating copy to clipboard operation
xero-node copied to clipboard

getInvoiceAsPdf endpoint does not set PDF headers as default

Open samueldjones24 opened this issue 3 years ago • 5 comments

  • Version 4.7.6

Describe the bug Similar problem to one reported in Issue #422 whereby the invoice is returned as a Buffer in JSON format rather than a PDF.

Expected behavior We expected an endpoint entitled getInvoiceAsPdf to return a PDF as default. The workaround is xero.accountingApi.getInvoiceAsPdf(activeTenantId, invoiceId, {headers: {Accept: 'application/pdf'}})

samueldjones24 avatar Sep 01 '20 09:09 samueldjones24

Hey @samueldjones24 - agreed this would be ideal to auto-detect.

We've got full examples in the sample app but you make a good point. Added examples for both getting files as PDF, and POSTIng attachments to the core SDK readme!

SerKnight avatar Sep 04 '20 17:09 SerKnight

I think getInvoiceAsPdf method should do this automatically behind the scenes for you without passing any additional option parameters. The name of the method suggests you'll receive a PDF back.

ersel avatar Sep 04 '20 19:09 ersel

Agree with the latter :) great to have the option to add headers as well, but it is also missing from the documentation, that'd help to imagine the workaround

kapekost avatar Jan 21 '21 20:01 kapekost

Agree with the latter :) great to have the option to add headers as well, but it is also missing from the documentation, that'd help to imagine the workaround

Yes - improvement will be in an upcoming release but a documentation addition in this readme would be a good place to start as we have it shown in the sample app https://github.com/XeroAPI/xero-node-oauth2-app/blob/master/src/app.ts#L1191

SerKnight avatar Jan 21 '21 22:01 SerKnight

This is still the case in 2024. I would put some sort of flag in the documentation while this is ongoing because calling the function as it is now actually returns a json object with the invoice data (so it doesn't throw an error).

TudorAB avatar Mar 07 '24 08:03 TudorAB