From mariusdumitru.florea@xwiki.com Mon Nov 7 06:55:42 2011 From: Marius Dumitru Florea To: xwiki-users@xwiki.org Subject: Re: [xwiki-users] RESTful API to create a new object of custom class? Date: Mon, 07 Nov 2011 08:55:34 +0200 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1834684198805243413==" --===============1834684198805243413== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi Aaron, On Sat, Nov 5, 2011 at 10:46 AM, Ashtar Communications wrote: > Hi, > > Is it possible to create a new object of a custom class using the RESTful A= PI? > > The documentation page only lists the following POST method, which > doesn't accept a class name: > /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects[?start=3Doffs= et&number=3Dn] True, but the documentation page ( http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HObjectreso= urces ) also says that the supported media types are: * either application/xml (Object element) or * application/x-www-form-urlencoded (a set of property#name=3Dvalue pairs representing properties and a field className) Regarding the first option, I would add the object manually from the wiki (object editor), then export the page as XAR, then look for the "object" tag inside the XML file corresponding to the exported wiki page and use it as POST data for the REST API. Note that the class is specified in the content of the object element so you don't have to specify it in the REST resource URL. Regarding the second option, I would try something like: className=3DXWiki.TestClass&Text=3DThis%20is%20some%20text I think the specified class must exist because otherwise the REST API won't be able to determine the type of the listed properties (e.g. "Text"). Hope this helps, Marius > > I have tried things like the following: > curl -u Admin:admin -X POST -H "Content-type: text/plain" -H "Accept: > application/xml" -d "@test.xml" > http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects/XWik= i.TestClass > > Where test.xml contains some variation on: > > > > > > > > > > > > > > > > > This is some text. > > > > Curl returns this: > > > =C2=A0 Status page > > >

The method specified in the request is not allowed for the resource ide= ntifi > ed by the request URI

You can get technical details 3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6">here.
> Please continue your visit at our home page. >

> > > > Simpler syntax without the XML file still fails for me. In fact, I > can't seem to even get the basic "create object" method to work, even > without the class. For example: > curl -u Admin:admin -X POST > http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects > > Just comes back with a "malformed syntax" error. > > Is there an example anywhere of how to do this? > > Thank you, > > Aaron > _______________________________________________ > users mailing list > users(a)xwiki.org > http://lists.xwiki.org/mailman/listinfo/users > --===============1834684198805243413==--