API - Get Support Group Sys ID

lipetravis
Giga Contributor

I'm trying to use the ServiceNow API to get the system id for a particular support group. I would like to pass in the support group's name, like "Service Desk" and have the API return the support group's system ID.

Is this possible?

1 ACCEPTED SOLUTION

danpatino
Tera Expert

Here is how you would do it with javascript



var requestBody = "";



var client=new XMLHttpRequest();


client.open("get","https://YOUR_INSTANCE.service-now.com/api/now/table/sys_user_group?sysparm_query=name%3DService%20Desk&sysparm_fields=sys_id&sysparm_limit=1");



client.setRequestHeader('Accept','application/json');


client.setRequestHeader('Content-Type','application/json');



//Eg. UserName="admin", Password="admin" for this code sample.


client.setRequestHeader('Authorization', 'Basic '+btoa('admin'+':'+'admin'));



client.onreadystatechange = function() {


if(this.readyState = this.DONE) {


document.getElementById("response").innerHTML=this.status + this.response;


}


};


client.send(requestBody);




Let me know if you need it in Python cURL, Perl, Ruby or Powershell instead.


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Travis,



You can implement your logic via scripted REST API. More info here.


Scripted REST APIs


danpatino
Tera Expert

Here is how you would do it with javascript



var requestBody = "";



var client=new XMLHttpRequest();


client.open("get","https://YOUR_INSTANCE.service-now.com/api/now/table/sys_user_group?sysparm_query=name%3DService%20Desk&sysparm_fields=sys_id&sysparm_limit=1");



client.setRequestHeader('Accept','application/json');


client.setRequestHeader('Content-Type','application/json');



//Eg. UserName="admin", Password="admin" for this code sample.


client.setRequestHeader('Authorization', 'Basic '+btoa('admin'+':'+'admin'));



client.onreadystatechange = function() {


if(this.readyState = this.DONE) {


document.getElementById("response").innerHTML=this.status + this.response;


}


};


client.send(requestBody);




Let me know if you need it in Python cURL, Perl, Ruby or Powershell instead.


Thanks, this is perfect.