Search.../

listGroups( )

Lists groups.

Description

The listGroups() function returns a Promise that resolves to a list of up to 1,000 groups on your site. Sorts by default to _createdDate in descending order.

Notes:

  • For SECRET groups, only site admins, group admins, and group members can see a list of group and their content. However, if the suppressAuth option is set to true, all permissions are overwritten, and all site members (including non-group members) can see a list of groups and their content.
  • This function's parameters are positional, and must be specified in the sequence shown in the syntax below. When specifying a parameter, use null as a placeholder for any unspecified parameters. For example, to specify limit only, call listGroups(paging, null). To specify supressAuth only, call listGroups(null, options).

Syntax

function listGroups([paging: Paging], [options: Options]): Promise<ListGroups>

listGroups Parameters

NAME
TYPE
DESCRIPTION
paging
Optional
Paging

Paging options.

options
Optional
Options

Authorization options.

Returns

Return Type:

Promise<ListGroups>
NAME
TYPE
DESCRIPTION
groups
Array<Group>

List of groups.

metadata
Metadata

Paging information.

Was this helpful?

Get a list of groups

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { groups } from 'wix-groups-backend';
3
4export const myListGroupsFunction = webMethod(Permissions.Anyone, () => {
5 return groups.listGroups()
6 .then((groupResults) => {
7 const groupResultsMemberCount = groupResults.groups[0].memberCount;
8 const groupResultsName = groupResults.groups[0].name;
9 return groupResults;
10 })
11 .catch((error) => {
12 console.error(error);
13 });
14});
15
16/* Promise resolves to:
17 * groups: [
18 * {
19 * "_id": "83636377-b415-4ebe-ba41-df338c5ad6b7"
20 * "name": "My Group 1"
21 * "slug": "my-group-1"
22 * "description": "Welcome to the group! You can connect with other members, get updates and share videos."
23 * "privacyStatus": "PUBLIC"
24 * "coverImage": {
25 * "imageUrl": "wix:image://v1/vcc6074e348009011fa9f2d29kk7~mv2.jpg/maple.jpg#originWidth=999&originHeight=240",
26 * "position": {
27 * "x": 44,
28 * "y": 90
29 * }
30 * }
31 * "memberCount": 83
32 * "settings": {
33 * "groupUpdatePostEnabled": true
34 * "membersCanApprove": false
35 * "membersCanInvite": true
36 * "showMemberList": true
37 * "welcomeMemberPostEnabled": true
38 * }
39 * "lastActivityDate": "Sun Sep 26 2021 08:23:23 GMT+0300"
40 * "_createdDate": "Tues January 22 2021 12:56:02 GMT+0300"
41 * "_updatedDate": "Fri October 2 2021 04:56:22 GMT+0300"
42 * "owner": "9ne8e9e1-d050-4c86-9684-e7f231600a34"
43 * },
44 * {
45 * "_id": "6ff5333-b477-4e9tt-ba4j-df338c5ad6221"
46 * "name": "My Group 2"
47 * "slug": "my-group-2"
48 * "description": "Welcome to the group! You can connect with other members, get updates and share videos."
49 * "privacyStatus": "PRIVATE"
50 * "coverImage": {
51 * "imageUrl": "wix:image://v1/dn33kcc6074e348009011fa9f2d29k03~mv2.jpg/fire.jpg#originWidth=287&originHeight=100",
52 * "position": {
53 * "x": 55,
54 * "y": 166
55 * }
56 * }
57 * "memberTitle": "Friends"
58 * "memberCount": 68
59 * "settings": {
60 * "groupUpdatePostEnabled": true
61 * "membersCanApprove": true
62 * "membersCanInvite": true
63 * "showMemberList": false
64 * "welcomeMemberPostEnabled": true
65 * }
66 * "lastActivityDate": "Thurs Nov 12 2020 11:13:03 GMT+0300"
67 * "_createdDate": "Wed May 14 2020 10:05:20 GMT+0300"
68 * "_updatedDate": "Sun June 7 2020 09:07:33 GMT+0300"
69 * "owner": "abe5e4e1-d950-4c46-8884-e7f231600d67"
70 * }
71 * ],
72 * metadata:
73 * {
74 * "length": 2
75 * "tooManyToCount": false
76 * "totalCount": 2
77 * }
78 */
Get a list of groups using options

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { groups } from 'wix-groups-backend';
3
4export const myListGroupsFunction = webMethod(Permissions.Anyone, async (paging, options) => {
5 try {
6 const groupResults = await groups.listGroups(paging, options);
7 const groupResultsMemberCount = groupResults.groups[0].memberCount;
8 const groupResultsName = groupResults.groups[0].name;
9 return groupResults;
10 } catch (error) {
11 console.error(error);
12 }
13});
14
15/* Promise resolves to:
16 * groups: [
17 * {
18 * "_id": "83636377-b415-4ebe-ba41-df338c5ad6b7"
19 * "name": "My Group 2"
20 * "slug": "my-group-2"
21 * "description": "Welcome to the group! You can connect with other members, get updates and share videos."
22 * "privacyStatus": "PUBLIC"
23 * "memberCount": 68
24 * "settings": {
25 * "groupUpdatePostEnabled": true
26 * "membersCanApprove": false
27 * "membersCanInvite": true
28 * "showMemberList": true
29 * "welcomeMemberPostEnabled": true
30 * }
31 * "lastActivityDate": "Sun Sep 26 2021 08:23:23 GMT+0300"
32 * "_createdDate": "Tues January 22 2021 12:56:02 GMT+0300"
33 * "_updatedDate": "Fri October 2 2021 04:56:22 GMT+0300"
34 * "owner": "9ne8e9e1-d050-4c86-9684-e7f231600a34"
35 * },
36 * {
37 * "_id": "6ff5333-b477-4e9tt-ba4j-df338c5ad6221"
38 * "name": "My Secret Group"
39 * "slug": "5D3yTX"
40 * "description": "This is my secret group."
41 * "privacyStatus": "SECRET"
42 * "coverImage": {
43 * "imageUrl": "wix:image://v1/ff9074e348009011fa9f2d2961b~mv2.jpg/oak.jpg#originWidth=400&originHeight=900",
44 * "position": {
45 * "x": 80,
46 * "y": 77
47 * }
48 * }
49 * "memberCount": 10
50 * "settings": {
51 * "groupUpdatePostEnabled": true
52 * "membersCanApprove": true
53 * "membersCanInvite": true
54 * "showMemberList": false
55 * "welcomeMemberPostEnabled": true
56 * }
57 * "lastActivityDate": "Thurs Nov 12 2020 11:13:03 GMT+0300"
58 * "_createdDate": "Wed May 14 2020 10:05:20 GMT+0300"
59 * "_updatedDate": "Sun June 7 2020 09:07:33 GMT+0300"
60 * "owner": "abe5e4e1-d950-4c46-8884-e7f231600d67"
61 * }
62 * ],
63 * metadata:
64 * {
65 * "length": 2
66 * "tooManyToCount": false
67 * "totalCount": 2
68 * }
69 */