Last active
May 15, 2018 12:23
-
-
Save 1951FDG/526db345843401da769af42476ab53b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment