Zendeskの記事をエクスポートする
2023-02時点では公式が提供する手段はないのでZendesk APIをスクリプトでコールするしかない
(公式)ヘルプセンターのコンテンツをエクスポートするにはどうすればよいですか?
Zendesk Guide の記事を一括でバックアップしてみた にあるPythonスクリプトがほぼそのまま使える
access tokenを使ったリクエストの方法
カテゴリ単位での指定
上記の記事を一部改変した例
HTMLでなくテキストで出力するためにhtml2textを加えた
インデックスファイルは不要
日時とロケールのディレクトリは不要
code:python
import csv
import datetime
import os
import html2text
import requests
credentials = '{YOUR_EMAIL}/token', '{YOUR_ACCESS_TOKEN}'
zendesk = 'https://{YOUR_ORG}.zendesk.com'
language = '{YOUR_LOCALE}'
backup_path = os.path.join('./backup')
if not os.path.exists(backup_path):
os.makedirs(backup_path)
log = []
endpoint = zendesk + '/api/v2/help_center/{YOUR_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}.txt'.format(id=article'id')
with open(os.path.join(backup_path, filename), mode='w', encoding='utf-8') as f:
text = html2text.html2text(title + '\n' + article'body')
f.write(text)
print('{id} copied!'.format(id=article'id'))
log.append((filename, article'title', article'author_id'))
endpoint = data'next_page'