Sign in to submit new ideas and vote
Get Started

Generate list of current group memberships for a given user in Bridge

I would like to be able to make an API call in Bridge to generate a list of all groups/groupIDs that a user is a member of. To my knowledge, this can only be done for me as the "current user" at this time.

2
2 votes

Idea Submitted · Last Updated

Comments

  • Brian_Richardson
    Brian_Richardson Overachievers Alumni
    edited 04/05/24

    Unfortunately there isn't an easy way to do this over a single endpoint. As you've seen, getting a user doesn't provide the groups. Getting a group provides the members, but it's not a filterable/searchable list.

    I'm assuming you want to sweep down a list of users and find this for a set of people?

    Without using Javascript, you could do this natively in Bridge like below. Warning though, it will be slow.

    PARENT WORKFLOW

    1. Get the sheet that contains a list of users that you want to check. Alternatively, Call API to get a list of users from the account (GET /users).
    2. API Call to Get list of groups (GET /groups)
    3. Run child workflow 1, setting Number of Runs to be the array containing the list of users. The child will run once for each row / user and will pass through the information from that row or user object to the child. Set the Entities to contain the data from your list of groups, so that each time the child runs it has the list of groups to check.

    CHILD WORKFLOW 1

    1. Run Child workflow 2, setting Number of Runs to be the array of groups from {{runtime.entities}}, and set Entities to be the user data for the single user that initiated the child workflow {{runtime.data}}. Remember it's running this once for each user.

    CHILD WORKFLOW 2

    1. API Call to Get the group passed in by Child Workflow 1 in the {{runtime.data}}. This child workflow will run once for each group.
    2. Contains Junction to check the "members" array returned from step 1 and see if it contains the email address of the user that you're looking for, which you're getting from {{runtime.entities}}.
    3. If found - you want to put that group ID and group name somewhere. You could do an Update Row and paste the data into a sheet, but it'll overwrite each time it finds a group. It may be better to do an Add Row and set the parent as the row with the user's email address, adding the found group name/id into the new row. That way, you'll end up with a sheet with the username on a row and then an indented set of rows, each with a group name/ID.

    JAVASCRIPT

    • Javascript could help you run this much faster, but it's a little more complicated to set up. If I was doing this though, I would probably change it up and do a single parent-child, with the parent getting a list of groups and users and then the child getting the group membership for each group. In the child a quick javascript could search for all the users in the group membership array, and for the ones that are found could return the group information and the row ID of the user's data in Smartsheet, to pass to a next step to Add rows and capture the information for all the users found. ChatGPT can help write the Javascript, but you'll need to play a bit with this to get it working the way you want it to.


    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN

  • Brian_Richardson
    Brian_Richardson Overachievers Alumni

    BTW, to see how to write Javascript to return a formatted array to do Add Row - check the post here. You may or may not need the "chunking" function described in this, and don't need the Resource Management pieces, but you'll see in the Javascript code that there's a section that takes the data and formats it into an array of row objects to pass along to Add Rows. Your row objects, instead of using toTop: true as the row location specifier, should use the {"parentId": xxxxx, "toBottom": true} format to insert the rows underneath the row that has your user listed in a sheet. You'll need the rowId for parentId, that comes from your user data.

    https://community.smartsheet.com/discussion/97621/use-javascript-in-bridge-to-efficiently-import-data-from-an-api

    BRIAN RICHARDSON | PMO TOOLS AND RESOURCES | HE|HIM

    SEATTLE WA, USA

    IRON MOUNTAIN