Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active April 30, 2019 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chucknado/f62e18f4047fef26d0f7 to your computer and use it in GitHub Desktop.
Save chucknado/f62e18f4047fef26d0f7 to your computer and use it in GitHub Desktop.
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 = (
query => 'type:ticket status:open',
sort_by => 'created_at',
sort_order => 'asc'
);
my $url = URI->new('https://your_subdomain.zendesk.com/api/v2/search.json');
$url->query_form(%params);
my $ua = LWP::UserAgent->new(ssl_opts =>{ verify_hostname => 0 });
my $response = $ua->get($url, 'Authorization' => "Basic $credentials");
die 'Status: ' . $response->code . ' ' . $response->message
unless ($response->is_success);
# Print the subject of each ticket in the results
my $data = decode_json($response->content);
my @results = @{ $data->{'results'} };
foreach my $result ( @results ) {
print $result->{"subject"} . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment