Skip to content
Discussion options

You must be logged in to vote

pdf: true isnt a valid got option. to download a PDF (or any binary file), you need to use buffer response type:

const pdfBuffer = await got.post(url, {
  headers: header,
  json: bodysuit
}).buffer();

fs.writeFileSync('file.pdf', pdfBuffer);

the JSON parsing error happens because by default got tries to parse responses as JSON when you use .json() on it, but PDFs are binary data. responseType: 'buffer' tells got to return the raw binary data as a Buffer instead.

also, i notice you have bodysuit - if thats a typo and you meant to send JSON data, use the json option (shown above). if its form data, use form instead.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants