cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to pass HTTP codes in JSON output

kumar25
New Contributor II

Hi,

I have a JSON like below, have to pass the value of StatusCode into HTTP Header. I am using JSON Formatter, but incase of Failure also it gives 200 with the actual code in the JSON payload. Help me in how to handle this

JSON:
{
โ€œStatusCodeโ€:โ€œ500โ€,
โ€œStatusMessageโ€:โ€œSuccessโ€
}

4 REPLIES 4

j_angelevski
Contributor III

Hi @kumar25,

You can add the headers you want in the Binary header properties in the JSON Formatter snap.
In your case instead of using โ€˜500โ€™ in the expression field like in the sample below, you can use $StatusCode.
image

kumar25
New Contributor II

Hi @j.angelevski ,

I am able to get the error code in HTTP header along with that the entire message is published in the payload(as i am passing the entire input in the content of JSON Formatter).

How can i exclude statuscode field to be populated in the response.
image

@kumar25

You can choose what to provide in the response by changing the Content property by selecting the
StatusMessage field from the input or you can have a Mapper snap before the JSON Formatter and map the values that you only need.

kumar25
New Contributor II

Thanks @j.angelevski