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

Copy Code
1import { groups } from 'wix-groups-backend';
2
3// Sample paging value:
4// {
5// limit: 2,
6// skip: 1
7// }
8//
9// Sample options value:
10// {
11// suppressAuth: true
12// }
13
14export function myListGroupsFunction(paging, options) {
15 return groups.listGroups(paging, options)
16 .then((groupResults) => {
17 const groupResultsMemberCount = groupResults.groups[0].memberCount;
18 const groupResultsName = groupResults.groups[0].name;
19 return groupResults;
20 })
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 */