#Need to install requests package for python
#easy_install requests
import requests
# Set the request parameters
url = 'https://[instance name].service-now.com/api/now/table/[table name]'
# 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 - this is fake data
response = requests.post(url, auth=(user, pwd), headers=headers ,data="[your json string of fields and values]")
# 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)
ServiceNow table REST API非常简单,因此使用Python将记录插入任意表中非常简单。例如:
ServiceNow中的restapiexplorer对于构建和测试查询非常有用。它甚至生成示例代码。您可以在navigator中搜索restapiexplorer来找到它。在
另一个选择是在ServiceNow中创建一个Scripted REST API,以创建一个自定义URL,您可以点击该URL来获得通知。如果您不需要持久化数据而只想得到通知,那么这是很好的。在
相关问题 更多 >
编程相关推荐