#!/usr/bin/perl use strict; use warnings; # 2018-0425: Test script to access the Freshdesk API. ... use LWP::UserAgent; use JSON; use Data::Dumper; use utf8; # Path to authentication module ... { my $ua = LWP::UserAgent->new; my $headers = $ua->default_headers; $ua->default_header( 'Accept', 'application/json' ); $ua->default_header( 'Accept-Charset', 'UTF-8' ); $headers->authorization_basic( $Auth::User, $Auth::Password ); binmode STDOUT, ":utf8"; foreach my $arg (@ARGV) { # 2018-0426: If it's a query, then that stuff has to be within # double quotes. The command line processing throws them out. if ( $arg =~ /^(.+query=)(.+)/ ) { $arg = join ( '', $1, '"', $2, '"' ); } my $this_url = join ( '', $Auth::Url, $arg ); print "GET $this_url ..\n"; my $response = $ua->get($this_url); if ( $response->is_success ) { my $result = decode_json( $response->content ); print Dumper ($result); if ( exists ( $result->{'description_text'} ) ) { my $as_is = $result->{'description_text'}; print "Text as-is: $as_is.\n"; } } else { print "Ugh, not a good response.\n"; print "Response:\n" . " " . $response->status_line . "\n" . " " . $response->message . "\n" . " " . $response->content . "\n"; } } }