Perl: Get Letter Metadata with GetLetterDetails()

Instructions

  1. Make sure your Perl environment is ready and create a new script.
  2. Copy the entire code below and paste the code in the Perl script.
  3. Replace MyUsername and MyPassword with your PostalMethods user details
  4. Replace ID with the LetterID for which you would like to get the status
  5. Run your script. If the response is -3000, you will see the details report. If the response is any other number, check the Web Service Status Codes section.
#!/usr/bin/perl
use strict;
use warnings;
use SOAP::Lite;
use MIME::Base64;
 
my $MyUsername = 'MyUsername';
my $MyPassword = 'MyPassword';
# Letter ID, provided as a response by the letter sending functions
my $MyResponseID = 'MyResponseID';
# -3000 means successfully received Web Service request
# for details, check http://www.postalmethods.com/statuscodes#webservice
my $ResultCodeOk = -3000;
 
 
my $soap = SOAP::Lite
    -> uri('PostalMethods')
    -> on_action( sub { join '/', 'PostalMethods', $_[1] } )
    -> proxy('https://api.postalmethods.com/PostalWS.asmx');
 
 
my $GetLetterDetailsResult =  $soap->GetLetterDetails( 
				SOAP::Data->new(name => 'Username', value => $MyUsername)->uri('PostalMethods'),
				SOAP::Data->new(name => 'Password', value => $MyPassword)->uri('PostalMethods'),
			        SOAP::Data->new(name => 'ID', value => $MyResponseID)->uri('PostalMethods')
				)->result;
 
 
if($GetLetterDetailsResult->{'ResultCode'}  == $ResultCodeOk){
    print "Message submitted successfully for the transaction " . $MyResponseID . "\n";
    print "ID: " . $GetLetterDetailsResult->{'ID'} . "\n";
    print "Price: " . $GetLetterDetailsResult->{'Price'} . "\n";
    print "NumOfSheets: " . $GetLetterDetailsResult->{'NumOfSheets'} . "\n";
    print "SubmitTime: " . $GetLetterDetailsResult->{'SubmitTime'} . "\n";
    print "CompletionTime: " . $GetLetterDetailsResult->{'CompletionTime'} . "\n";
    print "Orientation: " . $GetLetterDetailsResult->{'Orientation'} . "\n";
    print "Envelope: " . $GetLetterDetailsResult->{'Envelope'} . "\n";
    print "Paper: " . $GetLetterDetailsResult->{'Paper'} . "\n";
    print "PrintColor: " . $GetLetterDetailsResult->{'PrintColor'} . "\n";
    print "PrintSides: " . $GetLetterDetailsResult->{'PrintSides'} . "\n";
    print "NationalMailting: " . $GetLetterDetailsResult->{'NationalMailing'} . "\n";
    print "InternationalMailing: " . $GetLetterDetailsResult->{'InternationalMailing'} . "\n";
}
else{
    print "Message submission failed on error " . $GetLetterDetailsResult->{'ResultCode'} . "\n";
}
 
exit 1;