Zendesk API 搜索结果索引

问题描述 投票:0回答:1

我编写了一个Python脚本来在zendesk API中执行GET和PUT方法,并成功获取我想要的数据并对票证进行一些更新。

以下方法产生此票号“6442”,而 put 方法旨在删除标签

from urllib.parse import urlencode
import json
import requests

# Set the credentials
credentials = 'some email', 'some password'
session = requests.Session()
session.auth = credentials

# Set the GET parameters
params_noreply_window = {
    'query': 'type:ticket tags:test status<closed',
}

params_oustide_businesshour = {
    'query': 'type:ticket tags:send_whatsapp_obh status:new',
}

url_search1 = 'https://propertypro.zendesk.com/api/v2/search.json?' + \
    urlencode(params_noreply_window)
url_search2 = 'https://propertypro.zendesk.com/api/v2/search.json?' + \
    urlencode(params_oustide_businesshour)

response_noreply_window = session.get(url_search1)
response_oustide_businesshour = session.get(url_search2)
# -----------------------------------------------------------------------------

if response_noreply_window.status_code != 200 | response_oustide_businesshour.status_code != 200:
    print('Status 1:', response_noreply_window.status_code + 'Status 2:', response_oustide_businesshour.status_code,
          'Problem with the request. Exiting.')
    exit()

# Print the subject of each ticket in the results
data_noreply_window = response_noreply_window.json()
data_oustide_businesshour = response_oustide_businesshour.json()

# Ticket to update
# Create a list containing the values of the id field
# for each dictionary that is an element of the list data
id_merged1 = [result['id'] for result in data_noreply_window['results']]
print(type(id_merged1))
print(id_merged1)

id_merged2 = [result['id'] for result in data_oustide_businesshour['results']]
print(type(id_merged2))
print(id_merged2)


# Join value of list by using comma separated
id_merged1_joined = ','.join(map(str, id_merged1))
print(id_merged1_joined)

id_merged2_joined = ','.join(map(str, id_merged2))
print(id_merged2_joined)

# Package the data in a dictionary matching the expected JSON
data_comment1 = {"ticket":
                 {
                     "remove_tags": ["test"]
                 }
                 }
data_comment2 = {"ticket":
                 {
                     "remove_tags": ["send_whatsapp_obh"]
                 }
                 }


# Encode the data to create a JSON payload
payload1 = json.dumps(data_comment1)
payload2 = json.dumps(data_comment2)

print("**Start**")

# Set the request parameters
url_put_comments1 = 'https://propertypro.zendesk.com/api/v2/tickets/update_many.json?' +\
    'ids=' + id_merged1_joined

url_put_comments2 = 'https://propertypro.zendesk.com/api/v2/tickets/update_many.json?' +\
    'ids=' + id_merged2_joined

user = 'some email'
pwd = 'some password'
headers = {'content-type': 'application/json'}

# Do the HTTP put request
response_request_noreply = requests.put(url_put_comments1, data=payload1,
                                        auth=(user, pwd), headers=headers)

response_request_obh = requests.put(url_put_comments2, data=payload2,
                                    auth=(user, pwd), headers=headers)

# Check for HTTP codes other than 200
if response_request_noreply.status_code != 200 | response_request_obh.status_code != 200:
    print('Status 1:', response_request_noreply.status_code +
          'Status 1:', response_request_obh.status_code,
          'Problem with the request. Exiting.')
    exit()

    # Report success
    print('Successfully added comment to tickets')

但是,在运行我的 python 代码并执行另一个 GET 方法后,相同的票号仍然出现,我需要随机等待才能获得我想要的结果,即返回“null”,因为我已经使用 PUT 方法更新了票证.

谁能解释一下 Zendesk API 是如何工作的?并对我在解释我的担忧时的错误句子表示歉意。

python api zendesk
1个回答
0
投票

Zendesk 数据库是分布式的,因此没有 ACID 属性。 如此处所述,Zendesk 支持索引新的和修改的票证可能需要几分钟的时间:Zendesk 支持搜索参考

有关此帮助中心文章的更多说明:Search API Delayed Results vs Users API

© www.soinside.com 2019 - 2024. All rights reserved.