Not a developer? Go to MovableType.com

Documentation

Creating an entry

Once a client retrieves the service.post URI for the weblog or collection it wishes to create the entry within, the client can post an Atom <entry> element representing the entry to be created via an authenticated HTTP POST operation to the service.edit URI.

If the operation is successful, the Atom server will return an HTTP status code of 201, indicating the the entry was created.

Finding the service.post URI for a Collection

The following demonstrates where in an Atom feed document one can find the URI that a client can use to create Atom entries within that collection or weblog. The following is an excerpt from an Atom feed document:

<feed xmlns="http://www.w3.org/2005/Atom" 
    xmlns:thr="http://purl.org/syndication/thread/1.0">
  <id>tag:www.somedomain.com,2006://3</id>
  <title>Your Weblog</title>
  <link rel="alternate" type="text/html" href="http://www.majordojo.com/" />
  <link rel="service.post" type="application/atom+xml"
     href="http://www.somedomain.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=3" 
     title="Your Weblog" />
  <updated>2006-01-20T05:23:19Z</updated>

Notice the element:

<link rel="service.post" type="application/atom+xml"
 href="http://www.somedomain.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=3" 
 title="Your Weblog" />

The href attribute points to the URI that new Atom entries can be posted to.

Sample Request

POST /t/atom/weblog/blog_id=1 HTTP/1.1
Host: www.typepad.com
X-WSSE: my credentials

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Trip to the Lake</title>
  <dc:subject>Vacation</dc:subject>
  <content type="application/xhtml+xml" mode="xml"><div xmlns="http://www.w3.org/1999/xhtml"><img src="http://example.typepad.com/photos/vacation/lake-thumb.jpg" /> Here is a picture of me at the lake.</div></content>
</entry>

Sample Response

HTTP/1.1 201
Content-Type: application/x.atom+xml

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://purl.org/atom/ns#">
  <title>Trip to the Lake</title>
  <content mode="xml"><div xmlns="http://www.w3.org/1999/xhtml"><img src="http://example.typepad.com/photos/vacation/lake-thumb.jpg" /> Here is a picture of me at the lake.</div></content>
  <issued>2003-10-23T18:35:51Z</issued>
  <link rel="alternate" href="http://example.typepad.com/weblog/2003/10/trip_to_the_lake.html" type="text/html" />
  <id>tag:typepad-com:post:3</id>
  <link rel="service.edit" href="http://www.typepad.com/t/atom/weblog/blog_id=1/entry_id=3" title="Trip to the Lake" type="application/x.atom+xml" />
</entry>

Sample Perl Code

#!/usr/bin/perl

use XML::Atom::Client;
use XML::Atom::Entry;

my $BLOG_ID = '131501';
my $USERNAME = 'your username';
my $PASSWORD = 'your password';
my $FeedURI = 'http://reesespieces.typepad.com/majordojo/atom.xml';

my $api = XML::Atom::Client->new;
$api->username($USERNAME);
$api->password($PASSWORD);

my $PostURI;

my $feed = $api->getFeed($FeedURI);
my @links = $feed->link();
foreach my $l (@links) {
    if ($l->rel eq 'service.post') {
        $PostURI = $l->href;
    }
}

my $entry = XML::Atom::Entry->new;
$entry->title('New Post');
$entry->content('Content of my post.');
my $EditURI = $api->createEntry($PostURI, $entry);

my $entry = $api->getEntry($EditURI);

use Data::Dumper;
print Dumper($entry);
Back

Leave a Comment