Contacts
Sales: 603-546-6751
Email: sales@cairnapps.com

General:

Services:

Resources:

Direct Booking example - Perl

The following is a working example in Perl:


     #!/usr/bin/perl
     use strict; 
     use LWP::UserAgent;
     use Data::Dumper; 
     use JSON;  
     use Date::Simple; 
     use URI::Encode qw(uri_decode uri_encode ); 

     ############ Config ############

     my $username = 'tobeissued'; 
     my $password = 'tobeissued'; 

     ################################


     my $destination; 
     ################### Hand shake ####################

     my %fields = ( 
          command   => 'cmdBoxTWebAPIHandShake', 
          username  => "$username", 
          password  => "$password" ); 

     my @args = (); 

     foreach my $key ( keys %fields ) {
          my $value = uri_encode( $fields{ $key } ); 
          push @args, "$key=$value"; 
     }

     my $queryString = join('&', @args ); 


     $destination     = "https://www.dumpster.software/controller.html?$queryString"; 
     my $ua = LWP::UserAgent->new; 
     my $response =  $ua->request(HTTP::Request->new(GET => $destination));

     my $json = JSON->new(); 
     my $obj = $json->decode( $response->content ); 

     unless ( $obj->{ status } == 200) { 
          print Data::Dumper->Dump([ $obj ]); 
          exit; 
     }

     #####################  Pricing Query ##############
     #Extract Key from the resulting JSON for use in the Pricing Query
     my $key = $obj->{ key }; 

     %fields = (
          command        => 'cmdBoxTWebAPIPricing', 
          username       => '$username', 
          key            => '$key', 
          zipPostalCode  => '23462' ); 

     @args = (); 

     foreach my $key ( keys %fields ) {
          my $value = uri_encode( $fields{ $key } ); 
          push @args, "$key=$value"; 
     }

     $queryString = join('&', @args ); 

     $destination = "https://www.dumpster.software/controller.html?$queryString"; 
     $response =  $ua->request(HTTP::Request->new(GET => $destination));
     $obj = $json->decode( $response->content ); 


     unless ( $obj->{ status } == 200) { 
          print Data::Dumper->Dump([ $obj ]); 
          exit; 
     }

     #####################  Post Request  ##############

     my $dsDate = Date::Simple->new(); 
     $dsDate = $dsDate+5; 
     my %fields = (
          command                  => 'cmdBoxTWebAPIDirectBooking', 
          username                 => $username, 
          key                      => $key, 
          name                     => 'Dave Smally', 
          billingAddress1          => '88 Main Street', 
          billingAddress2          => 'Apt 2', 
          billingCity              => 'Smithfield', 
          billingStateProv         => 'VA', 
          billingZipPostal         => '12345', 
          billingCountry           => 'USA', 
          billingPhone             => '1234567890', 
          billingEmail             => 'johns@somedomain.com', 
          jobName                  => 'Clean out', 
          jobAddress               => '88 Main Street', 
          jobCity                  => 'Yourtown', 
          jobStateProv             => 'VA', 
          jobZipPostal             => '12345', 
          jobLatitude              => '42.9815689', 
          jobLongitude             => '-71.4862495', 
          distanceByRoad           => '18 mi', 
          dateRequested            => "$dsDate", 
          serviceType              => 'Delivery', 
          assetClass               => '20-open', 
          containerID              => '', 
          material                 => 'C & D',
          hazards                  => 'Low wires', 
          priceSheetID             => '44', 
          note                     => 'Call first', 
          ccardFName               => 'John', 
          ccardLName               => 'Smith', 
          ccardBillingAddress1     => '123 Main Street', 
          ccardBillingAddress2     => 'Apt 2',
          ccardBillingCity         => 'Yourtown', 
          ccardBillingStateProv    => 'VA', 
          ccardBillingZipPostal    => '12345', 
          ccardNumber              => '4111111111111111', 
          ccardExp                 => '0422', 
          ccardCVV                 => '123',  
          mode                     => 'TEST');

     @args = (); 

     foreach my $key ( keys %fields ) {
          my $value = uri_encode( $fields{ $key } ); 
          push @args, "$key=$value"; 
     }

     $queryString = join('&', @args ); 

     $destination = "https://www.dumpster.software/controller.html?$queryString"; 
     $response =  $ua->request(HTTP::Request->new(GET => $destination));
     $obj = $json->decode( $response->content ); 

     print Data::Dumper->Dump([ $obj ]);