REST API - "Error: Request is not valid JSON" Status Code: 400

Hi UIPathians,

After reading through tons of posts on REST API calls on the forum, still unable to figure out a reason for the error am facing.

Am trying to POST a REST request and the workflow looks like as below:

image

After going through many posts here, have tried with following values in the Body part till now:

  1. Single Quotes:
    “{“‘default_phone_number”‘:null,”‘password”‘: “‘1234”‘,”‘email”‘:”‘av@av.com”‘,”‘first_name”‘:”‘Joe”‘,”‘is_admin”‘: True,”‘last_name”‘:”‘Admin”‘,”‘permissions”‘:{“‘edit_apps”‘:True,”‘edit_cc_users”‘:True,”‘edit_data”‘:True,”‘edit_web_users”‘:True,”‘view_report_list”‘:,”‘view_reports”‘:True},”‘phone_numbers”‘:,”‘role”‘:”‘Admin”‘,”‘username”‘:”‘av2@av.com”‘}”

  2. Double Quotes, ecaped:
    “{““default_phone_number”“:null,““password”“: ““1234”“,““email”“:”“av@av.com”“,““first_name”“:”“Joe”“,““is_admin”“: True,““last_name”“:”“Admin”“,““permissions”“:{““edit_apps”“:True,““edit_cc_users”“:True,““edit_data”“:True,““edit_web_users”“:True,““view_report_list”“:,““view_reports”“:True},““phone_numbers”“:,““role”“:”“Admin”“,““username”“:”“av@av.com”“}”

  3. Only Single Quotes:
    “{‘default_phone_number’:null,’password’: ‘qwer1234’,’email’:’av1@avtest.com’,’first_name’:’Joe’,’is_admin’: True,’last_name’:’Admin’,’permissions’:{‘edit_apps’:True,’edit_commcare_users’:True,’edit_data’:True,’edit_web_users’:True,’view_report_list’:,’view_reports’:True},’phone_numbers’:,’role’:’Admin’,’username’:’av1@avtest.com’}”

All yield same error: “Error: Request is not valid JSON” Status Code: 400

An help on this is highly appreciated.
Thanks!

@ovi
@badita
@aksh1yadav

Check for JSON validator using various website available one of them - https://jsonformatter.curiousconcept.com, https://jsonlint.com/… I tried one of your JSON and got the error invalid JSON

Thanks for looking into, @Akash_N_Jain!
I looked into the formatter and it gives same error for all the three varieties " [Strings should be wrapped in double quotes.](javascript:;)"

Also, the format in which UiPath accepts the JSON is different from normal JSON format. Any way to validate the former?

Sample JSON - {
“Enabled”: true,

 "Name": "HelloTrigger11",

 "ReleaseId": 26471,

 "ReleaseKey": "66d493f1-080b-428d-821e-ba4e460ddb",

 "ReleaseName": "helloLog_hello",

 "PackageName": "helloLog",

 "EnvironmentName": "hello",

 "EnvironmentId": "16584",

 "StartProcessCron": "0 0 0/1 1/1 * ? *",

 "StartProcessCronDetails": "{\"type\":1,\"minutely\":{},\"hourly\":{\"atMinute\":0,\"frequencyInHours\":\"1\"},\"daily\":{},\"weekly\":{\"weekdays\":[]},\"monthly\":{\"weekdays\":[]},\"advancedCronExpression\":\"\"}",

 "StartProcessCronSummary": "Every hour",

 "StartProcessNextOccurrence": "2018-08-02T07:30:00Z",

 "StartStrategy": -1,

 "StopProcessExpression": "",

 "StopStrategy": null,

 "ExternalJobKey": null,

 "TimeZoneId": "India Standard Time",

 "TimeZoneIana": "Asia/Calcutta",

 "Id": 0

}

@Akash_N_Jain
Same error!
Is this something that should be entered explicitly? Does it mean something I don’t know?

Nopes that was required for the JSON that i was forming

okay!
so am still unable to get rid of the error…

@ovi @ClaytonM @badita

Have corrected one of your JSON & it shows as valid now:
{
“default_phone_number”: null,
“password”: “qwer1234”,
“email”: “av1 @avtest.com”,
“first_name”: “Joe”,
“is_admin”: “True”,
“last_name”: “Admin”,
“permissions”: {
"edit_apps ": "True ",
“edit_commcare_users”: “True”,
“edit_data”: “True”,
“edit_web_users”: “True”,
“view_report_list”: null,
“view_reports”: “True”
},
“phone_numbers”: null,
“role”: “Admin”,
“username”: “av1 @avtest.com
}

I observed lot of random quotation marks used in JSON. When you try to validate the JSON on online please follow the error message that it shows which will help you in resolving the same.

Hey @Akash_N_Jain,
Thanks for helping out.
The thing is, JSON format used in normal tools like Postman does not work in UiPath.
image

@Akanksha_Varshney
Hi. Don’t know if this helps, but sometimes when you copy text with quotations it copies a different character for the quotation marks and so it doesn’t work in UiPath. Try replacing all the quotation marks manually, because it should create “strings” in colored text within the Expression editor.

1 Like

Hi @ClaytonM,

Thanks for the inputs!
I have tried the string even by manually replacing all the quotes but still get the error as “Invalid JSON”

Any other thoughts on this?
Thanks!

I use https://jsonformatter.org and https://codebeautify.org/jsonvalidator
to validate the JSON data.

Hi Akansha,

Did you solve the issue, because I am also facing same issue?

Hey @roma.sodha,
Yes, I was able to solve this by putting the whole JSON in a JSON file and reading the same. Reading an external makes it convenient for UiPath to figure out the best way to deal with quotes.
Let me know in case of further questions.
Thanks!

Can you send me sample workflow working?

Hey @roma.sodha,

The message got missed somehow.
Please find attached a sample json file.
Would be glad if it still helps!

Request_Body.json (549 Bytes)

I am trying to put a filter in the body of the request. unfortunately, its not working for me. so far I tried double quotes 2x and single quotes. I just discovered this post about creating the json file. Did you put the file path of the json file in the request body field?

Hello Imran,
In this video I work with a complex JSON:

Thanks,
Cristian Negulescu