How to get all incidents bases up on status and Configuration Item via RESTAPI

knchaitanya9
Tera Contributor

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"

3 REPLIES 3

Harsh Vardhan
Giga Patron

@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.

https://developer.servicenow.com/dev.do#!/learn/learning-plans/utah/servicenow_application_developer... 

 

Thanks,

Harsh

knchaitanya9
Tera Contributor

Thanks @Harsh Vardhan 
I will try and look into the documentation

Amit Gujarathi
Giga Sage
Giga Sage

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