Recent searches
No recent searches
404 error during attempted export of KB articles
Posted Sep 20, 2023
Hi. I'm trying to export our KB articles using this ZD documentation: https://developer.zendesk.com/documentation/help_center/help-center-api/backing-up-your-knowledge-base-with-the-help-center-api/
Because we use SSO and 2FA to log into ZD, I changed the authentication method in the script from credentials to API key. I believe I formatted the script correctly, but I'm getting an unexplained 404. Any thoughts about what might be going wrong?
Here's my modified version of the Python script provided in the documentation:
import os
import datetime
import requests
api_token = 'MY_ZENDESK_TOKEN'
zendesk = 'https://securityscorecard.zendesk.com'
language = 'en_US'
date = datetime.date.today()
backup_path = os.path.join(str(date), language)
if not os.path.exists(backup_path):
os.makedirs(backup_path)
headers = {
'Authorization': f'Bearer {api_token}',
}
endpoint = zendesk + '/api/v2/help_center/en-US/articles.json'.format(locale=language.lower())
response = requests.get(endpoint, headers=headers)
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']:
print(article['id'])
0
5
5 comments
Nathan van Jole
The locale needs to be in lowercase. In this line:
You hardcoded the "en-US" which should be replaced with "{locale}". Also make sure to set the language variable to "en-US" instead "en_US" (with underscore).
Hope this helps!
0
Charles Nadeau
Also, an API token in Zendesk is different than an OAuth token. So the following header won't work:
An API token should be used as follows in a Python request (see API token in the docs for details):
In the API request, add the `credentials` variable to the `auth` parameter:
0
Mark Glinski
Thank you for the suggestions Nathan van Jole and Charles Nadeau!
So, now I'm no longer getting a 404. Now I'm getting different output after running the script:
First, there's a list of 30 article IDs from our KB.
Then there's a message:
Failed to retrieve articles with error 200: (which is weird because 200 is typically a "success" message)
...which is followed by a massive blob of text. I analyzed the text and it includes all the IDs in that list of 30.
Then, for each article ID, it shows some words from the article and some metadata.
And the backup folder that gets created by the script is empty.
Has anyone experienced this?
0
Mark Glinski
Also, Charles Nadeau, regarding your comment about using an OAuth header ^^ should I replace that header or just get rid of it?
Your comment for reference:
Also, an API token in Zendesk is different than an OAuth token. So the following header won't work:
0
Charles Nadeau
Yes, you should delete the header.
0