REST API - Get the Input of user id and Pass the count of Assigned Tickets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 07:23 AM
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.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 05:25 PM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 10:46 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2020 01:34 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2020 09:42 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 07:44 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader