gib
gib

Reputation: 788

SOAP client in Perl

Im trying to "talk" to https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl using Perl and SOAP::Lite.

In PHP its as simple as this:

<?
$client = new SoapClient('https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');
$results = $client->doQueryAllSysStatus(array(
    'countryId' => 1,
    'webapiKey' => 'XXXXXX'
));
header('Content-type: text/plain');
var_dump($results);
?>

But with Perl... its not ;).

I wrote this:

use SOAP::Lite;
my $soap = SOAP::Lite->new(proxy => 'https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');
my $som = $soap->call('doQueryAllSysStatus', 1, 'XXXXXX');
# tried also this:
# my $som = $soap->call('doQueryAllSysStatus', 
#     SOAP::Data->name('countryId')->value(1),
#     SOAP::Data->name('webapiKey')->value('XXXXXX')
# );
die $som->faultstring if ($som->fault);
print $som->result, "\n";

$som->result is empty.

Tried also:

use SOAP::Lite;
my $soap = SOAP::Lite->service('https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');
my $r = $soap->doQueryAllSysStatus(1, 'xxxxxx');
print $r, "\n";

... and got Use of uninitialized value $r in print.

Any help would be appreciated...

UPDATE #1: PHP code outputs this:

object(stdClass)#2 (1) {
  ["sysCountryStatus"]=>
  object(stdClass)#3 (1) {
    ["item"]=>
    object(stdClass)#4 (8) {
      ["countryId"]=>
      int(1)
      ["programVersion"]=>
      string(3) "1.0"
      ["catsVersion"]=>
      string(6) "1.4.94"
      ["apiVersion"]=>
      string(3) "1.0"
      ["attribVersion"]=>
      string(3) "1.0"
      ["formSellVersion"]=>
      string(7) "1.11.91"
      ["siteVersion"]=>
      string(3) "1.0"
      ["verKey"]=>
      int(1505223106)
    }
  }
}

Upvotes: 0

Views: 838

Answers (2)

gib
gib

Reputation: 788

I found a working solution, so for anybody curious here it is.

I gave up with SOAP::Lite and used XML::Compile::* modules with a little help from HTTP::Tiny.

The code:

use Data::Printer;
use HTTP::Tiny;
use XML::Compile::SOAP11;
use XML::Compile::WSDL11;
use XML::Compile::Transport::SOAPHTTP;

my $wsdlXml = HTTP::Tiny->new->get('https://....')->{content};
my $wsdl    = XML::Compile::WSDL11->new($wsdlXml);

my $response = $wsdl->compileCall('doQueryAllSysStatus')->(
    countryId => 1, 
    webapiKey => 'xxxxxx'
);
p $response;

Which prints out:

\ {
    parameters   {
        sysCountryStatus   {
            item   [
                [0] {
                    apiVersion        1.0,
                    attribVersion     1.0,
                    catsVersion       "1.4.94",
                    countryId         1,
                    formSellVersion   "1.11.91",
                    programVersion    1.0,
                    siteVersion       1.0,
                    verKey            1505223106
                }
            ]
        }
    }
}

Yay! ;)

Upvotes: 1

Ed Dunn
Ed Dunn

Reputation: 1172

I don't have a web api key so I can't fully test but what about something like this?

#!/usr/bin/perl

use warnings;
use strict;
use SOAP::Lite;

my $soap = SOAP::Lite->new( proxy => 'https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');

my $country = 1;
my $api = 'XXXXX';

my $r = $soap->doQueryAllSysStatus($country,$api);

print $r->result, "\n";

--- UPDATE ---

#!/usr/bin/perl

use warnings;
use strict;
use SOAP::Lite;
use Data::Dumper;

my $soap = SOAP::Lite->new( proxy => 'https://webapi.allegro.pl.webapisandbox.pl/service.php?wsdl');

my $country = 1;
my $api = 'XXXXX';

my @r = $soap->doQueryAllSysStatus($country,$api);

print Dumper(\@r);

Upvotes: 0

Related Questions