Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
PDF file encoding when downloading from API

I have the following code which downloads a PDF file from Xero API into Zapier. The code works fine, but the PDF file is always blank white page. I have inspected the contents of the PDF file returned (in a text file) and the top characters are returned as diamond shaped question marks (special characters). See screenshot below.

I have also compared with a working PDF file and the diamond shaped question marks are displayed as È on the good file.

Here's my code:

const pdfURL = {
  url: 'https://api.xero.com/api.xro/2.0/Quotes/' + bundle.inputData.QuoteID,
  method: 'GET',
  headers: {
    'Accept': 'application/pdf',
    'Authorization': `Bearer ${bundle.authData.access_token}`,
    'Xero-tenant-id': bundle.inputData.TenantID,
    'Content-type': 'application/pdf'
  }
};
const fileRequest = await z.request(pdfURL);
const url = await z.stashFile(fileRequest, fileRequest.length, 'Quote #123' + '.pdf', 'application/pdf;'); // knownLength and filename will be sniffed from the request. contentType will be binary/octet-stream
return {url};

Here's a screenshot of the contents in the corrupt PDF file:

enter image description here

Does anyone know what the problem could be?

I have tried setting the charset to 'utf-8' to no avail.

Any help would be greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I just had the exactly same problem here.

To solve it, just set the parameter raw:true in the z.request(), it will avoid parsing and messing up with the encoding.

Like that:

const pdfURL = {
  ...
  raw: true
};

Your file will then render properly.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!