python - Zendesk API 搜索结果索引
问题描述
我编写了一个 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 = 'mart.polman@lamudi.co.id'
pwd = 'lamudionfire'
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 是如何工作的?并为我在解释我的担忧时不正确的句子道歉。
解决方案
推荐阅读
- vba - 为什么 CurrentDB 可以在一台计算机上工作,但不能在另一台计算机上工作
- c# - 将另一列的两列datagridview单元格值相乘,然后将所有行的值相加
- database - dbms中多级索引和二级索引的区别
- r - 地图中缺少标记/点
- r - 从图例中删除特定标记
- typescript - 有没有像 JQAssistant 这样的 Typescript 工具
- python - 如何在 django 中将图像添加到数据库中而不在选择的按钮中显示图像的路径
- javascript - 带有没有子路由Angular的链接的面包屑
- node.js - 如何将 favicon 添加到 mern 应用程序?
- javascript - 根据 SVG 的单击路径动态创建 html 的正确方法是什么?如何在页面上隐藏/显示所述 html?