I am trying to use the UCS REST API to move an existing user from one OU to another.
For testing, I am using this cURL command: curl -X PUT -H "Accept: application/json" -H "Content-Type: application/json" -H 'If-Match: "4ec61010c15aef4d59e3746aa6bdfb531f88b9e9"' 'https://user:password@ucs-server.org/univention/udm/users/user/uid%3Dusername%2Cou%3DSOURCE%2Cou%3Dtwo%2Cou%3Dthree%2Cdc%3Dcity%2Cdc%3Dorg%2Cdc%3Dde' --data @mydata.json
The “dn” describes the user as it is now, and “position” is adjusted to reflect the new location where the user should be moved to.
Unfortunately, this does not work (user is not moved) and this is what I get as response: {"finished": false, "errors": false, "_links": {"curies": [{"href": "https://ucs-server.org/univention/udm/relation/{rel}", "name": "udm", "templated": true}]}, "id": "42465069-d8b6-4315-81a4-f42d91d47ffc"}
So…
First question: what is it this response is trying to tell me?
And second question: How do I move a user instead?
your request ist correct. You are getting a HTTP 202 Accepted response. As moving objects may take longer than e.g. HTTP request timeouts this is an asynchronous operation. The response contains a Location header with a temporary URL which tells you the status. This again gives you a 3XX redirection to the same URL with a Retry-After header which specifies the time to wait between following the redirect. If the operation is finished on server side you are getting a redirection to the moved object in the new location.
Thanks very much for the speedy reply! Good to know I am not doing something completely stupid (yet).
I am not very experienced with REST APIs and mean no offense, but three requests with incremental header data just to do a simple ldapmodify with changetype: modrdn seems rather excessive. Why does moving to an OU take so much longer that it warrants such a complicated staging?
Isn’t there a more direct way to move a user to a different OU?
no, there is currently no more efficient way. This is because we currently don’t differentiate what kind of object is moved. Moving a whole OU or CN is more than just a modrdn as it moves also all sub-objects. If there are 1000 objects underneath we would run into timeout problems.
Moving entire OUs being slow and timing out → yes, that makes a lot more sense to me now, thank you for the clarification!
And thank you for creating the report to improve this. I wholeheartedly agree that moving an individual user could be more streamlined. After all, how often do you need to automate moving entire OUs in daily work?
(I just tried to add myself to the bug report by creating a new account but did not receive any email…)
now that I had some more time to look more into this I need to come back to you, as the response I am getting is 201 (created), not 202 (accepted).
I was hoping that setting the PHP curl options to $options[CURLOPT_FOLLOWLOCATION] = true; would solve my issues, but apparently this will only work for 3xx response codes…
it’s not a redirection but an async operation which is started. The tools/libraries should learn to also provide functionality to follow redirects from 201 and 202 Location headers.