REST API, Python and creating new incident ticket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2018 03:20 AM
Hello,
I have an issue with creating an incident ticket using REST API and Python. In general it works, I can create it, set short description, CIs, contact information, priorities etc.. But not everything works fine. When I try to also fill creator group in the ticket, it works as long as I won't take a look in the ticket. Then the group blinks and dissipaters from the view. But the worst issue is when I try to create and assign the incident to some group, it just fails but in a strange way. REST API response is 201, so it looks good, but in response headers I can see things like:
'location': 'https://xxx.xxx.xxx/api/now/table/incident/NULL'
So, I can create the incident, but only if assignment group isn't specified. What can be wrong here?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2018 05:56 PM
I'd guess you've got some assignment rules or data lookup rules that are trying to set the 'Assignment group' field. If you view the created record in a list is the Assignment group there?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2018 10:11 PM
When I try to create a ticket with assignment group then no ticket is being created at all. When I remove that field from the script, then the incident is there, but assignment in XML view looks like this:
<assignment_group/>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2018 10:37 PM
Have you tested this successfully with the REST API Explorer in ServiceNow? Can you do a quick test with something like Postman to see if that works? We need to see if we can determine if the problem is somewhere with ServiceNow or with what you're sending to ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2018 10:47 PM
The issue is I'm just an user of ServiceNOW and I don't have an access to API Explorer, so I figured out how to create an incident by looking at sample code provided here, and by trial and error 🙂 My code looks like this at the moment:
# Incident vars
short_description = "MONITORING TEST: Share is full"
assignment_group = "0996f38ec89112009d04d87a50caf610"
contact_type = "Event1"
u_contact = "a7761d3a44511200e4852779951f55da" # you / contact person
caller_id = "a7761d3a44511200e4852779951f55da" # affected user
u_creator_group = "0996f38ec89112009d04d87a50caf610"
description = "Share 'this and this' is full, please do something."
u_symptom = "b3a47ffcb07932002f10272c5c585dfc" # Information
state = '3' # Assigned, 3 - work in progress, 2 - assigned
incident_state = '2' # Assigned ?
u_infrastructure_ci = '42e2472a65fa26009d04fcdf1618cb81' # Dummy CI
work_notes = 'a work notes test1' # Work notes
comments = 'comments test' # Additional comments
# Set proper headers
headers = {"Content-Type": "application/json", "Accept": "application/json"}
# Do the HTTP request
response = requests.post(url, auth=(user, pwd), headers=headers,
data=str({"short_description": short_description,
"u_creator_group": u_creator_group,
"contact_type": contact_type,
"u_contact": u_contact,
"description": description,
"u_infrastructure_ci": u_infrastructure_ci,
"u_symptom": u_symptom,
"caller_id": caller_id,
"work_notes": work_notes,
"comments": comments,
"assignment_group": assignment_group,
"state": state,
}), verify=False)
I also tried to create a incident without creator and assignment groups, and then update it with PUT request, but also with no luck.