python ServiceNow REST附件API示例Python示例使用/ now / attachment / file endpoint将文件作为附件发布(上载)到inc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python ServiceNow REST附件API示例Python示例使用/ now / attachment / file endpoint将文件作为附件发布(上载)到inc相关的知识,希望对你有一定的参考价值。

#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)

以上是关于python ServiceNow REST附件API示例Python示例使用/ now / attachment / file endpoint将文件作为附件发布(上载)到inc的主要内容,如果未能解决你的问题,请参考以下文章

ServiceNow Rest API时域

ServiceNow常用系统表

使用 Python 进行 base64 解码,并使用基于 REST 的 Gmail API 下载附件

python 示例请求Python ServiceNow JSONv2 - GetIncidents使用编码查询从ServiceNow使用JSONv2 Web服务获取多个事件

python 示例请求Python ServiceNow JSONv2 - 更新事件

python 示例请求Python ServiceNow JSONv2 - 创建事件