Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Outbound REST API GET from XML Response to Table

dylanlevy
Tera Contributor

So I have an Outbound REST API GET setup correctly and the test is pulling the data back correctly. I am trying to pull (using a GET) CIs from a third party tool into my cmdb (Access Points to a new Access Point table that extends from the Network Gear table)

It is pulling all the devices with the information needed, but I need help getting those devices into the new table. How should I go about doing this? This needs to happen on a reoccurring basis, so something scheduled would be preferred. I want to split out each entity to be its own record, making one of the fields the unique field. 

Here is an example of the xml response:

<?xml version="1.0" ?>
<queryResponse last="99" first="0" count="455" type="AccessPoints" responseType="listEntityInstances" requestUrl="" rootUrl="">
  <entity dtoType="accessPointsDTO" type="AccessPoints" url="">
    <accessPointsDTO displayName="693695" id="693695">
      <adminStatus>ENABLE</adminStatus>
      <bootVersion>1.1.2.4</bootVersion>
      <clientCount>0</clientCount>
      <clientCount_2_4GHz>0</clientCount_2_4GHz>
      <clientCount_5GHz>0</clientCount_5GHz>
      <controllerIpAddress>10.1.5.130</controllerIpAddress>
      <controllerName></controllerName>
      <countryCode></countryCode>
      <ethernetMac></ethernetMac>
      <hreapEnabled>false</hreapEnabled>
      <ipAddress></ipAddress>
      <location>default location</location>
      <lwappUpTime>170020453</lwappUpTime>
      <macAddress>/macAddress>
      <model></model>
      <name></name>
      <serialNumber></serialNumber>
      <softwareVersion></softwareVersion>
      <status></status>
      <type></type>
      <upTime></upTime>
    </accessPointsDTO>
  </entity>
  <entity dtoType="accessPointsDTO" type="AccessPoints" url="">
    <accessPointsDTO displayName="693700" id="693700">
      <adminStatus>ENABLE</adminStatus>
      <bootVersion>15.2.4.5</bootVersion>
      <clientCount>0</clientCount>
      <clientCount_2_4GHz>0</clientCount_2_4GHz>
      <clientCount_5GHz>0</clientCount_5GHz>
      <controllerIpAddress></controllerIpAddress>
      <controllerName></controllerName>
      <countryCode>US</countryCode>
      <ethernetMac></ethernetMac>
      <hreapEnabled>false</hreapEnabled>
      <ipAddress></ipAddress>
      <location>Store</location>
      <lwappUpTime>1538746054</lwappUpTime>
      <macAddress></macAddress>
      <model></model>
      <name></name>
      <serialNumber></serialNumber>
      <softwareVersion></softwareVersion>
      <status></status>
      <type></type>
      <upTime></upTime>
    </accessPointsDTO>
  </entity>
14 REPLIES 14


var r = new sn_ws.RESTMessageV2('Cisco Prime', 'GET Devices - APs');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

var xmldoc = new XMLDocument2();
xmldoc.parseXML(responseBody);
var node = xmldoc.getNode('/queryResponse');

var i = node.getChildNodeIterator();
while(i.hasNext()) {
   var entity = i.next().getChildNodeIterator();
   var j = entity.next().getChildNodeIterator();
   while(j.hasNext()) {
      var element = j.next();
      var fieldName = element.getNodeName();
      var fieldValue = element.getTextContent();
      gs.info(fieldName + ': ' + fieldValue);
   }
}

Maybe print your responseBody variable just to confirm that it is what you're expecting and there isn't any additional text? Other than that all I could think of is my string didn't have whitespace in between nodes but that shouldn't matter.

dylanlevy
Tera Contributor

Weird - I'm getting this error. I'm also going to attach the full response I'm seeing. Maybe that will help.

 

"java.lang.ClassCastException: org.apache.axiom.om.impl.dom.TextImpl cannot be cast to org.apache.axiom.om.impl.dom.ParentNode"

Mahendra RC
Mega Sage

Hi 

Could you please ping the request body as well.. I want to know if you are passing the ids in request or not

 

I am getting the response body when I print it.