Perl: Get Letter Metadata with GetLetterDetailsV2()

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.
    • Replace MyUsername and MyPassword with your PostalMethods user details.
    • Replace MyResponseID with the LetterID for which you would like to get the metadata.
  3. Run your script. If the response is -3000, you will see the status 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 $result =  $soap->GetLetterDetailsV2( 
				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')
				);
 
unless ($result->fault) {
	my $GetLetterDetailsResult = $result->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";
	    print "WorkMode: " . $GetLetterDetailsResult->{'WorkMode'} . "\n";
	} else {
	    print "Message submission failed on error " . $GetLetterDetailsResult->{'ResultCode'} . "\n";
	}
} else {
	print join ', ', 
	$result->faultcode, 
	$result->faultstring, 
	$result->faultdetail;
}
 
exit 1;
<br />
<br />