Unable to close the incident using Python Script
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-28-2019 01:13 AM
Hi,
I am trying to resolve/close the incident using python script in the developer instance. Below is the code I am using, but it throws this message "<Response [403 - PUT]>". But if I try to delete or update the incident record then its working fine with status code as 200. Please advise what I am doing wrong.
import pysnow
import requests
s = requests.Session()
s.verify = False
s.auth = requests.auth.HTTPBasicAuth('username', 'password')
c = pysnow.Client(instance='devxxxx', session=s)
incident = c.resource(api_path='/table/incident')
update = {"close_code":"Closed/Resolved","state":"7","close_notes":"Closed by Automation utility"}
###Different payloads tried
#update = {'state': '6','resolution_code':'Closed/Resolved by Caller','resolution_notes': 'Closed by Automation utility' }
updated_record = incident.update(query={'number': 'INC00xxxxx'}, payload=update)
print(updated_record)
Labels:
- Labels:
-
Personal Developer Instance
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-29-2019 08:31 PM
when you use put method then you have to define the record id so that it will identify which record you are going to update.
Adding sample code here.
#Need to install requests package for python
#easy_install requests
import requests
# Set the request parameters
url = 'https://devxxxx.service-now.com/api/now/table/incident/4350c0abdb998010e4d95740cf96196f'
# Eg. User name="admin", Password="admin" for this code sample.
user = 'id'
pwd = 'password'
# Set proper headers
headers = {"Content-Type":"application/json","Accept":"application/json"}
# Do the HTTP request
response = requests.put(url, auth=(user, pwd), headers=headers ,data="{\"short_description\":\"COMMUNITY\"}")
# 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)