Question

How to return a PDF file in Zapier developer platform

  • 6 December 2021
  • 3 replies
  • 373 views

  • Anonymous
  • 0 replies

I have a custom app setup in Zapier developer and i’m connecting to the Xero API oauth2.  Everything connects fine.  I then query the Xero API using the following url to retrieve a quote in the Xero system. 

https://api.xero.com/api.xro/2.0/Quotes/{QuoteID}

This also works fine and returns the quote information as expected when headers are set to “application/json”.

However, if I change the headers to “application/pdf” in accordance with the Xero API guidelines, it returns the below error:

 

 

It doesn’t seem to like the pdf response.  Is there limitation which means we can’t retrieve a PDF in this way?


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 7
Badge +12

Hi @BradE - If you’re still having issues with this action, try the following:

const customHttpOptions = {
url: "https://api.xero.com/api.xro/2.0/Quotes/" + bundle.inputData.QuoteID,
headers: {
Accept: "application/pdf",
Authorization: `Bearer ${bundle.authData.access_token}`,
"Xero-tenant-id": bundle.inputData.TenantID,
},
raw: true,
};

const fileRequest = await z.request(customHttpOptions);
const buffer = await fileRequest.buffer();
const url = await z.stashFile(buffer);
return { url };

 

I’ve managed to get a bit further with this and it’s returning a PDF file.  But the PDF file is blank.  Here’s my code in Zapier Platorm..

const customHttpOptions = {
url: 'https://api.xero.com/api.xro/2.0/Quotes/' + bundle.inputData.QuoteID,
headers: {
'Accept': 'application/pdf',
'Authorization': `Bearer ${bundle.authData.access_token}`,
'Xero-tenant-id': bundle.inputData.TenantID
},
};

const fileRequest = await z.request(customHttpOptions);
const url = await z.stashFile(fileRequest); // knownLength and filename will be sniffed from the request. contentType will be binary/octet-stream
return {url};

Any ideas whats not quite right?

I have tried setting the Accept header to “application/json” but it just saves the file as a JSON file..

Still struggling with this guys, any ideas?