Индекс результатов поиска API Zendesk - PullRequest
0 голосов
/ 01 октября 2019

Я пишу скрипт на языке Python для выполнения метода GET и PUT в API zendesk, успешно получаю нужные данные и обновляю заявки.

Метод ниже, в результате чего получен номер заявки "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.

Может кто-нибудь объяснить мне, как работает API Zendesk? и мои извинения за мои неправильные предложения в объяснении моей озабоченности.

...