Pass Json body in Http Request issue

I have a post method, and I need to pass a variable there.
Once I am trying to do that - I receive code 400.
The Test Json without variable that receives code 200 is ( in one line):
“{ ““appUserName””: ““username””, ““fileExt””: ““txt””, ““fileBase64"”: ““dGVzdDM=””, ““fieldsKeyValue””: { ““company””:”“07"”, ““insuree_id””:”“11581642"”, ““policy_num””:““600015977"”, ““doc_type””:”“902"”, ““doc_date””:““01/01/2019"” }}”

When I try to paste a variable there - i receive code 400. It looks like this:
“{ ““appUserName””: “+ Variable1+”, ““fileExt””: ““txt””, ““fileBase64"”: ““dGVzdDM=””, ““fieldsKeyValue””: { ““company””:”“07"”, ““insuree_id””:”“11581642"”, ““policy_num””:““600015977"”, ““doc_type””:”“902"”, ““doc_date””:““01/01/2019"” }}”

I searched through many topics on the forum, but have not found out.
I took two ways of syntax from here:

The same request with single quotes retrieves code 400:
“{ ‘appUserName’: ‘username’, ‘fileExt’: ‘txt’, ‘fileBase64’: ‘dGVzdDM=’, ‘fieldsKeyValue’: { ‘company’:‘07’, ‘insuree_id’:‘11581642’, ‘policy_num’:‘600015977’, ‘doc_type’:‘902’, ‘doc_date’:‘01/01/2019’ }}”

Glad for the help.

@Slavich - please add additional double quotes for the variable1 as well

" “+ Variable1 +”"

1 Like

It doesn’t recognize variables in case I add double quotes"

Try this-
“{ ““appUserName””: “”+ Variable1+”“, ““fileExt””: ““txt””, ““fileBase64"”: ““dGVzdDM=””, ““fieldsKeyValue””: { ““company””:”“07"”, ““insuree_id””:”“11581642"”, ““policy_num””:““600015977"”, ““doc_type””:”“902"”, ““doc_date””:““01/01/2019"” }}”

1 Like

Thats what is did in second screenshot. - It doesnt recognize variable - AppUserName

can you share the complete screenshot with the error text of expression editor? (hover on blue with ! icon)

There is no error in expression editor. If I do as you mentioned above, the variable “AppUserName” is not recognized as variable, but as hardcoded string.

@Slavich - can you check the AppUserName variable scope? also change the variable type as string.

1 Like

I doublechecked. All fine with scope and type.

Try reading the JSON code from a text file but use a key(like XXVarXX) where the variable will go, then use stingreplace to replace the XXVARXX with your string variable.


I tried what you offered, but I receive again - code 400. Even if send the same variable, which was hardcoded before.
In case it is hardcoded - i receive code 200 - Ok.
In case of variable - receive code 400.

I would have to defer to someone more familiar with your use case, but would double check you syntax outside of the program to make sure your script has no errors. Perhaps share your script for us to see and redact the sensitive material-leaving the punctuation.

1 Like

As @matt_s suggested, do put XXVARXX inside double quote, your error might be cause of Syntax.

1 Like

There are my Json syntax:
“{ ‘appUserName’: ‘imageTest’ }” - hardcoded one - doesn’t work
“{ ““appUserName””: ““imageTest””}” - hardcoded one -yes works
“{ ““appUserName””: “+VAR+”}” - not hardcoded and doesn’t work.
I need to make it work with variable.

The problem was in particular this API server. According to its syntax, it accepted the request with triple quot like:
“{ ““appUserName””: ““”+VAR+”“”}”
Thanks to UiPath support team.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.