Adding user to organisation unit

Hi there !

We are trying to add a user to an organisation unit using the API. We tried several different approaches, calling on URL:

/api/users/<my_user_id>?mergeMode=MERGE&importStrategy=CREATE_AND_UPDATE

PATCH

Patch is the action used by user management console, we we tried that one first.

Patch works fine, but replaces the existing list of orgUnit (we just want to add one) by the one we want to add.

Going for this solution would force us to make a GET call before this one to get the existing list of organisation units. It would also not be very secure in a multithreaded environment but that’s minor, so I’d like to avoid it if we can.

POST
"{"httpStatus":"Method Not Allowed","httpStatusCode":405,"status":"ERROR","message":"Request method 'POST' not supported"}"

I think this settles it.

PUT

we try to send this body:

{
    "organisationUnits": [
        {
            "id": "<my_orgunit_id>"
        }
    ],
    "dataViewOrganisationUnits": [
        {
            "id": "<my_orgunit_id>"
        }
    ],
    "teiSearchOrganisationUnits": [
        {
            "id": "<my_orgunit_id>"
        }
    ]
}

We also got an error stating:
“message”:“User needs to have at least one user role associated with it”,

We don’t want to change user roles or anything, so I’m not sure why we would want to have user roles in our payload. I’m afraid it’s asking for more info because it’s planning to replace the whole user.

Question

Can someone confirm what would be the best strategy for just assigning a user to a facility ?

Thanks a lot !

Hi @Arnaud_Demarcq

I think your best option is to use the PATCH request as for the PUT request, you said it right, it will need to replace the whole user.

Maybe there’s another approach to the issue you are trying to solve. :slight_smile: