Skip to content

Instantly share code, notes, and snippets.

View chucknado's full-sized avatar

Charles Nadeau chucknado

View GitHub Profile
@chucknado
chucknado / main.js
Last active August 14, 2021 11:01
Sample JavaScript for the Zendesk Apps tutorial, Accessing external data, at https://support.zendesk.com/hc/en-us/articles/222391587
$(function() {
var client = ZAFClient.init();
client.invoke('resize', { width: '100%', height: '400px' });
showStart();
$("#get-tasks").click(function() {
getTaskData(client);
});
});
function showStart() {
@chucknado
chucknado / app.py
Last active May 27, 2021 13:37
A Python script for "Zendesk API tutorial: Building a custom ticket form" at https://support.zendesk.com/hc/en-us/articles/209003547
import json
import requests
from bottle import route, template, run, static_file, request, response
@route('/create_ticket', method=['GET', 'POST'])
def handle_form():
if 'verified_email' in request.cookies:
ask_email = False
@chucknado
chucknado / write_posts.py
Last active November 23, 2020 07:41
Sample script for "Write large data sets in Excel with Python and pandas" at https://support.zendesk.com/hc/en-us/articles/212227138
import dateutil.parser
import pandas as pd
topic = pd.read_pickle('my_serialized_data')
posts_df = pd.DataFrame(topic['posts'], columns=['id', 'title', 'created_at', 'author_id'])
users_df = pd.DataFrame(topic['users'], columns=['id', 'name']).drop_duplicates(subset=['id'])
posts_df['created_at'] = posts_df['created_at'].apply(lambda x: dateutil.parser.parse(x).date())
@chucknado
chucknado / search.py
Last active October 20, 2020 14:52
A Python script for the article "Zendesk REST API tutorial: Searching" at https://support.zendesk.com/hc/en-us/articles/203691406
from urllib.parse import urlencode
import requests
credentials = 'your_zendesk_email', 'your_zendesk_password'
session = requests.Session()
session.auth = credentials
params = {
'query': 'type:ticket status:open',
@chucknado
chucknado / post_articles.py
Last active March 11, 2020 23:26
Uploads a collection of HTML files to Help Center
from pathlib import Path
from bs4 import BeautifulSoup
import requests
"""
1. Place the HTML files in a folder named 'html_files' in the same folder as this file.
2. Change the settings starting on line 14 to values that are valid for your account.
3. In your command line interface, navigate to the folder containing this file and run `python3 post_articles.py`.
4. In Guide, set the correct sections, authors, and access permissions for the articles.
@chucknado
chucknado / category_with_sections
Created December 12, 2019 18:13
Show the subsections of each section from the category page
<div class="container-divider"></div>
<div class="container">
<nav class="sub-nav">
{{breadcrumbs}}
{{search submit=false}}
</nav>
<div class="category-container">
<div class="category-content">
<header class="page-header">
@chucknado
chucknado / make_backup.py
Last active December 9, 2019 11:32
A Python script for the REST API tutorial, "Backing up your knowledge base," at https://help.zendesk.com/hc/en-us/articles/229136947
import os
import datetime
import csv
import requests
credentials = 'your_zendesk_email', 'your_zendesk_password'
zendesk = 'https://your_subdomain.zendesk.com'
language = 'some_locale'
@chucknado
chucknado / search.pl
Last active April 30, 2019 19:45
A Perl script for the article "Zendesk REST API tutorial: Searching" at https://support.zendesk.com/hc/en-us/articles/203691406
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use MIME::Base64;
use URI::Escape;
my $credentials = encode_base64('your_email_address:your_password');
my %params = (
@chucknado
chucknado / sunshine.py
Last active April 10, 2019 22:35
Python module for Sunshine profiles in "Getting started with Sunshine profiles" article
import requests
credentials = 'your_zendesk_email', 'your_zendesk_password'
zendesk = 'https://your_subdomain.zendesk.com'
def post_profile(profile):
data = {'profile': profile}
url = f'{zendesk}/api/sunshine/profile'
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
response = requests.post(url, json=data, auth=credentials, headers=headers)
@chucknado
chucknado / sunshine.py
Last active April 10, 2019 19:19
Python module for Sunshine events in "Getting started with Sunshine user events" article
import requests
credentials = 'your_zendesk_email', 'your_zendesk_password'
zendesk = 'https://your_subdomain.zendesk.com'
def track_event(payload):
url = f'{zendesk}/api/sunshine/events'
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
response = requests.post(url, json=payload, auth=credentials, headers=headers)