I would like to have an integration to pull the data from an external source and create records in a custom table. Can someone help?

Rijeesh Rathna1
Tera Contributor

Hi All,

I would like to have an integration to pull the data from an external source and create records in a custom table. The daa will be pulled every sec and should create/update the corresponding records. Can someone help? The external API is created with a token for security purpose. 

The API Information sample is below.

GET https://mydomain.net/api/vm/
Content-Type: application/json
Authorization: token <insert token here>

Also below is the JSON Sample.

[
{
"vm": "vm-123",
"name": "ABCSharePoint",
"power_state": "POWERED_ON",
"cpu_count": 4,
"memory_size_MiB": 24576,
"resource_pool": "resgroup-123",
"pool_name": "ABC-SQL",
"vsphere_instance": "ABC_INFRA",
"total_disk_MiB": 697796,
"timestamp": "2022-01-03T12:23:20.781822+04:00"
},
{
"vm": "vm-12345",
"name": "XYZ-ADC1",
"power_state": "POWERED_OFF",
"cpu_count": 4,
"memory_size_MiB": 16384,
"resource_pool": "resgroup-1234",
"pool_name": "XYZ-DC",
"vsphere_instance": "ABC_INFRA",
"total_disk_MiB": 42949,
"timestamp": "2022-01-03T12:23:20.981633+04:00"
}
]

Thanks,
Rijeesh Rathnakumar

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

Please find the steps below to achieve your requirement:

1) Create a Outbound Rest API by navigating to the module "Outbound Rest" as shown below:

find_real_file.png

2) Click on New button and give a valid Name as shown below:

find_real_file.png

3) Now click on New under HTTP Method as shown below and select method as "Get"

find_real_file.png

4) Define your HTTP header and then you can write a Async or After Insert and Update Business Rule on your table where you want and use the script below to fetch the response

Sample script shared below to be used in BR:

 try { 
 var r = new sn_ws.RESTMessageV2('Get Records', 'Get Records');

//override authentication profile 
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

 var response = r.execute();
 var responseBody = response.getBody();
for(var i=0;i<responseBody.length;i++){
createRecord(responseBody[i]);
}

 var httpStatus = response.getStatusCode();

function createRecord(responseBody[i]){
var gr = new GlideRecord('Table Name');
gr.initialize();
gr.FIeldName = responseBody[i].vm;
gr.FIeldName = responseBody[i].name;
gr.FIeldName = responseBody[i].power_state;
gr.FIeldName = responseBody[i].cpu_count;
gr.insert();

}
}
catch(ex) {
 var message = ex.message;
}

 

This way you can fetch the response and then parse it and insert record.. Let me know if you are facing an issue.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

13 REPLIES 13

Sandeep74
Tera Expert

Hi Rijeesh,

 

can you create the post method to update those records and set the time limit for that so after everytime its get updated with those records .

 

thanks,

sandeep

Hi Sandeep,

Thanks for your reply. Sorry, I dont have any expertise of REST scripting or coding. Can you please guide me on how to do it from scratch?

Thanks,
Rijeesh Rathnakumar

Sourabh26
Giga Guru

Hi,

 

Below are pre requisite for the pull request -

  • Get the end point details of the 3rd party application.
  • Get the user credentials for authentication purpose. 

Once done you need to just create the REST Message to configure same things in your Service Now instance.

 

Then create a business rule to get which call your REST message to get all the data and do your server side scripting based on your requirement to insert the data in your table.

 

Mark this as Helpful if it helps you in anyways.

 

Regards,

Sourabh

Hi Sourabh,

Thanks for your reply. 

Yes, I have the end point details and its using a token to access it. 

Can you please guide me on how to create a rest message in ServiceNow and to configure the business rule? If you have any sample, can you please share that? Sorry, I am new to this type of configuration and dont have much idea about it.

Many thanks in advance.

Thanks,
Rijeesh Rathnakumar