0

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

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

但是,我找不到任何直接的 python REST Service Now API 来进行文本搜索。有谁知道做这项任务的任何替代方法?

提前致谢!

4

1 回答 1

1

您可以使用 ServiceNow 平台中的“全局文本搜索 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)
于 2019-11-15T06:29:59.637 回答