Hi Friends,
I am creating the the Json for POST Body
Steps:
Reading parameters from Excel
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)
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
HareeshMR
(Hareesh Madasi)
May 13, 2019, 6:55am
4
That’s simple one.
Here are the steps :
use excel application scope to read the excel file and store in a data table.
Use for each row loop to iterate through the rows .
Use three variables in three different assign activities to get the name, age and salary.
Then build the json as required (as in the above reference)
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”}
HareeshMR
(Hareesh Madasi)
May 13, 2019, 7:10am
6
Yeah ok, give me 5 mins, will upload the file
HareeshMR
(Hareesh Madasi)
May 13, 2019, 7:15am
7
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
HareeshMR
(Hareesh Madasi)
May 13, 2019, 7:34am
9
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
1 Like
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.
HareeshMR
(Hareesh Madasi)
May 13, 2019, 8:27am
11
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
HareeshMR
(Hareesh Madasi)
May 13, 2019, 9:20am
14
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 response
1 Like
HareeshMR
(Hareesh Madasi)
May 13, 2019, 9:34am
16
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:
HareeshMR
(Hareesh Madasi)
May 13, 2019, 9:41am
18
If possible, Can you share the project personally so that I will check and let you know the issue?
HareeshMR
(Hareesh Madasi)
May 13, 2019, 1:13pm
20
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., ’ → “”
5 Likes