Last active
August 12, 2016 17:50
-
-
Save chucknado/b26c42e8ad22b908af9c to your computer and use it in GitHub Desktop.
A Python script for "Zendesk API tutorial: Listing the followers of a KB section" at https://support.zendesk.com/hc/en-us/articles/206340488
This file contains hidden or 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 argparse | |
| import requests | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("id") | |
| args = parser.parse_args() | |
| hc_id = args.id | |
| session = requests.Session() | |
| session.headers = {'Content-Type': 'application/json'} | |
| session.auth = ('your_zd_email/token', 'your_api_token') | |
| zendesk = 'https://your_subdomain.zendesk.com' | |
| endpoint = '/api/v2/help_center/sections/{}/subscriptions.json?include=users' | |
| url = zendesk + endpoint.format(hc_id) | |
| users = [] | |
| while url: | |
| response = session.get(url) | |
| if response.status_code != 200: | |
| print('Failed to get followers with error {}'.format(response.status_code)) | |
| exit() | |
| data = response.json() | |
| if data['subscriptions']: | |
| users.extend(data['users']) | |
| url = data['next_page'] | |
| for user in users: | |
| print(user['name']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment