REST API w/Python for SENDING PUT/POST for assigning ticket to myself
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 08:10 AM
Hello everyone,
I am new to the community, sorry if I mismatched the board.
I am new to snow api environment. I am currently working on getting ticket table via get (python requests).
I wonder if you can write just a sample snippet for assigning incident number xxx to myself via API.
Thank you a lot in advance.
Davide
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 12:19 PM
You error says it all. You are not passing a proper JSON object. try this instead:
data = json.dumps({ "assigned_to": "your_sys_id"})
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 02:24 AM
Update:
headers = {"Content-Type":"application/json","Accept":"application/json"}
data = {'assigned_to':'12axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa'}
response = requests.put(url, auth=(user, pwd), headers=headers, json=data, timeout=None)
now I get 200 but incident is not assigned to me, state doesn't turn into 'in progress'.
Could you help me wiath that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 04:02 AM
Update
headers = {"Content-Type":"application/json","Accept":"application/json"}
data = {'assigned_to':'12cxxxxxxxxxxxxxxxxxxxxxxxxxa'}
response = requests.put(url, auth=(user, pwd), headers=headers, json=data, timeout=None)
returns status 200 but still no change in ticket state (it remains assigned with u_presa_in_carico_on_hold = false)
Please help
Thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 04:09 AM
HI @DavideT ,
I trust you are doing great.
Please refer the below code for the same.
import requests
from requests.auth import HTTPBasicAuth
# ServiceNow instance details
instance_url = 'https://your_instance.service-now.com'
api_endpoint = '/api/now/table/incident/'
incident_number = 'INC0012345' # Replace with your incident number
user_sys_id = 'your_sys_id' # Replace with your user sys_id
# Authentication details
username = 'your_username'
password = 'your_password'
# Headers
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
# Data to update the incident
data = {
'assigned_to': user_sys_id
}
# Construct URL
url = f'{instance_url}{api_endpoint}{incident_number}'
# Make the PUT request
response = requests.put(url, auth=HTTPBasicAuth(username, password), headers=headers, json=data)
# Check the response
if response.status_code == 200:
print('Incident assigned successfully.')
else:
print('Failed to assign incident:', response.content)
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2023 08:59 AM
Dear Amit,
thank you but this is not working!
In fact, you can see above the result of the code you posted (that I tried by myself as well before).
What I need is to 'click' on the 'Assign to me' button so that the incident will CHANGE STATE as it follows:
I thank you but I still need help. Maybe the topic was not clear at the start and I apologize for that. Please help!
Thank you.
Davide