Instructions
- Make sure your Perl environment is ready and create a new script.
- 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 status.
- 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->GetLetterStatusV2(
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 $GetLetterStatusResult = $result->result;
if($GetLetterStatusResult->{'ResultCode'} == $ResultCodeOk){
print "Message submitted successfully for the transaction " . $MyResponseID . "\n";
print "LetterStatus: " . $GetLetterStatusResult->{'Status'} . "\n";
print "LastUpdateTime: " . $GetLetterStatusResult->{'LastUpdateTime'} . "\n";
} else {
print "Message submission failed on error " . $GetLetterStatusResult->{'ResultCode'} . "\n";
}
} else {
print join ', ',
$result->faultcode,
$result->faultstring,
$result->faultdetail;
}
exit 1;
<br />
<br />