Rest API Add Object/Class NullPointerException

Hello Xwiki Community,
I am writing an API for our xwiki, here I encounter an error that I can’t fix.

I just want to add a class to a freshly created website without setting any properties.

The XML is as follows

<?xml version="1.0" encoding="UTF-8"?>
<object xmlns="http://www.xwiki.org">
   <className>Customer.Code.CustomerClass</className>

</object>

As an answer I get unfortunately a 500 with

Mai 09, 2022 7:27:27 PM org.restlet.engine.application.StatusFilter doHandle
WARNUNG: Exception or error caught by status service
java.lang.NullPointerException: Cannot invoke "com.xpn.xwiki.objects.PropertyInterface.getObject()" because "property" is null

Correspondingly I have tried following XML

<?xml version="1.0" encoding="UTF-8"?>
<object xmlns="http://www.xwiki.org">
   <className>Customer.Code.CustomerClass</className>
   <property Settings="text">hallo</property>
   <property />
</object>

This returns a 400 error with the following response

Action to take for this exception:
org.restlet.ext.jaxrs.internal.exceptions.ConvertRepresentationException: Could not convert the message body to a
org.xwiki.rest.model.jaxb.Object
 at
org.restlet.ext.jaxrs.internal.exceptions.ConvertRepresentationException.object(ConvertRepresentationException.java:49)

I use Xwiki 14.3.1
Sent with Invoke-WebRequest via Powershell 7
The error also occurs with Curl in the console

Is my XML correct ?
If yes where can I look further for the error ?

Hi, no apparently it’s not correct. The root entity you specified is an object as <object xmlns="http://www.xwiki.org"> so you cannot create a class with it, but an actual object.
You can check the XML schema there: xwiki-platform/xwiki.rest.model.xsd at master · xwiki/xwiki-platform · GitHub

Usually easiest is to query in XML an existing XClass to check its representation, something such as:

http://localhost:8080/xwiki/rest/wikis/xwiki/classes/XWiki.XWikiUsers

Also AFAICS in REST API (XWiki.org) it might not be possible to create a class this way. But I let you read the doc, I might have missed it.

Thank you for the quick reply,

First of all, I have to correct myself, I must have confused something here.

I want to add an object from a class that already exists.
Accordingly I have followed these instructions
[REST API (XWiki.org)](https://my Source)

My structure
I have created an application named Customer with the corresponding class.
Here I want to automatically create entries using a database.
To do this, I first create the page and then add the object with class, so that this page appears in application.

The corresponding information for this I had me to one from the upper article as well as directly about the rest API together searched (test page created and looked what was set here).

It has also brought me a bit further, that I can identify the properties correctly.
My XML with properties now looks like this

<?xml version="1.0" encoding="UTF-8"?>
<object xmlns="http://www.xwiki.org">
   <className>Customer.Code.CustomerClass</className>
   <property Interface="TextArea">hallo</property>
   <property />
</object>

Caused we as with my second XML a 400 error.
But with the following error

May 09, 2022 9:54:28 PM org.restlet.ext.jaxb.JaxbRepresentation getObject
WARNING: Unable to unmarshal the XML representation
javax.xml.bind.UnmarshalException

  • with linked exception:
    [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 7; The processing instruction target matching “[xX][mM][lL]” is not allowed.]

Which matches your answer that my XML is wrong.
Accordingly, a minimal example would have to look like this

Send To http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Customer/8888

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.xwiki.org"
  xmlns:xwiki="http://www.xwiki.org" elementFormDefault="qualified">
  <complexType name="PageSummary">
    <complexContent>
      <extension base="xwiki:Customer">
        <sequence>
          <element name="title" type="string">Testpage</element>
        </sequence>
      </extension>
    </complexContent>
  </complexType>
</schema>  

And after that

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.xwiki.org"
  xmlns:xwiki="http://www.xwiki.org" elementFormDefault="qualified">
<complexType name="ObjectSummary">
    <complexContent>
      <extension base="xwiki:Customer">
        <sequence>
          <element name="className" type="string">Customer.Code.CustomerClass</element>
        </sequence>
      </extension>
    </complexContent>
  </complexType>
</schema>

The curious thing I don’t understand.
On the one hand the example works, as well as my first XML
the object is added to the page.
The only problem that appears if I had analyzed it correctly, is that XWIKI wants to send me back an XML with the properties of the set classes object,
only there is here a wrong link back which has the consequence that I get a 500er displayed. The but not at all on the create / add refers but on the response.
What makes the error (NUllPointerExecption) in the log of XWIKI seem plausible, since the freshly erstelel object has got no properties from me and are therefore NULL.

What I also do not understand.
if I do it this way my minimal example is also wrong, because I would have to add more information like id,pageid etc…
But why should I do that ? I already specify via the URL where the target is.
Why do I have to add it again in XML?

Or the other way around.
If I simply give it to the rest-api why is it not enough to have the xml completely filled in but to specify the URl where it should be created.