You are not logged in.
Hi I am using GLPI 10.0.9 version,
I am LDAP for user creation,
After syncing users from LDAP to GLPI, I want to associate those users with a profile and a group.
I have use GET API-> server/apirest.php/user
partial response body part ->
{
"id": 14,
"name": “name@domain,
"password_last_update": null,
"realname": “lastname”,
"firstname": “firstname”,
"is_active": 1,
"auths_id": 1,
"authtype": 3,
"is_deleted": 0,
"profiles_id": 0,
"entities_id": 0,
"usertitles_id": 0,
"usercategories_id": 0,
"is_ids_visible": null,
"default_requesttypes_id": null,
"user_dn": "CN=firstname lastname,OU=somevalue,OU=somevalue,DC=somevalue,DC=somevalue,DC=somevalue,
"sync_field": “somevalue”,
"groups_id": 0,
"users_id_supervisor": 0,
}
here I am getting "groups_id" and "profiles_id",
But in POST API server/apirest.php/user/user_id I got response status code as 200
Please help me how to associate a group and profile to a user using APIs.
Thank you!
Offline
The groups_id and profiles_id fields in the User object correspond to the Default group and Default profile for the user and not a way to actually add new groups or profiles. Also, a POST request to /User would be to create a new User, not update it.
Profile assignments are represented by the Profile_User item type. To add an assignment, you would make a POST request to /apirest.php/Profile_User with a users_id, profiles_id, and entities_id property at least. If you want the assignment to apply to child entities, you should specify the is_recursive property as "1".
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
Hi,
Thank you for you response, it's working completely fine.
I want to add the API for adding groups to user:
/apirest.php/Group_User with a users_id, groups_id at least.
Also Please help me with the applymassiveAction API for assigning multiple users to a group and multiple users to a profile.
As the above API can associate a group and profile to a single user at a time.
Thank you!
Offline
The getMassiveActions and getMassiveActionParameters endpoints should provide the information you need to do that.
Additional examples (beyond what is in the documentation) can be found in the Pull Request that added the feature.
https://github.com/glpi-project/glpi/pull/9205
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
Hi,
Thank you for response
I have tried using the getMassiveAction Api -> GET apirest.php/getMassiveActions/user/
response (partial) ->
{
"key": "Group_User:add",
"label": "Associate to a group"
}
And I have tried getMassiveActionParameters API -> GET url/apirest.php/getMassiveActionParameters/user/Group_User:add
Response -> "BLANK", Status code - 200
Also I have tried applyMassiveAction API -> POST url/apirest.php/applyMassiveAction/user/Group_User:add
Request Body ->
{ "ids": [10,13,15],
"input":
{
"groups_id": 5,
"entities_id": 0
}
}
Response -> Status code ->477
{
"ok": 0,
"noaction": 0,
"ko": 3,
"noright": 0,
"messages": [
": Unable to get item"
]
}
I have also tried the same for getMassiveAction API for group -> GET apirest.php/getMassiveActions/group/
Same as above
So please help me how to associate groups and profiles to multiple users.
Offline
Are you using the correct casing for the itemtype name? It is "User" and "Group", not "user" and "group". The API is case sensitive with the types.
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline
Hi,
I have tried the APIs with "User", "Group" and "user", "group"
But still the same response in both the cases.
Also when using getMassiveAction Api -> GET url/apirest.php/getMassiveActions/user/,
Here "user" is used as item type name, and I got response and status code - 200
So please help me how to associate groups and profiles to multiple users.
Offline
Either do that with massive actions in the web interface or make a script that loops over the user IDs and make individual POST calls to create the User_Group and Profile_User items.
There is no advantage to using the massive action endpoints in this case over just creating the link items yourself.
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Offline