Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active August 29, 2015 14:23
Show Gist options
  • Save chucknado/36deb8b7d11f14fc9125 to your computer and use it in GitHub Desktop.
Save chucknado/36deb8b7d11f14fc9125 to your computer and use it in GitHub Desktop.
A Perl script for the article "Changing the author of a Help Center article" at https://support.zendesk.com/hc/en-us/articles/205815128
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use MIME::Base64;
# Settings
my $article_id = your_article_id;
my $updated_author_id = your_user_id;
my $zendesk_subdomain = 'your_zendesk_subdomain';
my $email = 'your_user_email';
my $password = 'your_user_password';
# Structure and encode the data the way the API expects it
my %data = (article => {author_id => $updated_author_id});
my $data = encode_json(\%data);
# Make the request
my $url = "https://$zendesk_subdomain.zendesk.com/api/v2/help_center/articles/$article_id.json";
my $credentials = encode_base64("$email:$password");
my $ua = LWP::UserAgent->new(ssl_opts =>{ verify_hostname => 0 });
my $response = $ua->put($url,
'Content' => $data,
'Content-Type' => 'application/json',
'Authorization' => "Basic $credentials");
die 'http status: ' . $response->code . ' ' . $response->message
unless ($response->is_success);
print "Successfully updated article $article_id.\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment