API to use for getting open tickets of any configuration item

RP5
Kilo Contributor

I am new to Service Now and to this community as well.

I am building a desktop application in Python to fetch below details from my Service Now account:

  1. Get all open tickets under a configuration item
  2. Get all tickets assigned to a particular group
  3. Assign tickets of a particular configuration item to a particular group

I want to know which API to use. I checked SNOW APIs section. There are various tables which it expects.

Can someone direct me to which API to use and from where to get the table name?

 

4 REPLIES 4

johnfeist
Mega Sage
Mega Sage

Hi RP,

Why don't you just build a filter or configure a list view to show you what you want to see and save yourself all the aggravation of building the interface?

If you have your heart set on the interface approach, you will need to build a database view to supply the data in a form that makes sense because several of the fields you want are references in the incident table so all you have is they sys_id.  You can't dot walk with an interface request. 

The primary table you need to to access is incident.  You will need to join to sys_user_group via incident.assignment_group = sys_user_group.sys_id to get the name and any other information about the assignment group.  You will also need to do a join to cmdb_ci using incident.cmdb_ci = cmdb_ci.sys_id to get data about your configuration item.  If you want to extract any other data that are references in incident (e.g. assigned to) you will need to include other joins.

If you are looking to do assignments coming back from Python (#3) that opens up a whole other set of issues/questions as best practice is to have any external interface populate a landing table.  You never want to give direct access to your OOTB or production tables to an external source.  In that scenario, you will need a job running on a regular interval, say every minute or two that will be checking for entries in the landing table and processing them.

Since you are working in Python, are you planning on interacting via the REST api or do you have another mechanism available?  If you are going to use REST, the SN documentation is pretty good (a rarity).  I'm not sure what other OOTB APIs you might want to use.  If you have the SN integration hub implemented you can use that as well.

Hope that helps.

:{)

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

RP5
Kilo Contributor

I want to use REST API and consume in Python application.

As of now, I just want to display open tickets under various configuration items. Also, I want to assign tasks in bulk to any specific person.

 

Community Alums
Not applicable

Hi RP,

PFB.

 

  1. Get all open tickets under a configuration item

Get API

https://INSTANCENAME.service-now.com/api/now/table/incident?sysparm_query=state%3D1%5EORstate%3D2%5Ecmdb_ci.name%3DApple%20-%20MacBook%20Pro%2015%22%20for%20Technical%20Staff

You need to enter the state values and CI name.  As of state in the above API is Open or In progress and CI Name is 'Apple - MacBook Pro 15" for Technical Staff'

     2. Get all tickets assigned to a particular group

GET API

https://INSTANCENAME.service-now.com/api/now/table/incident?sysparm_query=assignment_group.name%3DDatabase

Here you will have to give Assignment group name. In the above example I have taken assignment group as Database

   

3.Assign tickets of a particular configuration item to a particular group

POST API

 

https://INSTANCENAME.service-now.com/api/now/table/incident

 

Body:

{"cmdb_ci":"b4fd7c8437201000deeabfc8bcbe5dc1","assignment_group":"c2f32ab2dbe1230052bb73278c961992","short_description":"Test"}

 

In this you will have to build logic in python script to confirm which CI has to be assigned to which group.

 

 

Let me know in case of any queries.

Please mark this comment as Correct Answer/ Helpful if it helped you.

Cheers,

Hardit Singh

 

Here is a sample Python call that gets all incident where CI contains IBM 

#Need to install requests package for python
#easy_install requests
import requests

# Set the request parameters
url = 'https://dev68452.service-now.com/api/now/table/incident?sysparm_query=active%3Dtrue%5Ecmdb_ci.nameLIKEIBM&sysparm_limit=1'

# Eg. User name="admin", Password="admin" for this code sample.
user = 'admin'
pwd = 'admin'

# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}

# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers )

# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)