API with file field in form-data

I have an API that I need to use to add .pdf attachments to invoices. It takes a form-data body, and I'm trying to use a Workflow to accomplish this.

Quick background on the whole process:

  1. PDFs are stored in another system, so I call the initial API to get a download link.

  2. Call a GET on the download link to return a base64 result

  3. convert the base64 string to a file object (I think this is working, but not sure)
    image

  4. call the PATCH API to load the attachment to the invoice - this is not working

I think the problem is how to reference the output of my code block in the query parameters... but I'm not sure what else to put in there. Do I need to return a fileReader or something? I'm somewhat unfamiliar with working with files in Javascript...

Thanks,

Hey @pyee! So it looks like {{ code.data }} isn't working as we expect? Would you mind sharing what code.data is returning?

Thanks @victoria , here's where I started...

I get a temporary link from one system, and when I run a GET command on that link, I get a base64Binary value back. Initially I tried to pass that directly into the multipart/form-data request in a different system to add the file as an attachment to an invoice, but it gives me a vague 500 error. I'm assuming it wants a different type of format than base64?

That code block was my attempt to create the file inside the workflow and pass that to the API, but got that error.

In the preview window, it just looks like an empty object, but that's sort of what I would expect when the object is a large file... I did console.log out the size and the type, so it would appear that it's returning a pdf file...

But then if I put that into the API, I get that original message I posted about:

I'm also reaching out to the API support for this system, but the're slow to get back to me, so I was hoping someone here might have some experience with things like this and how they solved it in Retool. Thanks!

Sorry for the delay here. It’s been a bit busy on our end, so trying our best to stay on top of things!

Any documentation you have from the API about what it expects would be great.

I’m curious if something like this would be helpful for your setup:

http://community.retool.com/t/uploading-files-fails-with-the-new-components/7106/5