First of all, as I’m new here, I want to thank all developers from XWiki SAS and all other contributors for providing this awesome platform.
I’ve been checking out the REST API and generally speaking, it works like a charm when I know how to do things - could create pages, users, attachments and so on. However, I failed to achieve the following:
Is it possible to create class properties using the REST API? I mean the action you perform when using the class editor for a page.
Trying to create a page the normal way using a PUT request and adding a class/property section in the xml. At least that’s what the xml looks like if I send a GET request including ?class=true for a page which has a class property, so I thought this might work. That request was actually accepted, but the property I defined was not uploaded.
Adding the property as an object to the page seems to make no sense (and did not work either) as a class property isn’t a page object to my understanding.
I could provide more details but first I would like to understand which of these ways is the correct one, or maybe another, or even none, or if there’s a fundamental misconception in my thinking.
Unfortunately it’s still a (shameful) hole in that API, see Loading.... Should not be hard to add the resource for it, but just never been at the top of the TODO list.
the UI which manipulate the class actually use a kind of REST API, but it’s one which takes a token that you can only get by having a foot in the instance itself since you need to call a Java/script API to get one
Just for documentation, following the suggestion from @tmortagne I arrived at the following workaround. This works completely from the REST API so I’m achieving functionally the same as if the REST endpoint I’m after would actually exist. I’m creating the scripted page from the REST API, then execute it with a GET request, then delete it. It’s kind of verbose and might be achievable in a more elegant way but I’m fine with it.
The code for the XClass creation is taken directly from the XWiki Scripting API Guide (with slight adjustments).
As for the outcome of 1.-3. I’ll have my desired class “Temp/MyTestClass”, being a terminal page, including a property “MyTestProperty” of type string with size of 30.
That’s a lot of created and delete pages (I would have seen a single persistent ClassCreator service which takes what to do as parameter), but glad you found a workaround that works for you