Hi Aaron,
On Sat, Nov 5, 2011 at 10:46 AM, Ashtar Communications
<ashtarcommunications(a)gmail.com> wrote:
Hi,
Is it possible to create a new object of a custom class using the RESTful API?
The documentation page only lists the following POST method, which
doesn't accept a class name:
/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects[?start=offset&number=n]
True, but the documentation page (
http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HObjectre…
) also says that the supported media types are:
* either application/xml (Object element) or
* application/x-www-form-urlencoded (a set of property#name=value
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=XWiki.TestClass&Text=This%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 "(a)test.xml"
http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects/XWik…
Where test.xml contains some variation on:
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<properties xmlns="http://www.xwiki.org">
<property type="com.xpn.xwiki.objects.classes.TextAreaClass"
name="Text">
<attribute value="Text" name="name"/>
<attribute value="Test" name="prettyName"/>
<attribute value="0" name="unmodifiable"/>
<attribute value="0" name="disabled"/>
<attribute value="100" name="size"/>
<attribute value="10" name="rows"/>
<attribute value="" name="customDisplay"/>
<attribute value="Text" name="editor"/>
<attribute value="6" name="number"/>
<attribute value="0" name="picker"/>
<attribute value="" name="validationMessage"/>
<attribute value="" name="validationRegExp"/>
<value>
This is some text.
</value>
</properties>
Curl returns this:
<html>
<head>
<title>Status page</title>
</head>
<body>
<h3>The method specified in the request is not allowed for the resource identifi
ed by the request URI</h3><p>You can get technical details <a
href="http://www.w
3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6">here</a>.<br>
Please continue your visit at our <a href="/">home page</a>.
</p>
</body>
</html>
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