HttpRequest - Json Creation POST Body

Hi Friends,

I am creating the the Json for POST Body

Steps:

  1. Reading parameters from Excel
  2. Iterating the excel file using for each

My expected Json —> “{”“name”": ““ArulMozhi””,"“salary”": ““23000"”,”“age”":"“20"”}"

Note: Attached the project and excel file

Please help me to create the json.POSTApi.zip (10.5 KB)
TestData.xls (25.5 KB)

Hi @Alagupandi,

Refer this post:

Thank You @HareeshMR
Gone through the reference but my problem is not explained there.

In My case, I am reading the data from excel and i have to create the json which is same as my expected one

That’s simple one.
Here are the steps :

  1. use excel application scope to read the excel file and store in a data table.
  2. Use for each row loop to iterate through the rows .
  3. Use three variables in three different assign activities to get the name, age and salary.
  4. Then build the json as required (as in the above reference)
  5. Send the post request within the for each row and the loop will iterate again with the new data.

Hope it helps.

Thanks again @HareeshMR

The problem here is i am not able to build the Json as expected, struggling there.

Have completed first 3/5 steps.

In my sample api, post body should be in this format {“name”:“test”,“salary”:“123”,“age”:“23”}

Yeah ok, give me 5 mins, will upload the file

JSON.zip (20.6 KB)

NewTest.xaml is the file you have to look into…

let me know if it helps

Thank you for your valuable response.

The problem with the format.

Actually POST body is accepting only this format.{“name”: “ArulMozhi”,“salary”: “23000”,“age”:“20”}" in my scenario.
But the way you have created is {‘name’: ‘ArulMozhi’,‘salary’: ‘2300’,‘age’:‘20’}

i.e. single quote instead of double quotes

Yes, the body or the headers in UiPath will only accept single quotes and they are valid JSON, we don’t have to bother about it. I don’t know why it is not accepting in your case. It should accept

oh ok @HareeshMR

Do you think any other way is possible to do this in uipath.

Do you have any other sample API’s to validate that.

I tried the same method and it worked for me.
I don’t have any sample API … Just try displaying the json formed before sending the request and Can you post the error you are getting?

oh…can you share the project

RestApiValidation.zip (13.2 KB)

Project - APITesting and check POST sequence just change the excel path and run the project

Again i checked it out with my server credentials and its working and giving me the exact result.

This is the json I’m sending to the server : “{‘username’:’” + user + “’,‘password’:’” + pwd + “’,‘url’:’” + url +"’}"…
Can you check from your end whats the error?

Attached the Json and responseJson Response

Are you sure you are getting it because of the JSON you are sending?

Try sending the request from postman and check whether it is working or not?

Postman request should be with double quotes

Yes perfect.

I am getting the proper response when trying to test in Postman(with double quotes).

Validated two different API’s, both am facing the same issue with JSON format

Reference:
https://reqres.in/
http://dummy.restapiexample.com

If possible, Can you share the project personally so that I will check and let you know the issue?

Attached project, please check the RestApiValidation
https://aws1.discourse-cdn.com/uipath/original/3X/9/3/93c5c9fa1c91039377b35bb6abb85f88cb63a9b2.zip

This one is working… I don’t know why it is working with double quotes only…

“{”“name”":""" + emp_name+ “”","“salary”":""" + emp_salary+ “”","“age”":""" + emp_Age+ “”"}"

Sorry for all the confusion…
Replace myJson activity value with the above and it is working…

The change is --> replace all the single quotes with two double quotes
i.e., ’ --> “”

1 Like