Need to pass variable in Json body for API call

Hi All,

I am using http request activity in which I have to pass 2 variables in Json Body and then pass the same Json in Body (Properties options in HTTP Request activity). 1st variable(Request ID) is working fine but I am getting below error for 2nd variable(Transaction ID). I am also providing the complete Json body and their output along with error.

Error:
{“fault”:{“faultstring”:“JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason: Expected STRING or NUMBER or OBJECT or ARRAY at line 13”,“detail”:{“errorcode”:“steps.jsonthreatprotection.ExecutionFailed”}}}

Json Body that I am using:

“{”“Service”“:{
““ServiceHeader””:
{”“RequestorID”“:”“RPA”“,
““RequestID””:”&RequestID.ToString & "
}
,
““ServiceBody””:
{
““CallReason””:““DEA””,
““CallRequest””:
{““Action””:““UpdateVcatsRPAStatus””,
““Body””:
{
““EntityStatus””:““RequestQueued””,
““TransactionID””:“&TransactionID.ToString & "
}
}
}
}
}”

Json Body Output:

{“Service”:{
“ServiceHeader”:
{“RequestorID”:“RPA”,
“RequestID”:21091135
}
,
“ServiceBody”:
{
“CallReason”:“DEA”,
“CallRequest”:
{“Action”:“UpdateVcatsRPAStatus”,
“Body”:
{
“EntityStatus”:“RequestQueued”,
“TransactionID”:b8efgb6a-4f51-4g00-a777-8de1d476756c
}
}
}
}
}

Kindly help.

@shekharhimanshu627,

It seems your API endpoint is expecting some specific values inside the JSON. Try passing hardcoded values if it’s working.

Thanks,
Ashok :slight_smile:

@ashokkarale , Thanks for your response
Hardcoded value is working fine but in my case I have to use dynamic transaction ID value. Please find below hardcoded sample json body which is working absolutely fine.

{“Service”:{
“ServiceHeader”:
{“RequestorID”:“RPA”,
“RequestID”:“19186855”
}
,
“ServiceBody”:
{
“CallReason”:“DEA”,
“CallRequest”:
{“Action”:“UpdateVcatsRPAStatus”,
“Body”:
{
“EntityStatus”:“RequestQueued”,
“TransactionID”:“6d010d1a-5dfe-48bc-9615-fc1714fb828d”
}
}
}
}
}

@shekharhimanshu627,

Pass your variable this way

""RequestID"":""+ RequestID.ToString + ""

Concatenation operator is +

Thanks,
Ashjok :slight_smile:

@ashokkarale Already tried but same result. Thanks

I am facing issue only for Transaction ID not for Request ID

The image shows a snippet of a JSON-like structure intended for a service request, containing service header and body with fields such as , , ,  and nested actions  with attributes  and . (Captioned by AI)

Hi @shekharhimanshu627,

The best approach here is to use a txt file to have your JSON body template, read the txt file, replace the value with a dynamic variable, and pass it to the HTTP Request.

jsonbody.txt

{“name”:“John”, “ID”:“vID”}

vID - is the placeholder

In code, read the jsonbody.txt, store it as strJsonBody, and replace the values like

strJsonBody.Replace(“vID”, strID)

and pass the value to the HTTP request.

Hope it helps.

Regards,
Ranjith Udayakumar

The problem with this approach is you are missing the quotations for the string variable value. To have clear structure and ease of use, go with the approach I mentioned.

““TransactionID””:“”“+TransactionID.ToString+”“”

You can use asset also instead of txt file if you prefer.

@shekharhimanshu627,

Put this into a variable with Assign activity and analyze the structure. Then pass this variable to HTTP Request.

Thanks,
Ashok :slight_smile:

@ranjith_udayakumar Not working.

One additional way to do this is with the Deserialize JSON activity, like so:

Sample project:
DeserializeJSONSample.zip (16.1 KB)

This requires the latest Studio and System activity package, but the principle behind is the new JSON Sample property of the Deserialize JSON activity. It allows you to “generate” the actual usable object based on your JSON sample, and then to simply assign your desired values to its properties.

After you are done, you simply convert it back to a string and you have your input.

One thing to keep in mind is that you need to match your API’s requirement, so it could either be this:


or this:

(one has quotes and the other doesn’t)

1 Like