Darren Ferguson - Blog
09 January 2009 at 09:01
Create an Umbraco document with Perl and Web services
This isn't a blog post as such, just a code snippet that may be quite useful.
I spent quite a bit of time figuring out how to get Perl and Soap::Lite to do complex data types the other day. The following code creates a new Umbraco document using Web services.
use strict;
use SOAP::Lite +trace => 'debug';
use HTML::Entities;
use Date::Format;
use Data::Dumper;
use constant HOST => 'www.mydomain.com';
use constant UID => 'myuid';
use constant PWD => 'secrit';
my $access =
SOAP::Lite->proxy(
'http://' . HOST . '/umbraco/webservices/api/DocumentService.asmx' )
->uri('http://umbraco.org/webservices/')
->on_action( sub { sprintf '%s%s', @_ } );
my $data = SOAP::Data->name(
"carrier" => \SOAP::Data->value(
# SOAP::Data->name( 'Id' => 0 ),
SOAP::Data->name( 'Name' => 'This is a test'),
SOAP::Data->name( 'DocumentTypeID' => 1042 ),
SOAP::Data->name( 'ParentID' => 1049 ),
SOAP::Data->name( 'HasChildren' => 'false' ),
SOAP::Data->name( 'PublishAction' => 'Publish' ),
SOAP::Data->name( 'Published' => 'true' ),
# SOAP::Data->name( 'ReleaseDate' => time2str('%Y-%m-%d', time) ),
# SOAP::Data->name( 'ExpireDate' => time2str('%Y-%m-%d', time) ),
SOAP::Data->name(
"DocumentProperties" => \SOAP::Data->value(
SOAP::Data->name(
"documentProperty" => \SOAP::Data->value(
SOAP::Data->name( 'Key' => 'Title' ),
SOAP::Data->name( 'PropertyValue' => 'This is a test' ),
)
),
SOAP::Data->name(
"documentProperty" => \SOAP::Data->value(
SOAP::Data->name( "Key" => 'bodyText' ),
SOAP::Data->name(
"PropertyValue" => encode_entities('<p>This is some html</p>')
),
)
),
SOAP::Data->name(
"documentProperty" => \SOAP::Data->value(
SOAP::Data->name( "Key" => 'DisplayDate' ),
SOAP::Data->name(
"PropertyValue" => time2str( '%Y-%m-%d', time )
),
)
)
)
)
)
);
# print SOAP::Serializer->autotype(0)->serialize($data);
my $username = SOAP::Data->type( string => UID )->name('username');
my $password = SOAP::Data->type( string => PWD )->name('password');
my $result = $access->create( $data, $username, $password );
print Dumper( $result->result );
During this process, I also realised that the Umbraco media service is incomplete so I'll try and get access to the source and complete this.
Written by: Darren Ferguson
Mike
26 October 2009 at 06:08
I think Thomas Hoehler implemented his own web service to do this so it may be worth getting in touch with him.
26 October 2009 at 09:12