UserGroups bulk update

Hi everyone!

DHIS 2.40.3

Usually I assigne users to userGroups in the BIF template, like this:
image

But sometimes after bulk load user groups are still empty…

In this scenario when I try to use BIF template again, I get an error:

Then, I tried to use a method which I learned about from @Ulanbek (for bulk updating passwords)

So I Used the Postman app to get the list of users for a specific region with userGroup field:
https://{{URL}}/api/users.json?paging=false &filter=organisationUnits.path:like:UCh8L8MFPQr&fields=,sharing,userCredentials[,!access,!lastUpdatedBy,!sharing],userGroups

Then I used find and replace function to update all users with user group IDs,

like this:

image

Then I saved the updated Json file and tried to use import/export APP:

This is DRY RUN results:

With Import I get the error:

This is how it looks like in my Json file:

image

I must be doing smth wrong.

What is the best way to bulk update user groups?

Hi @m.siusko

Get all attributes from users, and change user group ID to desired

1 Like

Hi @Ulanbek ,
Could you please give me an example of how to get all attributes from users for a specific region? Import/export app gives me all users of the system.
When I try to use the GET request in the postman (e.g. https://{{URL}}/api/users.json?paging=false &filter=organisationUnits.path:like:UCh8L8MFPQr), It returns me only the list of Display Names and IDs.

https://{{URL}}/api/users.json?fields=*&paging=false &filter=organisationUnits.path:like:UCh8L8MFPQr

1 Like

Tried it. Yes it gave me all users attributes. TY!

I uptated user groups for all the users. Like this:
image
And successfully used import/export APP:


But still, my users dont have assigned userGroups((

And my get request still gives me blanks:
image

So only manual assigning from UI works for me.
Thats why I am wondering, if it is some kind of a bug, or I am doing smth wrong((

Hi @m.siusko

According to the documentation:

In the user creation payload, user groups are only supported when importing or POSTing a single user at a time. If you attempt to create more than one user while specifiying user groups, you will not recieve an error and the users will be created but no user groups will be assigned. This is by design and is limited because of the many-to-many relationship between users and user groups whereby user groups is the owner of the relationship. To update or create mulitple users and their user groups, consider a program to POST one at a time, or POST all users followed by another action to update their user groups while specifiying the new user’s identifiers.

Therefore I refer you to the Method #2 - using Postman scripts in the guidance which I created here Bulk passwords update - #2 by Ulanbek.

1 Like