Forum Discussion

mkuehnkhoros's avatar
5 years ago

Bulk Add Users to Group Hubs via API Calls?

Is there any way to programmatically bulk add users to multiple group hubs using API calls?Ideally, I'd like to take a CSV data with columns "group_hub_id, user_id, role" and iterate over it, adding each user to the group if they aren't already in that group, but I don't see a direct way to do that.

So far, all I've found would be to either manually upload a CSV through the admin for each group (which would involve more manual work) or possibly to use the existing API calls to invite a user and then accept the invitation on their behalf (which seems tedious and the user shouldn't be notified that this process is taking place, and perhaps isn't even possible).

There are other steps we'd automate into this process, but this would be the first step, and without it, the rest of the process is blocked.

Any ideas?

Thanks,
Matthew

  • Hi mkuehnkhoros 

    Some good news on this, you can actually do this, but you have to bypass the membership API in v2.

    You essentially need to call the APIv1 endpoint and add users i.e:

    https://yourcommunity.com/restapi/vc/roles/id/<roleid>/users/add?role.user=id/<userid>&restapi.session_key=<apiKey>
    
    you can use other varients of this but in my example above lest assume we want to add user 52 to the owner role for Group Hub MyHub, which has a role id of 216.
    
    You would make a post call like this:
    https://yourcommunity.com/restapi/vc/roles/id/216/users/add?role.user=id/52&restapi.session_key=dkldjlkfjgdlkfjdflkjg4989438u

     

     

  • Hi mkuehnkhoros 

    Some good news on this, you can actually do this, but you have to bypass the membership API in v2.

    You essentially need to call the APIv1 endpoint and add users i.e:

    https://yourcommunity.com/restapi/vc/roles/id/<roleid>/users/add?role.user=id/<userid>&restapi.session_key=<apiKey>
    
    you can use other varients of this but in my example above lest assume we want to add user 52 to the owner role for Group Hub MyHub, which has a role id of 216.
    
    You would make a post call like this:
    https://yourcommunity.com/restapi/vc/roles/id/216/users/add?role.user=id/52&restapi.session_key=dkldjlkfjgdlkfjdflkjg4989438u

     

     

    • Claudius's avatar
      Claudius
      Boss

      allensmith81 How do I obtain the role ID of a group hub membership role? I know for normale community roles I can get it from the role admin links, but I can't find an equivalent for group hub roles

      • JoshuaBr's avatar
        JoshuaBr
        Khoros Staff

        Hi Claudius,

        Using APIv2 you could run a query such as

        SELECT id FROM roles WHERE node.id = 'grouphub:welcome_center' AND users.id = '15665'

         and in the results you would see the IDs for that user for that grouphub.  From the test I ran, here is a snippet of the results:

        "items" : [ {
              "type" : "role",
              "id" : "g:welcome_center:Member"

         

        User 15665 is has a role id of "g:welcome_center:Member" for the Grouphub "welcome_center".

        If you're looking to get all the possible roles for the Grouphub, simply remove the users.id constraint, like so

        SELECT id FROM roles WHERE node.id = 'grouphub:welcome_center'

        and you'll see results such as

            "items" : [ {
              "type" : "role",
              "id" : "g:welcome_center:Curator"
            }, {
              "type" : "role",
              "id" : "g:welcome_center:Inviter"
            }, {
              "type" : "role",
              "id" : "g:welcome_center:Member"
            }, {
              "type" : "role",
              "id" : "g:welcome_center:Owner"
            } ]