Using REST API to modify one user attribute

Hi,

I am starting to use the REST API for UCS and would like to modify a single user LDAP attribute.

I am wondering whether there is a better way than: retrieving the entire set of user attributes as JSON, modifying the one value in the JSON structure, and then uploading the entire JSON data again…? This feels a bit excessive for only one single change.

Any suggestions welcome, thank you!

PS: I cannot use udm on the shell, sorry.

hi yes of course you can only change one attribute, below is an example to change the employeetype attribute.

ppaolino.json:

{
  "dn": "uid=ppaolino,cn=users,dc=acme,dc=corp",
  "position": "cn=users,dc=acme,dc=corp",
  "properties": {
    "lastname": "Paolino",
    "firstname": "Paperino",
    "username": "ppaolino",
    "password": null,
    "employeeType": "Fannullone"
  }
}
curl -kX PUT \
        -u user:password \
        -H "Accept: application/json" \
        -H "Content-Type: application/json" \
        -H 'If-Match: "XXXXXXXXXXXXXXXXXXXXXXXXXXX"' \
        https://UCS/univention/udm/users/user/uid%3Dppaolino%2Ccn%3Dusers%2Cdc%3Dacme%2Cdc%3Dcorp \
        --data @ppaolino.json

regards, bb.

Thank you very much, very helpful!

Allow me some follow-up questions while trying to better understand the system:

  • Why do I have to send properties “lastname” and “firstname” if “dn” and “position” are provided?
  • Will your example delete the password?
  • When does the Etag change?

Is it also possible to do this with a simple GET request, e.g.
curl -X GET -u user:password https://UCS/univention/udm/users/user/uid%3Dppaolino%2Ccn%3Dusers%2Cdc%3Dacme%2Cdc%3Dcorp?properties.employeeType=Fannullone

Mille grazie!

hi, i think the documentation is clear enough:

  1. to make changes the restapi need a minimum set of information (firstname, lastname, username)
  2. the password set to null does not change it but is needed
  3. get the ETag so prevent modification conflicts
  4. do the PUT to modify the user attribute

regards, bb.

Thank you.

Well, for me the documentation is pretty short, e.g. it says nothing about the reduced set of JSON data to make changes. Instead it suggests to “edit the user in the user.json file to your liking. After you are done, send the changed user.json via a PUT request”…

One more question if you allow:
What is the best way for adding or removing a user to/from a group? Do I need to make a full copy of the existing groups found on the user, modify that list and then upload the updated list as JSON?

Thank you

What is the best way for adding or removing a user to/from a group? Do I need to make a full copy of the existing groups found on the user, modify that list and then upload the updated list as JSON?

If you use PUT, you must upload the complete object you want to modify. In this case it means that you must make a copy of the complete user object, modify the groups property and upload the complete (modified) user object.

If you use PATCH, it only need to send the properties you want to change.

In case you’re using Python, use The Python UDM REST API Client from PyPI.

Thank you for the advice about PUT and PATCH.
As I was pointed to the docs before, I’d like to mention that the documentation has a section called " Modify a user via a PUT request" and only very briefly mentions “PATCH Modify or move a resource” in the first little table…

The Python package looks very easy to use but I need to use PHP - is there anything comparable for that language, too?

The Python package looks very easy to use but I need to use PHP - is there anything comparable for that language, too?

I haven’t tested it for PHP myself, but the UDM REST API Python Client library low-level part is auto-generated from the OpenAPI schema, that the UDM REST API exposes. So you should be able to do the same for PHP.
We used https://github.com/OpenAPITools/openapi-generator to create it for Python - its doc says it can do the same for PHP.

You can finde the interactive Swagger UI here: https://FQDN/univention/udm/schema/ and the OpenAPI schema here: https://FQDN/univention/udm/openapi.json

1 Like
Mastodon