servicenow_rest_attachment_api_python_simple_binary_example.py
#Need to install requests package for python
#easy_install requests
import requests
# Request Docs: http://docs.python-requests.org/en/master/user/quickstart/
# Set the request parameters
url = 'https://bbarnsc1.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=81f8915bdb6ba20028927416bf961971&file_name=issue_screenshot'
# url = 'https://fejr5sb8ead6.runscope.net/api/now/attachment/file?table_name=incident&table_sys_id=81f8915bdb6ba20028927416bf961971&file_name=issue_screenshot'
# specify files to send as binary
data = open('issue_screenshot.jpg', 'rb').read()
# Eg. User name="admin", Password="admin" for this code sample.
user = 'xxxx'
pwd = 'xxxxxx'
# Set proper headers
headers = {"Content-Type":"image/jpg","Accept":"application/json"}
# Do the HTTP request
response = requests.post(url, auth=(user, pwd), headers=headers, data=data)
# 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)