REST API Response format

Abhinab Achary1
Tera Guru

Hi All,

I am working on an integration. i have to use GET method.

I have an api end point with method get which only return in the format of XML only. I am only supposed to use REST.

How can i convert the XML to a table in servicenow effectively. I am not to use SOAP.

 

 

Thanks,

Abhi

11 REPLIES 11

Hi Abhinab,

So what is your question now?

you are getting response in xml, you are not facing any issue in parsing xml.

Regards

Ankur

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

Mahendra RC
Mega Sage

Hi Abhinab,

You can refer the below link for parsing the XML response:

https://docs.servicenow.com/bundle/kingston-application-development/page/script/server-scripting/con...

if you are working on scoped application then you can refer the below link:

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

Please mark this solution correct/helpful, if it resolves your issue.

Thanks

But i need to convert this to json as wrking on xml is very tedious.. so baiscally i want to covert that xml to json

i have already converted the xml to string and getting the nodes but , i want to convert that to complete json format

Hi Abhinab,

When you are consuming the 3rd party API can you set the http header as below:

Acceptapplication/json

May be this will try to give you json response in the body.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Abhinab,

Then I think you can check for some solution on internet. I haven't done this before. But I would like to share a thought

If you convert your entire XML response in Json and then read the data. you might need to store the XML response and then the JSON you got by converting the XML to JSON. because you will need these to troubleshoot the issue in future. Because error occur because of the following:

1) due to the data returned in XML response OR (so you need to store XML response)

2) there might be issue in converting XML to JSON OR (so you need to store JSON converted data to check if data was parsed correctly from XML to JSON)

3) there might be issue while reading the data from JSON.

think about this once before implementing.

Thanks.