최근 검색


최근 검색 없음

Ruth Kusterer's Avatar

Ruth Kusterer

가입한 날짜: 2023년 4월 12일

·

마지막 활동: 2023년 4월 12일

팔로잉

0

팔로워

0

총 활동 수

2

투표 수

0

가입 플랜

1

활동 개요

님의 최근 활동 Ruth Kusterer

Ruth Kusterer님이 에 댓글을 입력함

커뮤니티 댓글 Q&A - Help center and community

This script loops over Zendesk Guide articles and prints article ID and its attachment names. If you want it to do something smarter than print, then look up other options here: Article Attachments API. Hope it works for you.

## Loop over list of Zendesk Guide articles and then loop over their attachments
import os
import requests

## Zendesk API endpoint connection
credentials = 'YOURUSERNAME', 'YOURPW' # delete pw afterwards
zendesk_baseurl = 'https://blazemeterhelp.zendesk.com'
language = 'en-US' # "en-US" in our case
out_file='attachment_log.txt'
print("I will list all attachments in this output file: "+out_file)
## Use credentials to access Zendesk Articles endpoint. 
endpoint = zendesk_baseurl + '/api/v2/help_center/{locale}/articles.json'.format(locale=language.lower())
print("Connecting to "+endpoint)
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()
    ## response contains articles and info about pagination, loop over it:
    article_data = response.json()
    ## For each article...
    for article in article_data['articles']:
        articleID=article['id']
      ## Skip empty files and ...
        if article['body'] is None:
            continue
        ##... print article ID and ...
        print('Found article with ID {id}.'.format(id=articleID))
## ... loop over attachments and ...
        attachment_request=zendesk_baseurl + '/api/v2/help_center/articles/{article_id}/attachments.json'.format(article_id=articleID)
        attachment_response = requests.get(attachment_request, auth=credentials)
        if attachment_response.status_code != 200:
            print('Failed to check article for attachments with error {}'.format(attachment_response.status_code))
            exit()
        attachment_data = attachment_response.json()
      for att in attachment_data['article_attachments']:
      ## ... print all its attachment names
            print("    "+str(att['file_name']))
          ## Also keep a log of all IDs and attachment names in a file
            with open(os.path.join(out_file), mode='a', encoding='utf-8') as f:
                f.write(str(articleID)+"\t "+str(att['file_name']))
                f.write("\n")
    ## Next loop
    ## Toggle these two to do either a short debug run or loop over all articles:
    #endpoint = [] # EITHER loop over only 30 articles
  endpoint = article_data['next_page'] # OR loop over all articles

 

댓글 보기 · 2023년 4월 12일에 게시됨 · Ruth Kusterer

0

팔로워

0

투표 수

0

댓글