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 thesuppressAuth
option is set totrue
, 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 specifylimit
only, calllistGroups(paging, null)
. To specifysupressAuth
only, calllistGroups(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';34export 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});1516/* 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": 9029 * }30 * }31 * "memberCount": 8332 * "settings": {33 * "groupUpdatePostEnabled": true34 * "membersCanApprove": false35 * "membersCanInvite": true36 * "showMemberList": true37 * "welcomeMemberPostEnabled": true38 * }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": 16655 * }56 * }57 * "memberTitle": "Friends"58 * "memberCount": 6859 * "settings": {60 * "groupUpdatePostEnabled": true61 * "membersCanApprove": true62 * "membersCanInvite": true63 * "showMemberList": false64 * "welcomeMemberPostEnabled": true65 * }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": 275 * "tooManyToCount": false76 * "totalCount": 277 * }78 */
Get a list of groups using options
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { groups } from 'wix-groups-backend';34// Sample paging value:5// {6// limit: 2,7// skip: 18// }9//10// Sample options value:11// {12// suppressAuth: true13// }1415export 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});2526/* 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": 6835 * "settings": {36 * "groupUpdatePostEnabled": true37 * "membersCanApprove": false38 * "membersCanInvite": true39 * "showMemberList": true40 * "welcomeMemberPostEnabled": true41 * }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": 7758 * }59 * }60 * "memberCount": 1061 * "settings": {62 * "groupUpdatePostEnabled": true63 * "membersCanApprove": true64 * "membersCanInvite": true65 * "showMemberList": false66 * "welcomeMemberPostEnabled": true67 * }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": 277 * "tooManyToCount": false78 * "totalCount": 279 * }80 */