I want to post an array of objects as the payload in an API request. I have implemented a JavaScript function called transformData
, which returns the desired payload. My understanding is that posting {{transformData.data}}
(which returns the payload I need) in the raw body of the API request should work. However, it is failing because the payload is being passed as a string by default in the request. I am attaching a screenshot of a sample file as proof for reference.
Note: I have already added the header Content-Type as application/json. Please tell me how can I tackle the default string conversion.
Try JSON.stringify(transformData.data)
Thanks for your reply.
Yes, I tried that and got the same result. The issue is that I don’t want the payload to be passed as a string—Retool seems to be triggering JSON.stringify by default. Instead, I need to send the payload as an array of objects in the API request.
Is there a way to pass an array of objects without it being converted into a string?
Heya - it's a shame this isn't working as you intended! I don't suppose you can share your app so I can test this on my end?
Thanks!
Hey there,
Thanks so much for your response!
I discovered that instead of passing the x-backend-api-key
header directly in my resource API, adding it in the API’s customization options and passing JSON.stringify(transformData.data)
resolved the issue.
Apologies for any inconvenience caused, and I really appreciate your help!