API returning base64 rather than json even though header has Content-Type: application/json, help?

This API has been running for almost a year and just started a chain of errors because it is reporting results as base64 instead of json. Thoughts?

Hey @Bill_Waring!

Happy to help here! So this resource was previously returning JSON in Retool and is now returning base64? If you query this resource outside of Retool is the same base64 returned?

Hey @Chris-Thompson,

No, when I run it through windows command line I get a JSON response. Has anyone else had this issue - I wonder if it's a browser issue.

I just ran retool on Edge and it returns base64 also. So it looks like it might be a retool issue.

I just asked my team and it doesn't sound like we have any other users writing in about this at the moment :thinking:. One option to get you unblocked while we get to the bottom of this would be to add a query transformer on this query using something like:

return JSON.parse(atob(data))

This may need to be adjusted depending on your data though. Would you mind sharing a screenshot of an example of the return of this query?

Yeah it's not a big deal to run a transformer - I just thought it was very strange to run without issue for a year and then to stop working. Anyway - thanks for you help.

Definitely is strange so this endpoint was working in Retool up until now? What resource type is it?

Sorry - here's a screenshot of the rest api query.

I'm having a hard time getting this decoded. I keep getting an error that the base64 was not encoded correctly to decode with atob().

Ah I see, could you try:

return JSON.parse(atob(data.base64Binary))

The base64 in this case may be nested in the query response a bit

I'm at a loss here. If I run:

var data = {{query.data.base64Binary}};
return atob(data)

I get a decoded string.

But when I run:

return JSON.parse(atob(data))

I get this error:
image

I see, is this in the queries transformer or in a separate transformer?

I've done it in both and it results in the same error.

I've also just tried nesting the atob() in my papa.parse injestion query to put the api results directly into my database, but that is throwing some errors. Were there any changes to the way retool handles api requests that would change the Content-Type header? Is it possible to see the raw api call in retool?

Okay, all fixed with a transformer:

var data = {{TimeularReport.data.base64Binary}};

return Papa.parse(atob(data),{header:true})

Good to hear! I'm going to work on reproducing this on our end, do you know approximately when this started occurring for you? I'll check back through any related changes on our end.

Would you mind sharing a screenshot of the fileType included in the response of your query here?

Hey @Bill_Waring — our team just shipped a potential fix this mornging. If you run your query without this transformer, does it still return base64Binary?

1 Like

@Chris-Thompson Just thought I'd add a note that this had affected us too and the fix appears to have sorted it :ok_hand: