Example clients

Perl and LWP

📘

Note:

In the test environment, Perl and LWP based requests may fail and return the error: 500 Can't connect to admin.test.hostedemail.com:443 (certificate verify failed) due to the test environment SSL certificate being invalid.

To bypass certificate checking, you can use the following line in your script:

$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;

The Perl script below lists a number of modules that need to be installed. In addition to these, and to make an HTTPS connection using LWP, please ensure you have the following module installed:

LWP::Protocol::https

!/usr/bin / perl
use strict;
use warnings;
use JSON;
use LWP::UserAgent;
use Data::Dumper;
my $api_url = 'https://admin.a.hostedemail.com/api';
my $method = 'get_user';
my $url = $api_url.$method;
my $credentials = {
    'user' => '[email protected]',
    'password' => 'sw0rdf1sh'
};
my $user = '[email protected]';
my % request_body = (
    'credentials' => $credentials,
    'user' => $user,
);
#encode request in JSON
my $json_request = encode_json(\ % request_body);
#send request to API
my $ua = LWP::UserAgent - > new;
my $request = HTTP::Request - > new(POST => $url);
$request - > content_type('application/json');
$request - > content($json_request);
my $response = $ua - > request($request);
if ($response - > is_success)# HTTP success 
{
    #convert response from JSON to a perl hash
    my $response_body = from_json($response - > content());
    print Dumper $response_body;
} 
else 
{
    print "Something went terribly wrong\n";
    print $response - > status_line, "\n";
}