簡體   English   中英

Python REST 現在服務 API 用於文本搜索

[英]Python REST Service Now API for text search

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

我有在 Service Now 中執行文本搜索的要求。 I'm planning to insert the texts to be searched in a csv file and then through a python rest API of service now, perform the text search.

但是,我無法找到任何直接 python REST Service Now API 來進行文本搜索。 有誰知道做這項任務的任何替代方法?

提前致謝!

您可以使用 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM