How to export a PDF from an API response object?

  • Goal: I'm attempting to export a PDF given some API response data

  • Steps:

  • used a button to run a GET request to retrieve PDF data

  • onSuccess, use utils.downloadFile() on the given PDF data

  • Details: When I do the steps above, it exports the file as JSON since the parameter I'm feeding utils.downloadFile() is an object. The schema of the response data is:

{
  "name": "file-name",
  "type": "application/pdf",
  "sizeBytes": 1234,
  "base64Data": "someEncodedStringData"
}

The only way I'm able to accomplish this is by storing the response object in a PDF component and manually downloading the PDF which is not the goal.

I was able to accomplish this by doing

utils.downloadfile({ base64Binary: data.base64Data }, 'fileName', 'pdf');

The docs aren't very clear on having to feed the method a specific type of object so it's probably worth updating.

1 Like

Thanks for sharing this feedback. I agree, it could be more clear. I'll share this idea with our Docs team.