How to get all incidents bases up on status and Configuration Item via RESTAPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 10:43 AM
Hello everyone,
I have a requirement where I would need to get all incidents in an open state via RESTAPI.
I'm trying to get it from the below curl API request, but it is giving all incidents
curl -s -X GET -H "Content-Type:application/json" -H "Authorization:Basic <TOKEN>” "https://tokyo.servicenow.com/api/now/table/incident
I want to get all of the incidents which are in status - Open, Closed and Resolved separately, also can we filter the Incidents based on "Configuration Item"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 10:52 AM
@knchaitanya9 You can use sysparm_query parameter and add the filter query based on your requirement .
eg:
curl "https://YourInstanceName.service-now.com/api/now/table/incident?sysparm_query=stateIN1%2C2%2C3%2C6%2C7%5Ecmdb_ci%3D46cb6095a9fe19810129cd0c1f8fc6d2&sysparm_limit=10" \
--request GET \
--header "Accept:application/json"
Doc link for further details.
Thanks,
Harsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 07:21 PM
Thanks @Harsh Vardhan
I will try and look into the documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 07:40 PM
HI @knchaitanya9 ,
I trust you are doing great.
Please find below curl code :
Get all incidents in the "Open" state:
curl -s -X GET -H "Content-Type:application/json" -H "Authorization:Basic <TOKEN>" "https://tokyo.servicenow.com/api/now/table/incident?sysparm_query=active=true^state=1"
Get all incidents in the "Closed" state:
curl -s -X GET -H "Content-Type:application/json" -H "Authorization:Basic <TOKEN>" "https://tokyo.servicenow.com/api/now/table/incident?sysparm_query=active=false^state=7"
Get all incidents in the "Resolved" state:
curl -s -X GET -H "Content-Type:application/json" -H "Authorization:Basic <TOKEN>" "https://tokyo.servicenow.com/api/now/table/incident?sysparm_query=active=false^state=6"
Filter incidents based on "Configuration Item":
curl -s -X GET -H "Content-Type:application/json" -H "Authorization:Basic <TOKEN>" "https://tokyo.servicenow.com/api/now/table/incident?sysparm_query=active=true^state=1^cmdb_ci=<CONFIGURATION_ITEM>"
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi