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