Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active February 9, 2017 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chucknado/8473cfbad848425e075ee4c0bfd66af4 to your computer and use it in GitHub Desktop.
Save chucknado/8473cfbad848425e075ee4c0bfd66af4 to your computer and use it in GitHub Desktop.
Update a property of all the articles in a Zendesk Help Center section
import requests
credentials = 'your_zendesk_email', 'your_zendesk_password'
zendesk = 'https://your_subdomain.zendesk.com'
language = 'some_locale'
section_id = 123456
# Configure the list section articles endpoint
endpoint = zendesk + '/api/v2/help_center/{}/sections/{}/articles.json'.format(language, section_id)
while endpoint: # keep going until the value is False
response = requests.get(endpoint, auth=credentials) # get a page of articles
if response.status_code == 200:
data = response.json()
else:
print('Failed to retrieve articles with error {}'.format(response.status_code))
exit()
for article in data['articles']:
if article['comments_disabled']: # if comments are already disabled, skip to the next article in the list
continue
update = {'article': {'comments_disabled': True}}
url = zendesk + '/api/v2/help_center/{}/articles/{}.json'.format(language, article['id'])
response = requests.put(url, json=update, auth=credentials) # make the put request
if response.status_code == 200:
print('Comments disabled for article {}'.format(article['id']))
else:
print('{}: Error {}, {}'.format(article['id'], response.status_code, response.reason))
endpoint = data['next_page']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment