Using Umbraco Webservices with Perl
I had quite a few spam comments on my site that I wanted to get rid of. Without a content search option available in Umbraco, I decided to use the webservices to get a list of all blog comments.
As a result of this, I have quite a nice example of how to access Umbraco via webservices with Perl. The example below will simply get all documents from Umbraco and print them to screen.
use SOAP::Lite +trace => 'debug';
use Data::Dumper;
use constant HOST => 'myhost';
use constant UID => 'admin';
use constant PWD => 'mypwd';
use constant ROOTNODE => 0;
my $access = SOAP::Lite
-> proxy('http://'.HOST.'/umbraco/webservices/api/DocumentService.asmx')
-> uri('http://umbraco.org/webservices/')
-> on_action( sub {sprintf '%s%s', @_} );
my $username = SOAP::Data->type(string=> UID)->name('username');
my $password = SOAP::Data->type(string => PWD)->name('password');
my $result = $access->UserAuthenticates($username, $password);
if ($result->fault) {
print $result->faultcode, " : ", $result->faultstring, "\n";
die "Couldn't login";
}
my @docs = allDocs($access, ROOTNODE, $username, $password);
foreach my $doc (@docs) {
print Dumper($doc);
}
sub allDocs {
my ($access, $nodeId, $username, $password) = @_;
my @docs;
my $node = SOAP::Data->type(int=> $nodeId)->name('parentid');
$result = $access->readList($node, $username, $password);
if($result->result)
{
if($result->result->{documentCarrier}->{Id}) {
push @docs, $result->result->{documentCarrier};
} else {
@docs = @{$result->result->{documentCarrier}};
}
}
foreach my $doc (@docs) {
push(@docs, allDocs($access, $doc->{Id}, $username, $password));
}
return @docs;
}