Skip to content

Instantly share code, notes, and snippets.

View dpawluk's full-sized avatar

Daniel Pawluk dpawluk

  • Zendesk
  • Wisconsin
View GitHub Profile
@dpawluk
dpawluk / get_tickets_sideloading.py
Created June 8, 2016 15:36
How to get tickets and include sideloads using Python Requests
import requests
import json
SUBDOMAIN = 'myzendesksubdomain'
s = requests.Session()
s.headers.update({"content-type":"application/json"})
s.auth = ('username@domain/token','VERYSECTRETAPIKEY')
def getTicket(ticket_id, sideloads=[]):
url = "https://{}.zendesk.com/api/v2/tickets/{}.json".format(SUBDOMAIN, ticket_id)
@dpawluk
dpawluk / app.js
Created June 7, 2016 21:49
Very basic usage of node.js and Requests package to create_many tickets in zendesk
var request = require('request');
var util = require('util');
var config = {
'username': '[email protected]/token', // email if using password, email/token if token
'token':'AVERYSECRETAPIKEY', // password or token, see above
'subdomain': 'my_subdomain' // replace with Zendesk subdomain
};
function printDone(error, response, body) { // Wrote this to be callback for testing requests
@dpawluk
dpawluk / app.js
Created June 6, 2016 13:28
Using a modal in handling a save hook event
(function() {
return {
events: {
'app.activated':'init',
'ticket.save':'popModal',
'click #save_ticket': 'onModalSave',
'click #fail_ticket': 'onModalCancel'
},
@dpawluk
dpawluk / app.gs
Created April 7, 2016 21:49
Google Apps Script Refactor of Sheets Code... Baby steps
var app = {
sheet: {
get_row_by_id: function(post_id) {
var sheet = SpreadsheetApp.getActiveSheet();
var last_row = sheet.getLastRow();
var columns = sheet.getLastColumn();
var post_id_column = this.get_column_by_name("Post ID");
var post_id_range = sheet.getRange(2,post_id_column,last_row,1).getValues();
var post_id_list = _.flatten(post_id_range, true);
var row_found = (post_id_list.indexOf(post_id)+2); // header + index zero
@dpawluk
dpawluk / make_many_posts.py
Created April 7, 2016 21:39
Example script and source data for creating multiple posts from a list/array of posts
import json
import requests
import pprint
# Think about storing these outside the script as a best practice.
# Look into YAML (One standard method of serializing data, like JSON in ways)
# you could store this config object in a YAML file outside the script and just load it in similar to
# how you are loading in your JSON file. This tends to be more secure (sharing scripts is easier,
# you don't have to worry about accidentally publishing secret tokens or private info by accident)
@dpawluk
dpawluk / make_post.py
Created April 7, 2016 18:27
Fully test example Python for creating posts using Help Center API
import json
import requests
import pprint
# Remember to edit the example json file and replace the placeholder topic_id with the appropriate topic_id
with open('test_post.json', 'r', encoding='utf-8') as data_file: #going to change this up a bit to help explain differences
payload_as_object = json.loads(data_file.read()) # Read the string in the file, json.loads() takes json string and converts to a Python object
payload_as_string = json.dumps(payload_as_object) # Here we have changed the object back into a json string, this is what the API expects to recieve
@dpawluk
dpawluk / generic_request.js
Created April 5, 2016 14:33
Generic request in app
(function() {
return {
requests: {
generic_request: function(url, action) {
return {
url: url,
type: action,
contentType: "application/json"
@dpawluk
dpawluk / upload_file.rb
Created March 29, 2016 00:04
Using RestClient to create an ActiveResource Style experience for making http requests
# Require our http client
require 'rest_client'
# Create the 'resource', use basic auth
client = RestClient::Resource.new("https://#{zensubdomain}.zendesk.com","#{zenadminemail}/token","#{zenapitoken}")
# Point to the appropriate nested resource
# We are uploading a file so we tell ruby to read some bytes
# Set the content-type header and provide the required querystring parameter for this endpoint (filename)
response = client['/api/v2/uploads.json'].post File.new("/Path/to/file/upload_example.gif", "rb"), :content_type => 'application/binary', :params => {:filename => "upload_example.gif"}
@dpawluk
dpawluk / get_all_resources.js
Last active March 15, 2016 19:16
Something to get all resource using javascript. Not pretty but working.
/*
* jQuery v1.9.1 included
*/
function get_all_users(total_pages){
var deferreds = []; // An array to store all our requests
for(x=0;x<total_pages;x++) {
var url = "/api/v2/users?pages=" + (x+1);
deferreds.push($.ajax({url: url}));
}
@dpawluk
dpawluk / whyyyy
Created March 8, 2016 20:30
redactions
makeTextRedaction: function() {
this.$('.text_redact').modal('hide');
var self = this;
var user_string = this.$('.redaction_string')[0].value;
var comment_data = this.comments;
var matched_comments = _.chain(comment_data)
.filter(function(comment) { // Creates a new object only including comments that contain the user's desired string
var body_text = comment.body;
return body_text.indexOf(user_string) > -1;
})