python Zendesk API Python脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Zendesk API Python脚本相关的知识,希望对你有一定的参考价值。

import requests
import pprint

# Set the organization id
id = '{id}'

# Set the request parameters
url = 'https://{subdomain}.zendesk.com/api/v2/organizations/' + id + '/users.json'
user = '{email_address}'
pwd = '{password}'

output = []
output2 = []
output3 = []

while url:
    # Do the HTTP get request
    response = requests.get(url, auth=(user, pwd))
    # Check for HTTP codes other than 200
    if response.status_code != 200:
        print('Status:', response.status_code, 'Problem with the request. Exiting.')
        #exit()
    # Decode the JSON response into a dictionary and use the data
    data = response.json()
    for object in data['users']:
        temp = object['email'].split('@')
        if temp[1] == 'acme.com':
            output2.append(object['email'])
        else:
            output.append(object['email'])
    url = data['next_page']

for object in output2:
    temp = object.split('@')
    temp2 = []
    temp2.append(temp[0])
    temp2.append('@getacme.com')

    temp3 = ''.join(temp2)

    if temp3 in output:
        output3.append(object)

for object in output3:
    print object
import requests
import pprint
import json
import codecs

file = codecs.open('python.csv', 'r', "utf-8")
list = file.read().split('\r\n')

# Set the organization id
id = '{id}'

# Set the request parameters
url = 'https://{subdomain}.zendesk.com/api/v2/organizations/' + id + '/users.json'
user = '{email_address}'
pwd = '{password}'

output = []
output2 = []
output3 = []

while url:
    # Do the HTTP get request
    response = requests.get(url, auth=(user, pwd))
    # Check for HTTP codes other than 200
    if response.status_code != 200:
        print('Status:', response.status_code, 'Problem with the request. Exiting.')
        #exit()
    # Decode the JSON response into a dictionary and use the data
    data = response.json()
    for object in data['users']:
        temp = object['email'].split('@')
        if temp[1] == 'acme.com':
            continue
        if object['email'] not in list:
            #output.append(object['email'])
            continue
        email = temp[0] + '@acme.com'
        output2.append(email)
        update = { 'user': { 'email': email} }
        payload = json.dumps(update)
        headers = {'content-type': 'application/json'}
        response2 = requests.put(object['url'], data=payload, auth=(user, pwd), headers=headers)
        if response2.status_code != 200:
            print('Status:', response2.status_code, 'Problem with the request. Exiting.')
    url = data['next_page']

for object in output2:
    print object

以上是关于python Zendesk API Python脚本的主要内容,如果未能解决你的问题,请参考以下文章

Zendesk & Ionic - cordova-plugin-zendesk 不为 IOS 构建

如何设计用于文件上传的 XML Restful 服务接口?

远程服务器返回错误:(401)在Zendesk中未经授权

html Zendesk:格式化标签

html Zendesk:推荐文章的提醒通知

html Zendesk:推荐文章的提醒通知