Last active
April 30, 2019 19:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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