Python REST 服务现在 API 用于文本搜索

Python REST Service Now API for text search

我是 Service Now 中外部脚本的新手。

我有在 Service Now 中执行文本搜索的要求。我打算将要搜索的文本插入到 csv 文件中,然后通过 python rest API 服务,执行文本搜索。

但是,我无法找到任何直接 python REST Service Now API 来进行文本搜索。有谁知道执行此任务的其他方法吗?

提前致谢!

您可以在ServiceNow平台中使用'Global Text Search API'获取搜索结果。首先,您需要获取可用的搜索组列表,然后发送包含需要搜索的组列表和搜索关键字的查询。

这是一个在知识库和服务目录中搜索关键字代理的示例程序。

import requests

# Set the request parameters
url = 'https://<instance>.service-now.com/api/now/v1/globalsearch/groups'

# 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.get(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)

url = 'https://<instance>.service-now.com/api/now/v1/globalsearch/search?sysparm_groups=2b77ce594bd6c0d901b8fbe25ceff671&sysparm_search=agent'

# Do the HTTP request
response = requests.get(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)