Start a new topic

How to add users to an exiting group

Hi, 


We want to add users to a existing group.


We know that we can add users when creating group, but in our case we want to create a group first with some users, and then add users to that group.


Let me explain,


We are creating a collection for a doctor who creates patients entries, but also we will grant doctors to add a secretary role account so her can add users and data (appointments), that doctor can see as well. So doctor and secretary belong to a group  but the entrance of the latter is made after the group has being made. 


We saw that this can be done using REST-API:


https://support.kinvey.com/support/discussions/topics/5000041300?page=1



but we could not find an example code to do that. Can share a link or paste a sample code in order to understand how to add users in a group using REST API.


We can create a group using API, and add list of existing users, but we need add more users coming from registration to this group.


Thanks for help in advance,



Hello MedPike,


You can find information about updating user groups in the Users guide of our REST API section in our guides, which is available over here: http://devcenter.kinvey.com/rest/guides/users#usergroupsupdate


Please let me know what other questions you have after reviewing this material.


Thanks,

Thanks Damien,


The issue is that we can update group and send the file <JSON-Document-representing-UserGroup>, but when we made this we replace all existing users.



for instance:



Let says that we have a group called "Secretary" and has 1 user: (ID:3)


GET


{
 "_id": "Secretary",
 "users": {
   "_type": "KinveyRef",
   "_id": "3",
   "_collection": "user"
 },
 "_acl": {
   "creator": "asasdasd"
 },
 "_kmd": {
   "lmt": "2015-08-11T20:13:20.524Z",
   "ect": "2015-07-27T04:02:03.960Z"
 }
}


the we run the following code to add new user 4 ID the group:



PUT

{
 "_id": "Secretary",
 "users": {
               "_type": "KinveyRef",
               "_id": "4",
               "_collection": "user"
 }
}



but user with ID; 3 disappeared and its replaced by ID:4



see:



{
 "_id": "Secretary",
 "users": {
   "_type": "KinveyRef",
   "_id": "4",
   "_collection": "user"
 },
 "_acl": {
   "creator": "kid_Z10M63523"
 },
 "_kmd": {
   "lmt": "2015-08-11T20:21:47.361Z",
   "ect": "2015-07-27T04:02:03.960Z"
 }
}


What we want to do is not replacing existing users in the group when adding new ones....



Have a sample code to do make happen?.



Medpike,


You would first get the list of users using a get, then manually append and upload the modified json document to the backend.


Thanks,

Login or Signup to post a comment