Perl example using SOAP::LITE

Discussion in 'Developers Forum' started by gavin, Jun 18, 2009.

  1. gavin New Member

    Hi,

    For those of you interested, here's how to connect via SOAP::Lite:

    Code:
    #!/usr/bin/perl 
    #===============================================================================
    #
    #         FILE:  invoices.pl
    #
    #        USAGE:  ./invoices.pl
    #
    #  DESCRIPTION:  KashFLow API to check and generate invoices
    #
    #      OPTIONS:  ---
    # REQUIREMENTS:  ---
    #         BUGS:  ---
    #        NOTES:  ---
    #       AUTHOR:  Gavin Henry (GH), <ghenry@suretecsystems.com>
    #      COMPANY:  Suretec Systems Ltd.
    #      VERSION:  1.0
    #      CREATED:  17/06/09 14:00:32 BST
    #     REVISION:  ---
    #===============================================================================
    
    use strict;
    use warnings;
    use Data::Dumper;
    
    # By default, SOAP::Lite generates a SOAPAction header with the structure of
    # [URI]#[method]. We need KashFlow/method, hence we use on_action
    #
    use SOAP::Lite on_action => sub { sprintf '%s/%s', @_ };
    
    # Need tomake sure they are definitely strings.
    my $user = SOAP::Data->type('string')->name( UserName => 'suretec' );
    my $pass = SOAP::Data->type('string')->name( Password => 'testing_password' );
    
    my $kfapi =
      SOAP::Lite->uri('KashFlow')
      ->proxy('https://secure.kashflow.co.uk/api/service.asmx')->on_fault(
        sub {
            my ( $soap, $res ) = @_;
            die ref $res ? $res->faultdetail : $soap->transport->status, "\n";
        }
      );
    
    my $cust_email =
      SOAP::Data->type('string')
      ->name( CustomerEmail => 'enquiries@suretecsystems.com' );
    my $cust = $kfapi->GetCustomerByEmail( $user, $pass, $cust_email )->result;
    
    print 'Customers name is ' . $cust->{'Name'}, "\n" if $cust;
    
  2. ukfsn New Member

    Alternatively use Net::KashFlow which provides a far easier, and more perlish, interface.
  3. gavin New Member

    Yeah, that wasn't around when I wrote this snippet.

Share This Page