REST API - Get the Input of user id and Pass the count of Assigned Tickets

Hari7
Kilo Guru

I have a requirement where I need to get the value of the user id as input outside of ServiceNow and send this value to ServiceNow using REST API to get the count of how many tickets assigned to this user id. Please let me know if anyone has done something like this or have some inputs. 

15 REPLIES 15

So it will work for assigned_to as this field is inherited from the parent task table. For others, you'll either need to complete individual api calls with a different encoded query or setup a scripted rest API.

This scripted rest API could ingest a userID and then perform a lookup for each reference field on specified tables. It can then spit out a JSON object of this information broken down.

{

"assigned_to" : 4,

"requested_for" : 4,

"created_by": 20

}

 

I have created individual API links listed below and this works as intended.


RITM & Incident Count: https://xxxx.service-now.com/api/now/stats/task?sysparm_query=active%3Dtrue%5Eref_sc_req_item.request.requested_for.user_name%3Dkab%5EORref_incident.caller_id.user_name%3Dkab&sysparm_count=true

Assigned_To Count: https://xxxx.service-now.com/api/now/stats/task?sysparm_query=active%3Dtrue%5Eassigned_to.user_name%3Dkab&sysparm_count=true

I need to create a Scripted REST API so that I can have as one single API link which can get the input of user_id and pass the ticket count as output. I was able to do this with scripted REST API but I have to input the user name in the REST API script. How can we make this as dynamic so that I can the input outside of ServiceNow and pass it through the REST and get the value.

 

Hi Kieran,

I was able to create a 1 single scripted REST API with multiple metrics and on multiple tables and get the output as JSON. Thanks for your support. 

You're welcome Hari,

If my reply helped with your issue please mark helpful ???? and correct if your issue is now resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Hari,

you can use REST API explorer to check the count

HTTP Method: GET

Endpoint: Table 'task'

Query - assigned_to.user_name=<Your User ID>

https://instanceName.service-now.com/api/now/table/task?sysparm_query=assigned_to.user_name%3Dbeth.anglin

Regards
Ankur

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