Create_Computer_REST-API

Hi, I’m experimenting with the REST-API and i successfully created a computer object via the gui with the following json:

{
  "properties": {
    "name": "RESTI",
    "description": "testvia api",
    "operatingSystem": "windows",
    "operatingSystemVersion": "win98",
    "domain": "string",
    "mac": [
      "11:22:33:44:55:66"
    ],
    "ip": [
      "1.2.3.4"
    ]
  }
}

However, the exact same json via a curl POST gives an error:

curl -nk -X POST -H  "Accept: application/json" -H "Content-Type: application/json" "https://<FQDN>/univention/udm/computers/computer/" --data @rest.json 
{"error": {"code": 422, "title": "Unprocessable Entity", "message": "3 error(s) occurred:\nRequest argument \"domain\" The Computer module has no property domain.\nRequest argument \"operatingSystem\" The Computer module has no property operatingSystem.\nRequest argument \"operatingSystemVersion\" The Computer module has no property operatingSystemVersion.\n", "error": {"domain": "The Computer module has no property domain.", "operatingSystem": "The Computer module has no property operatingSystem.", "operatingSystemVersion": "The Computer module has no property operatingSystemVersion."}}, "_embedded": {"udm:error": [{"location": ["body", "properties", "domain"], "message": "The Computer module has no property domain.", "type": "value_error"}, {"location": ["body", "properties", "operatingSystem"], "message": "The Computer module has no property operatingSystem.", "type": "value_error"}, {"location": ["body", "properties", "operatingSystemVersion"], "message": "The Computer module has no property operatingSystemVersion.", "type": "value_error"}]}, "_links": {"self": [{"title": "HTTP-Error 422: Unprocessable Entity", "href": "https://<FQDN>/univention/

Can someone explain what went wrong here?

Regards.
Oliver Niesner
P.S.: I did the same with with a user object and this worked also with a curl POST command!!

The UDM module computers/computer is purely virtual for listing objects.
You cannot create an object of it. You must create objects of a specific type like computers/domaincontroller_backup or computers/windows.

The easiest way to see what types exist and what properties they offer is using the udm command line interface.
The command udm modules will list all available object types. You can also get the list by looking at http://<IP>/univention/udm/schema/

Then run udm <module name> to see the properties a UDM module supports.
For example udm computers/domaincontroller_master includes operatingSystem.
If you run udm computers/computer, you’ll find no properties.

You have to send your POST request to https://<FQDN>/univention/udm/computers/memberserver or similar.

…thanks for the quick answer. :slightly_smiling_face:
You’re right i adapted the url from the …/users/user… object and that’s not correct.
Changing the url to:

curl -nkv -X POST -H  "Accept: application/json" -H "Content-Type: application/json" "https://<FQDN>/univention/udm/computers/windows/" --data @rest.json

does the trick and everything works as expected.

Thanks for pointing that out!
Oliver

Mastodon