12-04-2023 12:28 PM
I have a recipe with an HTTP Request action with monitor error handling to logger and email. I can attach the HTTP Response "Body" field into the logger and email, but is there a way to apply JSON formatting to it so it's easier to read?
Solved! Go to Solution.
12-04-2023 02:01 PM
You can do this with a quick JavaScript action.
Create one with an input and output like this. Replace the message data pill with your HTTP response:
Use this code:
exports.main = async ({ obj }) => {
var pretty = JSON.stringify(obj, null, "\t");
return { pretty };
}
You can use the "pretty" output pill as-is in a plaintext email to get this:
If you want to use it in an HTML email, use "pre" like this:
Emails like this in monospace font:
Hope this helps!
12-04-2023 03:21 PM
It's working now, thank you!
Realized, from the "Send Request via HTTP" action I needed to pass through the "Response" datapill and not the "Body" containing the "Response"
12-04-2023 02:01 PM
You can do this with a quick JavaScript action.
Create one with an input and output like this. Replace the message data pill with your HTTP response:
Use this code:
exports.main = async ({ obj }) => {
var pretty = JSON.stringify(obj, null, "\t");
return { pretty };
}
You can use the "pretty" output pill as-is in a plaintext email to get this:
If you want to use it in an HTML email, use "pre" like this:
Emails like this in monospace font:
Hope this helps!
12-04-2023 03:10 PM
I see some encoding problems in the input (it's passing as a string instead of an object).
Is the input field set to formula mode or text mode? Make sure it's formula. This might fix it.
12-04-2023 03:21 PM
It's working now, thank you!
Realized, from the "Send Request via HTTP" action I needed to pass through the "Response" datapill and not the "Body" containing the "Response"
12-04-2023 03:45 PM
Excellent, that would have been my follow up suggestion! The "body" is encoded as a string, but the parsed response gets passed as an object.