Help with Groups Query API for Members

Hi All

I’m trying to query a group using the Groups API. I want to see if a member exists within a specific group. If they do, return them and their role.

I’m hoping someone could write up a code example using the below dummy inputs. A link to the Velo docs wouldn’t help, unfortunately. I’ve been trying all day to figure it out!

I tried WIX Ai in the IDE and also ChatGPT to no avail… it’s starting to drive me crazy!

This is the set-up:

a) A group with the ID: 123
b) A user with the ID: ABC

What I want to know:

  1. Is User ABC a member of Group 123

If User is a member, return output similar to below (taken from Velo docs)

“joinedDate”: “Sun Aug 01 2021 12:32:35 GMT+0300”
“memberId”: “437cd3db-e9be-4980-93c1-a6d767a11050”
“role”: {“value”: “ADMIN”}

Thanks in advance!

In all sincerity, if the Wix AI, ChatGPT and the Velo doc example codes were not helpful then another piece of “example code” from a person may not be helpful to you either. It’s not just about “having a code” it’s knowing how and where to apply it. It’s knowing the logic of how to configure the moving pieces and where they are triggered, etc.

If this is something beyond your code expertise (or if you are on a time crunch), you may consider hiring a coder to either do the work for your or teach you how to do it based on your current set up and work flow.

You can either post something in the Collaboration category or browse the Wix Marketplace to find someone available for work: https://www.wix.com/marketplace/

Besides all that, this forum is not meant to be used to request “on demand” code to be written for you. This is a place to learn, guide and support the community in helping themselves at their own pace. Some people learn in a few minutes, others in a few weeks. It’s a self-service community, not a “do it for me” community. The knowledge people choose to share here is by their own free will not because of obligation.

Well, i do not see any code you provide about how much efforts you put on, to achieve your aim.

However, if you are working with Wix-Groups and you want to know if a USER is a MEMBER of a specific group, what you should know first?

1) Which groups are available in total? → Groups-Listing…

import { Permissions, webMethod } from 'wix-web-module';
import { groups } from 'wix-groups-backend';

export const myListGroupsFunction = webMethod(Permissions.Anyone, () => {
  return groups.listGroups()
    .then((groupResults) => {
      const groupResultsMemberCount = groupResults.groups[0].memberCount;
      const groupResultsName = groupResults.groups[0].name;
      return groupResults;
    })
    .catch((error) => {
      console.error(error);
    });
});

The results could look like…

/* Promise resolves to:
 * groups: [
 *  { 
 *    "_id": "83636377-b415-4ebe-ba41-df338c5ad6b7"
 *    "name": "My Group 1"
 *    "slug": "my-group-1"
 *    "description": "Welcome to the group! You can connect with other members, get updates and share videos."
 *    "privacyStatus": "PUBLIC"
 *    "coverImage": {
 *      "imageUrl": "wix:image://v1/vcc6074e348009011fa9f2d29kk7~mv2.jpg/maple.jpg#originWidth=999&originHeight=240",
 *      "position": {
 *        "x": 44,
 *        "y": 90
 *      }
 *    }
 *    "memberCount": 83
 *    "settings": {
 *      "groupUpdatePostEnabled": true
 *      "membersCanApprove": false
 *      "membersCanInvite": true
 *      "showMemberList": true
 *      "welcomeMemberPostEnabled": true
 *    }
 *    "lastActivityDate": "Sun Sep 26 2021 08:23:23 GMT+0300"
 *    "_createdDate": "Tues January 22 2021 12:56:02 GMT+0300"
 *    "_updatedDate": "Fri October 2 2021 04:56:22 GMT+0300"
 *    "owner": "9ne8e9e1-d050-4c86-9684-e7f231600a34"
 *  },
 *  {
 *    "_id": "6ff5333-b477-4e9tt-ba4j-df338c5ad6221"
 *    "name": "My Group 2"
 *    "slug": "my-group-2"
 *    "description": "Welcome to the group! You can connect with other members, get updates and share videos."
 *    "privacyStatus": "PRIVATE"
 *    "coverImage": {
 *      "imageUrl": "wix:image://v1/dn33kcc6074e348009011fa9f2d29k03~mv2.jpg/fire.jpg#originWidth=287&originHeight=100",
 *      "position": {
 *        "x": 55,
 *        "y": 166
 *      }
 *    }
 *    "memberTitle": "Friends"
 *    "memberCount": 68
 *    "settings": {
 *      "groupUpdatePostEnabled": true
 *      "membersCanApprove": true
 *      "membersCanInvite": true
 *      "showMemberList": false
 *      "welcomeMemberPostEnabled": true
 *    }
 *    "lastActivityDate": "Thurs Nov 12 2020 11:13:03 GMT+0300"
 *    "_createdDate": "Wed May 14 2020 10:05:20 GMT+0300"
 *    "_updatedDate": "Sun June 7 2020 09:07:33 GMT+0300"
 *    "owner": "abe5e4e1-d950-4c46-8884-e7f231600d67"
 *  }
 * ],
 * metadata: 
 * { 
 *   "length": 2
 *   "tooManyToCount": false
 *   "totalCount": 2
 * }
 */

2) You could expand the functionality of this shown code to filter out DATA of a specific group --> in your case ---> **GROUP-123**

This could be done by simply adding some if-else-conditions.

  1. You also could get a specific group by ID…
import { Permissions, webMethod } from 'wix-web-module';
import { groups } from 'wix-groups-backend';

// Sample groupId value:
// 'fc3df3c1-36b2-4279-8be1-8e72a05a88c8'
//
// Sample options value:
// {
//   suppressAuth: true
// }

export const myGetGroupFunction = webMethod(Permissions.Anyone, async (groupId, options) => {
  try {
    const getGroupResults = await groups.getGroup(groupId, options);
    const getGroupResultsName = getGroupResults.name;
    const getGroupResultsDescription = getGroupResults.description;
    return getGroupResults;
  } catch (error) {
    console.error(error);
  }
});

Getting all the data of the specific group, but this for again you first have to know the ID → result → first have to list all groups.

  1. Once you have found the right group → you can list all of its Group-Members…
    listGroupMembers - Velo API Reference - Wix.com

So as you can see, you did not provide anything about all these processes and itermediate steps, needed to get what you want.

1 Like

Hi @CODE-NINJA

Thanks for the reply. Sorry, I probably didn’t explain myself very well.

I’ve managed to get all the details for the Group and Member already. I have also used queryGroupMembers - Velo API Reference - Wix.com to get the group members, which also worked. However, it only returns a max of 100 members, and the ‘supported filters & sorting’ adjacent to it only stated filters for “roles” and “joinedDate”.

So, I was trying to figure out how to filter it by Group and Member to return only the person I need (in case there is over 100 people in the group). However, I’ve figured it out now. It let me filter by “.eq(“siteMemberId”, memberId)” as well.

import { members } from 'wix-groups-v2';

export function myQueryGroupMembersFunction() {
  return members.queryGroupMembers()
  **.eq("siteMemberId", memberId)**
    .find()
    .then((queryResults) => {
      const items = results.items;
      const firstItem = items[0];

      return items;
    })
    .catch((error) => {
      console.error(error);
    });
}

Many thanks!

1 Like