Skip to content

Instantly share code, notes, and snippets.

View tstachl's full-sized avatar

Thomas Stachl tstachl

  • Pilina
  • Remote
View GitHub Profile
@tstachl
tstachl / mycases.js
Created November 12, 2014 00:24
Load all cases without pagination on the My Cases page in the desk.com portal by adding this snippet of jquery code. It basically loads the next page of each page that has a next page specified and appends all the cases to the initial page.
(function($) {
function nextPage(url, callback) {
$.get(url, function(data, textStatus, jqXHR) {
var cases = $(data).find('.mycases tbody tr')
, nextUrl = $(data).find('#pagination a.next_page');
callback(cases);
if (nextUrl && nextUrl.attr('href')) nextPage(nextUrl.attr('href'), callback);
}, 'html');
# configure the client
client = DeskApi::Client.new username: 'support@example.com', password: '$uper$ecretP@ssword', endpoint: 'https://example.desk.com'
# create the customer using a plain request
resp = client.post('/api/v2/customers', {
first_name: 'John',
last_name: 'Doe',
emails: [{ type: 'home', value: 'jdoe@example.net' }]
})
@tstachl
tstachl / multipass.pl
Created November 18, 2014 19:43
A desk.com multipass example written in perl.
#!/usr/bin/perl -w
use Digest::SHA qw( sha1 hmac_sha1 );
use Crypt::Random qw( makerandom_octet );
use DateTime;
use JSON;
use Crypt::CBC;
use Digest::HMAC;
use URL::Encode qw( url_encode_utf8 );
use MIME::Base64::Perl;
@tstachl
tstachl / download_attachment.sh
Created November 24, 2014 18:31
Download attachment from desk.com using curl.
curl -L https://example.desk.com/api/v2/cases/3061/attachments/82558857/url -u agent@example.com:password > my_image.jpg
@tstachl
tstachl / create_case_and_reply.php
Created January 15, 2015 00:00
A quick php script that shows how to create a case and then a reply.
<?php
function post($path, $json) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://site.desk.com$path");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERPWD, "my-email:my-password");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
<?php
$date = new DateTime('2015-01-21T20:34:53Z');
$date->setTimezone(new DateTimeZone('Pacific/Chatham'));
echo $date->format(DateTime::ISO8601);
<div class='input-block'>
<span class='label'>
CUSTOM FIELD LABEL <span>({{system.snippets.required}})</span>
</span>
<div>
{{ ticket_custom_**CUSTOM FIELD KEY** }}
</div>
</div>
{
"type": "email",
"subject": "Email Case Subject",
"priority": 4,
"status": "open",
"labels": [
"Spam",
"Ignore"
],
"message": {
{% if case.group.name == 'Support' %}
<!-- put the case theme for support here -->
{% elsif case.group.name == 'Internal' %}
<!-- put the case theme for internal here -->
{% else %}
<!-- put the case theme for default here -->
{% endif %}
<h2>{{email.subject}}</h2>
{% if email.subject contains 'Suggestion' %}
<h3>This is a suggestion</h3>
{% else %}
<h3>This is default</h3>
{% endif %}