Update incident in service now using Python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2021 04:13 AM
Hi All,
I am trying to post worknotes(additional_comments) on an incident using below in a python script. I have tried the same with Request Item and was able to do so.
I have tried this with request item (sc_task)
def postComments(sctaskID, notes):
uname, pwd = X,Y
url = '{0}processRequestTask.do'.format(ServiceNowBaseURL)
headers = {"Content-Type":"application/xml", "Accept":"application/xml"}
content = "<request><task_id>" + sctaskID + "</task_id><additional_comments>"+ notes + "</additional_comments></request>"
logging.info(content)
r = requests.post(url, data=content, auth=(uname, pwd), headers=headers)
responseCode = getResponseCode(r)
if responseCode != "0":
logging.error(r.text)
return None
return "Success"
What will be used for incident (inplace of processRequestTask.do).. i have tried incident.do
& processincident.do
but it doesn't work.
Is there any way we can find what URL is used in service now to process an incident while doing an API call.
If I try: https://instance.service-now.com/incident.do --> it leads to create new incident page. I wish to update the additional comments in the incident.
Any help is greatly appreciated!! Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2021 06:56 AM
Hi Piyush,
You can use below sample code.
#Need to install requests package for python
#easy_install requests
import requests
# Set the request parameters
url = 'https://instanceName.service-now.com/api/now/table/incident/sys_idOfIncident'
# 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.patch(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)
Hope it helps.
Regards,
Ujjawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2021 07:03 AM
Updated with comments field
#Need to install requests package for python
#easy_install requests
import requests
# Set the request parameters
url = 'https://instance.service-now.com/api/now/table/incident/sys_idOFIncident'
# 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.patch(url, auth=(user, pwd), headers=headers ,data="{\"comments\":\"something\"}")
# 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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2021 04:49 AM
Hi Piyush,
If I helped you to resolve your query with my answer. Then I would really appreciate if you can mark my answer correct and helpful. So that it can be moved to answered list and helpful for future readers.
Regards,
Ujjawal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2021 06:57 AM
Hi,
Please find the samples and documentations on below link.
Thanks,
Anil Lande
Thanks
Anil Lande