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 / do_if_logged_in.js
Created November 4, 2013 17:30
Wrapper to execute code only for logged in users.
onlyLoggedIn = $.get("/api/v2/users/me.json", function(data){
in_or_out = data.user.id; //this variable contains the data for current user's UID
current_path = window.location.pathname;
})
onlyLoggedIn.done(function() {
if(!in_or_out && current_path != 'access/normal'){ //this is what checks to see if UID is null. If it is null, then executes the code below
windlow.location = "https://support.shareholderinsite.com/access/normal";
}
})
onlyLoggedIn.fail(function(){
@dpawluk
dpawluk / content_font_replace_zd
Created January 9, 2014 22:21
Here we say, if the {{content}} placeholder contains "font-family:'Lucida Sans Unicode','Lucida Grande','Tahoma',Verdana,sans-serif;", then go ahead with these replacements, otherwise, just display the default content. Because the above font stack is used for the paragraph elements of comments, this will apply to only those elements.
{% if content contains "font-family:'Lucida Sans Unicode','Lucida Grande','Tahoma',Verdana,sans-serif;" %}
{{content | replace: "font-family:'Lucida Sans Unicode','Lucida Grande','Tahoma',Verdana,sans-serif;", "font-family: Georgia, Times, "Times New Roman", serif;" | replace: "font-size:14px;", "font-size:12px;" | replace: "color:#2b2e2f;", "color:#6b6d6e;"}}
{% else %}
{{content}}
{% endif %}
@dpawluk
dpawluk / pyrequestZD.py
Created January 15, 2014 19:57
Regular REST api example using python
import requests
payload = '{"ticket":{"requester":{"name":"Dan Pawluk", "email":"daniel.pawluk@me.com"}, "subject":"My printer is on fire!", "comment": { "body": "I want thousands of tickets" }}}'
s = requests.Session()
s.headers.update({'Content-Type': 'application/json'})
s.auth = ('{username}','{password}')
#r = s.post("http://requestb.in/1hjs6jw1", data=payload)
for x in range (0,11999):
try:
r = s.post("https://sandedboxy.zendesk.com/api/v2/imports/tickets.json", data=payload)
print("finished with request number:" + str(x))
import thread
import threading
import requests
s = requests.Session()
s.headers.update({'Content-Type': 'application/json'})
s.auth = ('{username/token}','{password/token}')
#r = s.post("http://requestb.in/1hjs6jw1", data=payload)
ticketCount = 2000
{{content | replace: "<p></p>","<br />"}}
or even
{{content | replace: "<p></p>"," "}}
@dpawluk
dpawluk / HTTPWebRequestZD
Created January 29, 2014 17:34
Simple C# script using native HTTP Request handler (HttpWebRequest) to access /api/v2/tickets/{{ticket.id}}.json enpoint.
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Collections.Specialized;
namespace test2
{
class MainClass
{
@dpawluk
dpawluk / humble_squid_cat_images.js
Created February 28, 2014 21:59
Simple script that can be added to a Help Center using the Humble Squid Theme. Will give category boxes a background images specified in the array of links to substitute.
//Begin Humble Squid Category Image Boxes JS Snippet
cat_list = $("ul.category-list li"); // jQuery object containing the category list elements
link_list = $("ul.category-list li a"); // jQuery object containing the category list link elements
// hardcoded array of image assets for use with categories
image_links = [
"//p1.zdassets.com/hc/theme_assets/link/to/images/for/categories.jpg",//replace with actual image links from your Help Center's assets
"//p1.zdassets.com/hc/theme_assets/link/to/images/for/categories.jpg",
"//p1.zdassets.com/hc/theme_assets/link/to/images/for/categories.jpg",
"//p1.zdassets.com/hc/theme_assets/link/to/images/for/categories.jpg",
@dpawluk
dpawluk / requesting.js
Created March 13, 2014 22:30
JSON.stringify() is important. Sending a JSON object will result in automatic conversion to form/url-encoded key-value pairs.
requests: {
var json_data = {
"ticket": {
"subject": "Hello",
"comment": {
"body": "Some question"
},
"ticket_form_id": this.carrierOpsFormId,
"custom_fields": [{
"id": 23810968,
@dpawluk
dpawluk / getUserByEmail.php
Created March 20, 2014 23:27
Function that uses curlWrap to take an email input and returns a user's id.
<?php
require_once('curlwrap.php');
function getUserIdByEmail($email) {
$query = curlWrap('/search.json?query=type:user%20email:' . $email ,'',GET);
$results_array = $query->results;
$results_length = count($results_array);
if($results_length == 1){
echo "we found a single match, good stuff!\n User ID: ";
return $results_array[0]->id;
@dpawluk
dpawluk / delete_many.py
Created April 8, 2014 22:32
a script to delete many tickets based on ticket id range
import requests
s = requests.Session()
s.headers.update({'Content-Type': 'application/json'})
s.auth = ('ADMINEMAIL/token','APITOKEN')
y = 1500 #starting ticketid
#declare last ticketid here
while (y < 24167):