Recommended Method for Including Nested JSON Data Payloads in HTTP Push?

This topic was automatically generated from Slack. You can find the original thread here.

What’s the recommended way to include JSON data payloads in a HTTP push?

I can see there’s a tab for “Body”, and I can choose a application/json content type, but because I have a JSON object that has nested objects within it, I can’t seem to use the UI helper for “Edit Key-Value Pairs”.

Am I right that the only way is to use the raw request body mode, and then just use expressions to include a json object from a previous code step? Will that properly encode things?

Am I right that the only way is to use the raw request body mode, and then just use expressions to include a json object from a previous code step? Will that properly encode things?
Hi , I think this is one way to go. You’ll need to add the header Content-Type: application/json

Yes, under the Body tab, there’s a Content-Type dropdown for application/json which I’ve set.

So can I just paste in a reference to a variable that is a JSON object in the raw request body box, or do I have to do something special?

E.g. like this

And steps.prepare_trustpilot_data.$return_value.trustpilot_data would be a JSON object

oh for that you can stringify the object as JSON as this to be sure

{{ JSON.stringify(steps.prepare_trustpilot_data.$return_value.trustpilot_data)}}

Cool, okay

Wasn’t sure if I’d have to do that or not

you can alway test by creating another HTTP trigger, get the HTTP endpoint, put it in your HTTP action, then Test the action

You should see the HTTP request as a new event in your new HTTP trigger

Thanks, yeah

I’ve got it connected to a test trustpilot account anyway, so I guess it’ll either work or not work

Also I thought I would be able to see the generated request body in the results section of that step anyway