REST API: I am getting response data in json when i test the 'get' method, how to add these data to table?

swathigangadhar
Tera Expert

I have a third party endpoint, when i save it am getting only 'Default Get' method(no other methods are generated), when i test, am able to get all user details in 'Response' field (json format) , now i want to add these records to my sys_user table, how to do that?

1 ACCEPTED SOLUTION

Hi Swathi,



you need to parse the response using JSONParser() and iterate over the key value pairs


Can you share the response so that the script can be designed?



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

11 REPLIES 11

lks
ServiceNow Employee
ServiceNow Employee

No worries about "Default Get" method, you will see only those methods which are available in that third party webservice end point. The OOB functionality says, you first configure a REST Message using that third party end point and then run that get method. From therefore, copy the code using ServiceNow script link and write a server side script e.g. Business rule, Scheduled Job script etc and call that REST message from there.



Let me know if it helps!


Lalit thanks a lot for your help, now am running that script through scheduled job, how to parse the obtained result and how to store it into sys_user table?


Hi Swathi,



you need to parse the response using JSONParser() and iterate over the key value pairs


Can you share the response so that the script can be designed?



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,


Below is the response i got...



{\"UserID\":\"10001460\",\"Name\":\"B. Swathi\",\"FIrst Name\":\"B.\",\"Last Name\":\"Swathi\",\"Email\":\"\",\"Company\":\"ABC Corp Limited\",\"Company Code\":\"ABC0002\",\"Building\":\"Nagar\",\"City\":\"Cp Dist\",\"Country\":\"INDIA\",\"Department\":\"Support\",\"Vertival\":\"Admin\",\"Sub Vertical\":\"Admin\",\"Gender\":\"Male\",\"Business Phone\":\"\",\"Location\":\"India\",\"Manager\":\"Ashok\",\"State\":\"Kar\",\"Street\":\"kur\",\"Time Zone\":\"\",\"VIP\":\"\",\"Pincode\":\"500\"}