I'm attempting to back up the articles and access the columns (section, creation date, etc). I used this script as the jumping off point and everything seems to function. Unfortunately I get a 404 back every single time. Can someone more experienced with Python/API please help me troubleshoot this:
import os
import datetime
import csv
import requests
# selet the brand
product = 'collisionlinkinsurance'
# Set the request parameters
credentials = 'keena.tomko@oeconnection.com', 'Password'
zendesk = 'https://{product}.zendesk.com'.format(product=product)
print(zendesk)
language = 'en_us'
date = datetime.date.today()
backup_path = os.path.join(str(date),product, language)
if not os.path.exists(backup_path):
os.makedirs(backup_path)
print(backup_path)
log = []
endpoint = zendesk + '/api/v2/help_center/{locale}/articles.json'.format(locale=language.lower())
while endpoint:
response = requests.get(endpoint, auth=credentials)
if response.status_code != 200:
print('Failed to retrieve articles with error {}'.format(response.status_code))
exit()
data = response.json()
for article in data['articles']:
if article['body'] is None:
continue
title = '<h1>' + article['title'] + '</h1>'
filename = '{id}.html'.format(id=article['id'])
with open(os.path.join(backup_path, filename), mode='w', encoding='utf-8') as f:
f.write(title + '\n' + article['body'])
print('{id} copied!'.format(id=article['id']))
log.append((filename, article['title'], article['author_id']))
endpoint = data['next_page']
with open(os.path.join(backup_path, '_log.csv'), mode='wt', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerow( ('File', 'Title', 'Author ID') )
for article in log:
writer.writerow(article)
Hey Keena,
It looks like you have a ticket related to this issue open with our Customer Care team. One of our agents will follow-up with you to troubleshoot further.
Thanks for bringing this to our attention!