Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import pandas as pd
from pandas.io.json import json_normalize
import requests
from configparser import ConfigParser
dir_path = '.'
config = ConfigParser()
config_file = dir_path+'/config.ini'
config.read(config_file)
api_key=config['zendesk']['api_key']
email = config['zendesk']['email']
subdomain = config['zendesk']['subdomain']
user = 'USEREMAIL' + '/token'
pwd = api_key
def get_voice_comments(ticket_ids):
all_voice_comment_dfs = []
total_tickets = len(ticket_ids)
for i, ticket_id in enumerate(ticket_ids):
event_dfs = []
url = f'https://YOUR-ZENDESK-DOMAIN.com/api/v2/tickets/{ticket_id}/audits.json'
response = requests.get(url, auth=(user, pwd))
response_json = response.json()
event_dfs = []
for audit in response_json['audits']:
try:
audit_events_df = json_normalize(audit['events'],sep='_')
event_dfs.append(audit_events_df)
except Exception as ex:
print(ex)
continue
all_audit_events_df = pd.concat(event_dfs,ignore_index=True, sort=False)
voice_comment_df = all_audit_events_df[all_audit_events_df['type'].str.lower().str.contains('voice')]
if i % 100 == 0 and i != 0:
print(i / total_tickets * 100.0, "% of tickets completed")
print(len(all_voice_comment_dfs), ' dfs extracted with voice comments')
if voice_comment_df.empty == False:
voice_comment_df['ticket_id'] = ticket_id
all_voice_comment_dfs.append(voice_comment_df)
else:
continue
voice_comment_df = pd.concat(all_voice_comment_dfs, ignore_index=True, sort=False)
#voice_comment_df.to_csv('./voice_comments.csv',index=False)
return voice_comment_df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.