RESTful API to create a new object of custom class?

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

RESTful API to create a new object of custom class?

Aaron Hardy at AC
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]

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/XWiki.TestClass

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
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

Marius Dumitru Florea
Hi Aaron,

On Sat, Nov 5, 2011 at 10:46 AM, Ashtar Communications
<[hidden email]> 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#HObjectresources
) 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 "@test.xml"
> http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects/XWiki.TestClass
>
> 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
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

Fabio Mancinelli-4
In reply to this post by Aaron Hardy at AC
Hi,

you were almost there :)

Your request has two things that were wrong:

1) A text/plain content type instead of application/xml
2) The URI for POSTing new object is
/wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects (and not
 /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className})

...And your XML is missing the className element which will tell the
REST API what class has to be used.

So to sum up, imagine that you want to create on the page Test.Test a
new object of the class XWiki.TestClass, supposing that the class has
a Text property (like in your example)
So you have to do the following:

$ curl -u Admin:admin -X POST -H "Content-type: application/xml" -H
"Accept: application/xml" -d "@test.xml"
http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects

where test.xml is:

<object xmlns="http://www.xwiki.org">
  <className>XWiki.TestClass</className>
  <property name="Text">
    <value>Whatever you want to put here</value>
</property>
</object>

Alternatively you can use the less verbose
application/x-www-form-urlencoded format:

$ curl -u Admin:admin -X POST -H "Content-type:
application/x-www-form-urlencoded" -H "Accept: application/xml" -d
"@test.txt" http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects

where test.txt contains something like:
"className=XWiki.TestClass&property#Test=Whatever+you+want".

Or, better, you can use directly curl to specify these parameters
using multiple -d switches:

$ curl -u Admin:admin -X POST -H "Content-type:
application/x-www-form-urlencoded" -H "Accept: application/xml" -d
"className=XWiki.TestClass" -d "property#Test=Whatever you want"
http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects

The advantage of the second approach is that curl will take care of
url-encode your content, while if you send a file you are responsible
for this.

Now some remarks:

1) In the application/x-www-form-urlencoded format the "property#" is
a standard immutable prefix that is used to distinguish attributes
referring to properties from the attributes referring to the object.
For example if we had "className=XYZ&Text=FOO" we would have had an
ambiguity on className because we couldn't understand if className is
a property of the object to be set to XYZ or an attribute that
describes the object itself (i.e., its metadata like the className).
By having the property# prefix this ambiguity is resolved.

2) The information you get back when you retrieve an object (i.e., all
the <attribute> elements) are useful when clients need to understand
the type of data contained in an object (e.g., when they want to
display it). They are not necessary when creating an object because
the system already has this information. That's why the XML to be sent
is smaller. Actually the only information needed is the <className>
and a set of <property name="..."><value> elements.

3) How do you know what kind of information you can send with the XML?
You can discover it by using the class description URI. If you go to
http://localhost:8080/xwiki/rest/wikis/xwiki/classes you will get a
list of all the classes defined in the Wiki. By looking at this you
will understand what are the properties defined by each class, their
types and attributes. In that way you will know what you're allowed to
put in the <property><value> elements of the XML you send.

Hope this answers your questions.

-Fabio

On Sat, Nov 5, 2011 at 9:46 AM, Ashtar Communications
<[hidden email]> 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]
>
> 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/XWiki.TestClass
>
> 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
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

Aaron Hardy at AC
Thank you both very much! Your suggestions worked perfectly...

aaron

On Mon, Nov 7, 2011 at 8:25 AM, Fabio Mancinelli
<[hidden email]> wrote:

> Hi,
>
> you were almost there :)
>
> Your request has two things that were wrong:
>
> 1) A text/plain content type instead of application/xml
> 2) The URI for POSTing new object is
> /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects (and not
>  /wikis/{wikiName}/spaces/{spaceName}/pages/{pageName}/objects/{className})
>
> ...And your XML is missing the className element which will tell the
> REST API what class has to be used.
>
> So to sum up, imagine that you want to create on the page Test.Test a
> new object of the class XWiki.TestClass, supposing that the class has
> a Text property (like in your example)
> So you have to do the following:
>
> $ curl -u Admin:admin -X POST -H "Content-type: application/xml" -H
> "Accept: application/xml" -d "@test.xml"
> http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
>
> where test.xml is:
>
> <object xmlns="http://www.xwiki.org">
>  <className>XWiki.TestClass</className>
>  <property name="Text">
>    <value>Whatever you want to put here</value>
> </property>
> </object>
>
> Alternatively you can use the less verbose
> application/x-www-form-urlencoded format:
>
> $ curl -u Admin:admin -X POST -H "Content-type:
> application/x-www-form-urlencoded" -H "Accept: application/xml" -d
> "@test.txt" http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
>
> where test.txt contains something like:
> "className=XWiki.TestClass&property#Test=Whatever+you+want".
>
> Or, better, you can use directly curl to specify these parameters
> using multiple -d switches:
>
> $ curl -u Admin:admin -X POST -H "Content-type:
> application/x-www-form-urlencoded" -H "Accept: application/xml" -d
> "className=XWiki.TestClass" -d "property#Test=Whatever you want"
> http://localhost/xwiki/rest/wikis/xwiki/spaces/Test/pages/Test/objects
>
> The advantage of the second approach is that curl will take care of
> url-encode your content, while if you send a file you are responsible
> for this.
>
> Now some remarks:
>
> 1) In the application/x-www-form-urlencoded format the "property#" is
> a standard immutable prefix that is used to distinguish attributes
> referring to properties from the attributes referring to the object.
> For example if we had "className=XYZ&Text=FOO" we would have had an
> ambiguity on className because we couldn't understand if className is
> a property of the object to be set to XYZ or an attribute that
> describes the object itself (i.e., its metadata like the className).
> By having the property# prefix this ambiguity is resolved.
>
> 2) The information you get back when you retrieve an object (i.e., all
> the <attribute> elements) are useful when clients need to understand
> the type of data contained in an object (e.g., when they want to
> display it). They are not necessary when creating an object because
> the system already has this information. That's why the XML to be sent
> is smaller. Actually the only information needed is the <className>
> and a set of <property name="..."><value> elements.
>
> 3) How do you know what kind of information you can send with the XML?
> You can discover it by using the class description URI. If you go to
> http://localhost:8080/xwiki/rest/wikis/xwiki/classes you will get a
> list of all the classes defined in the Wiki. By looking at this you
> will understand what are the properties defined by each class, their
> types and attributes. In that way you will know what you're allowed to
> put in the <property><value> elements of the XML you send.
>
> Hope this answers your questions.
>
> -Fabio
>
> On Sat, Nov 5, 2011 at 9:46 AM, Ashtar Communications
> <[hidden email]> 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]
>>
>> 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/XWiki.TestClass
>>
>> 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
>> [hidden email]
>> http://lists.xwiki.org/mailman/listinfo/users
>>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

pgregoire
Hello,
I read through this thread, and being a newbie to XWiki, I do understand the cURL syntax explained here, but it's the location of wikis/pages/classes I'm unsure about.

I created a custom class of which I'm able to instanciate objects, and list them using a LiveTable.
The className I'm using in the LiveTable options is "Development.Resources.Version Information.VersionInformationClass".
New VersionInformationClass instances I'm creating wind up in the tree under [Home Symbol] / Software Development / Resources / Version Information.

I'd like to create new instances of that class using cURL.
I think the following syntax would look about right:

"C:\Program Files\cURL\bin\curl.exe" -u AdminUser:AdminPassword -X POST -H "Content-type: application/x-www-form-urlencoded" -H "Accept: application/xml" -d "className=Development.Resources.Version Information.VersionInformationClass" -d "property#Name=TestABCD" http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/pages/VersionInformation/objects

Now I have many more properties than just Name, but for testing I figured I'd start just with that one.
The className I'm pretty sure about since this is exactly what I'm successfully using in my LiveTable.
I think the problem is my URI. I'm not sure what the wiki, space and class should be in that context.

I get the following output:
<html>
<head>
   <title>Status page</title>
</head>
<body style="font-family: sans-serif;">
<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Not Found</p>
<p>The server has not found anything matching the request URI</p>
<p>You can get technical details here.<br>
Please continue your visit at our home page.
</p>
</body>
</html>

Can someone help me figure out the correct URI?

Thank you
Phil
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

Jean SIMARD
Hi Phil,

I'm not sure exactly what's wrong with what you're doing but here is two
thought that may help you.

1)  First, you say that "New VersionInformationClass instances I'm
creating wind up in the tree under [Home Symbol] / Software Development
/ Resources / Version Information." so I would expect a URI of the
following form

http://localhost/xwiki/rest/wikis/xwiki/spaces/Software
Development/spaces/Resources/spaces/Version
Information/pages/VersionInformation/objects

2) I see that you put spaces (the character ' ') in some of the spaces
name (wiki's nested spaces).  It should be possible to make it work with
spaces (character) but I'm not sure about the syntax in this case (maybe
a '+' to replace ' ', maybe something else).  You may want to test
without first to see if the problem come from this character or not?

Hope this helps,

Sincerely,

On 01/03/2016 14:42, pgregoire wrote:

> Hello,
> I read through this thread, and being a newbie to XWiki, I do understand the
> cURL syntax explained here, but it's the location of wikis/pages/classes I'm
> unsure about.
>
> I created a custom class of which I'm able to instanciate objects, and list
> them using a LiveTable.
> The className I'm using in the LiveTable options is
> "Development.Resources.Version Information.VersionInformationClass".
> New VersionInformationClass instances I'm creating wind up in the tree under
> [Home Symbol] / Software Development / Resources / Version Information.
>
> I'd like to create new instances of that class using cURL.
> I think the following syntax would look about right:
>
> "C:\Program Files\cURL\bin\curl.exe" -u AdminUser:AdminPassword -X POST -H
> "Content-type: application/x-www-form-urlencoded" -H "Accept:
> application/xml" -d "className=Development.Resources.Version
> Information.VersionInformationClass" -d "property#Name=TestABCD"
> http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/pages/VersionInformation/objects
>
> Now I have many more properties than just Name, but for testing I figured
> I'd start just with that one.
> The className I'm pretty sure about since this is exactly what I'm
> successfully using in my LiveTable.
> I think the problem is my URI. I'm not sure what the wiki, space and class
> should be in that context.
>
> I get the following output:
> <html>
> <head>
>    <title>Status page</title>
> </head>
> <body style="font-family: sans-serif;">
> <p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Not Found</p>
> <p>The server has not found anything matching the request URI</p>
> <p>You can get technical details  here
> <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5>  .<br>
> Please continue your visit at our  home page </>  .
> </p>
> </body>
> </html>
>
> Can someone help me figure out the correct URI?
>
> Thank you
> Phil
>
>
>
>
> --
> View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-API-to-create-a-new-object-of-custom-class-tp6965384p7598184.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>

--
Jean Simard
[hidden email]
Research engineer at XWiki SAS
http://www.xwiki.com
Committer on the XWiki.org project
http://www.xwiki.org
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

pgregoire
Thank you,
so basically everything that has children is considered a space?

I tried the two following syntaxes:

-X POST -H "Content-type: application/x-www-form-urlencoded" -
H "Accept: application/xml" -d "className=Development.Resources.Version Information.VersionInformationClass" -d "property#Name=TestABCD" htt
p://localhost/xwiki/rest/wikis/xwiki/spaces/Software+Development/spaces/Resources/pages/Version+Information/objects

I get this reply:
<p>The server has not found anything matching the request URI</p>

With the following:
http://localhost/xwiki/rest/wikis/xwiki/spaces/Software+Development/spaces/Resources/spaces/Version+Information/objects

I get this:
<p>The method specified in the request is not allowed for the resource identified by the request URI</p>

Which would indicate that it might be the correct URI, but for some reason the request is not allowed?
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

Jean SIMARD
It seems that Version+Information is a space, not a (terminal) page.
And indeed, you'll not be able to add objects to a space.  Nested spaces
is a new functionality from version 7.x.  You may want to read about
"Nested Spaces" in order to understand more what's a page and what's a
space in the this context.  In your case, you may try to use the
following URI

http://localhost/xwiki/rest/wikis/xwiki/spaces/Software+Development/spaces/Resources/spaces/Version+Information/pages/WebHome/objects

This WebHome should be here (I hope I'm not saying wrong things) for
retro-compatibility reasons.

In any case, I'm not mastering Nested Spaces so documentation (or
another community member more aware of the topic?) will say less crap
than me ;-)

Sincerely,

On 01/03/2016 17:17, pgregoire wrote:

> Thank you,
> so basically everything that has children is considered a space?
>
> I tried the two following syntaxes:
>
> -X POST -H "Content-type: application/x-www-form-urlencoded" -
> H "Accept: application/xml" -d "className=Development.Resources.Version
> Information.VersionInformationClass" -d "property#Name=TestABCD" htt
> p://localhost/xwiki/rest/wikis/xwiki/spaces/Software+Development/spaces/Resources/*pages*/Version+Information/objects
>
> I get this reply:
> <p>The server has not found anything matching the request URI</p>
>
> With the following:
> http://localhost/xwiki/rest/wikis/xwiki/spaces/Software+Development/spaces/Resources/*spaces*/Version+Information/objects
>
> I get this:
> <p>The method specified in the request is not allowed for the resource
> identified by the request URI</p>
>
> Which would indicate that it might be the correct URI, but for some reason
> the request is not allowed?
>
>
>
> --
> View this message in context: http://xwiki.475771.n2.nabble.com/RESTful-API-to-create-a-new-object-of-custom-class-tp6965384p7598216.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
>

--
Jean Simard
[hidden email]
Research engineer at XWiki SAS
http://www.xwiki.com
Committer on the XWiki.org project
http://www.xwiki.org
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

pgregoire
This post was updated on .
Ok I think we're on to something now...

The actual name of the space is "Development". "Software Development" is just the pretty name.
I entered the page as WebHome.

http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Resources/spaces/Version+Information/pages/WebHome/objects

Just ran this and I managed to create the object. It just overwrote the Version Information page instead of creating the new object under it.
Getting there!
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

pgregoire
This post was updated on .
I'm sorry, I think I still need a little help here...

So, I managed to get my object created.
To give you an idea, I have a page (at Development.Resources.Version Information.WebHome) where I have a LiveTable that shows all my VersionInformation objects.
When I create these objects, they wind up in the hierarchy under the Version Information node.

The only way I was able to run the cURL command properly was with this command line:
"C:\Program Files\cURL\bin\curl.exe" -u AdminUser:AdminPwd -X POST -H "Content-type: application/x-www-form-urlencoded" -H "Accept: application/xml" -d "className=XWiki.Development.Resources.Version Information.VersionInformationClass" -d "property#Name=TestABCD" http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Version+Information/pages/WebHome/objects

But doing this overwrites the Development.Resources.Version Information.WebHome with the newly created object.
Now, it seems that the URI must end with a page, but it is my understanding the a page can't have children - so how do I create VersionInformation class instances under a certain node?

Thanks again for the help.

Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

pgregoire
Ok an update here...
With the following syntax:

"C:\Program Files\cURL\bin\curl.exe" -u admin:admin -X POST -H "Content-type: application/x-www-form-urlencoded" -H "Accept: application/xml" -d "className=XWiki.Development.Resources.Version Information.VersionInformationClass" -d "property#Name=TestABCD" -d "property#Product=4.0" http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Resources/spaces/Version+Information/pages/WebHome/objects

it seems that some object does created - if I go to the Version Information webhome, click edit and select Objects, I see the following:
XWiki.Development.Resources.Version Information.VersionInformationClass
Development.Resources.Version Information.VersionInformationClass 0

And instances get added each time I run it again a new instance gets added (0, 1, etc.). It seems there's nothing I can do with these instances except delete them. I don't see them in the tree either.

Something else I tried is the following:
"C:\Program Files\cURL\bin\curl.exe" -u admin:admin -X PUT -H "Content-type: application/x-www-form-urlencoded" -H "Accept: application/xml" -d "className=XWiki.Development.Resources.Version Information.VersionInformationClass" -d "property#Name=TestABCD" -d "property#Product=4.0" http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Resources/spaces/Version+Information/pages/TestABCD

In this case, a new page called TestABCD appears in the hierarchy under Version Information. But it's a regular page, not a Version Information one like I can create with the template.

Could my issue be that my object creation does not include every property of the class?
Or am I not understanding the concept the class objects properly?

What I'm looking for is to wind up with a page that looks the same as when I create a new page using my Version Information template.
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

pgregoire
Finally made it!
So - first of all I messed up my class name while trying stuff out, I didn't need the XWiki. prefix in there.
Second, I first create the page with a PUT command, then I make it into an instance of my class (or rather create an object of that class under it and somehow it does the math) with a POST.

So I have the following:

"C:\Program Files\cURL\bin\curl.exe" -u admin:admin -X PUT ^
-H "Content-type: application/x-www-form-urlencoded" -H "Accept: application/xml" ^
http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Resources/spaces/Version+Information/pages/TestABCD 

"C:\Program Files\cURL\bin\curl.exe" -u admin:admin -X POST ^
-H "Content-type: application/x-www-form-urlencoded" -H "Accept: application/xml" ^
-d "className=Development.Resources.Version Information.VersionInformationClass" ^
-d "property#Name=TestABCD" ^
http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Resources/spaces/Version+Information/pages/TestABCD/objects
Reply | Threaded
Open this post in threaded view
|

Re: RESTful API to create a new object of custom class?

vmassol
Administrator
 

On 4 Mar 2016 at 15:11:24, pgregoire ([hidden email](mailto:[hidden email])) wrote:

> Finally made it!

Cool, glad you succeeded! And thanks for posting your solution, this could help others.

Thanks
-Vincent

> So - first of all I messed up my class name while trying stuff out, I didn't
> need the XWiki. prefix in there.
> Second, I first create the page with a PUT command, then I make it into an
> instance of my class (or rather create an object of that class under it and
> somehow it does the math) with a POST.
>  
> So I have the following:
>  
> "C:\Program Files\cURL\bin\curl.exe" -u admin:admin -X PUT ^
> -H "Content-type: application/x-www-form-urlencoded" -H "Accept:
> application/xml" ^
> http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Resources/spaces/Version+Information/pages/TestABCD
>  
> "C:\Program Files\cURL\bin\curl.exe" -u admin:admin -X POST ^
> -H "Content-type: application/x-www-form-urlencoded" -H "Accept:
> application/xml" ^
> -d "className=Development.Resources.Version
> Information.VersionInformationClass" ^
> -d "property#Name=TestABCD" ^
> http://localhost/xwiki/rest/wikis/xwiki/spaces/Development/spaces/Resources/spaces/Version+Information/pages/TestABCD/objects
>  
>  
>  
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users