Last active
August 29, 2015 14:25
-
-
Save chucknado/283b4b992d6d2adb36e3 to your computer and use it in GitHub Desktop.
A Perl script for "Zendesk API tutorial: Listing the followers of a KB section" at https://support.zendesk.com/hc/en-us/articles/206340488
This file contains hidden or 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; | |
my $num_args = $#ARGV + 1; | |
if ($num_args != 1) { | |
print "Usage error: list_followers.pl hc_id\n"; | |
exit; | |
} | |
my $zendesk = 'https://your_subdomain.zendesk.com'; | |
my $endpoint = "/api/v2/help_center/sections/$ARGV[0]/subscriptions.json?include=users"; | |
my $url = $zendesk . $endpoint; | |
my $credentials = encode_base64('your_zd_email/token:your_api_token'); | |
my $ua = LWP::UserAgent->new(ssl_opts =>{ verify_hostname => 0 }); | |
my @users; | |
while ($url) { | |
my $response = $ua->get($url, 'Authorization' => "Basic $credentials"); | |
die 'http status: ' . $response->code . ' ' . $response->message | |
unless ($response->is_success); | |
my $data = decode_json($response->content); | |
push @users, @{ $data->{'users'} }; | |
if (defined $data->{'next_page'}) { | |
$url = $data->{'next_page'}; | |
} else { | |
$url = ''; | |
} | |
} | |
foreach my $user ( @users ) { | |
print $user->{"name"} . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment