> To build a Wix site agentically, or add Wix features like bookings or a store to a site you already have, follow https://www.wix.com/headless/skill.md
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# ListGroupsByResource

# Package: members

# Namespace: GroupsService

# Method link: https://dev.wix.com/docs/api-reference/crm/members-contacts/members/access-groups/list-groups-by-resource.md

## Permission Scopes:
Read Access Groups: SCOPE.DC-IDENTITY.READ-ACCESS-GROUPS

## Introduction

Retrieves the groups of a specific type that grant access to a site resource.

Groups are what the site's dashboard calls member roles, including the roles that apps create,
such as one for each pricing plan. Site members get access to a resource through the groups they belong to.

For example, to find the pricing plans that protect a members-only page,
specify the page ID as `resourceId` and `"plan"` as `type`.
For groups of type `"plan"`, the group ID is the pricing plan ID.

The response includes groups of the current site, sorted by title.
The built-in Admin and Member groups aren't included.

The list is empty if no group of the requested type grants access to the resource,
for example for a page that every visitor can view, or for a resource of another site.

Site visitors and members can retrieve groups of type `"plan"` and no other type.

---

## REST API

### Schema

```
 Method: listGroupsByResource
 Description: Retrieves the groups of a specific type that grant access to a site resource.  Groups are what the site's dashboard calls member roles, including the roles that apps create, such as one for each pricing plan. Site members get access to a resource through the groups they belong to.  For example, to find the pricing plans that protect a members-only page, specify the page GUID as `resourceId` and `"plan"` as `type`. For groups of type `"plan"`, the group GUID is the pricing plan GUID.  The response includes groups of the current site, sorted by title. The built-in Admin and Member groups aren't included.  The list is empty if no group of the requested type grants access to the resource, for example for a page that every visitor can view, or for a resource of another site.  Site visitors and members can retrieve groups of type `"plan"` and no other type.
 URL: https://www.wixapis.com/members-groups/v1/groups/by-resource/{resourceId}
 Method: GET
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  resourceId, type
 Method parameters: 
   param name: paging | type: CursorPaging    
        - name: limit | type: integer | description: Maximum number of items to return in the results.  | validation: minimum 0, maximum 100, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 16000
   param name: resourceId | type:   none | required: true 
   query param name: type | type: type | description: Type of groups to retrieve. The type is set by the app that created the groups, for example `"plan"` for groups created by Wix Pricing Plans.  The value is case-insensitive. If no group of this type grants access to the resource, the list is empty. Some type values are reserved and fail with `INVALID_ARGUMENT`. Site visitors and members can specify `"plan"` and no other value. Other values fail with `PERMISSION_DENIED`. | required: true | validation: maxLength 50
 Return type: ListGroupsByResourceResponse
  - name: groups | type: array<GroupInfo> | description: Groups of the requested type that grant access to the resource, sorted by title.  
     - name: id | type: string | description: Role GUID.  | read-only: true | validation: format GUID
     - name: title | type: string | description: Role name as defined in the site's [Member Permissions](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Fmember-permissions/roles) page or one of `"Admin"` or `"Member"`.  | validation: maxLength 50
     - name: description | type: string | description: Role description, if defined in the site's dashboard.  | validation: maxLength 1500
     - name: color | type: Color | description: Role color, as defined in the site's [Member Permissions](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Fmember-permissions/roles) page.  One of:  - `"DARK_BLUE"` - `"LIGHT_BLUE"` - `"TEAL"` - `"LIGHT_GREEN"` - `"YELLOW"` - `"ORANGE"` - `"RED"` - `"VIOLET"` - `"PURPLE"`  
         - enum: UNDEFINED, DARK_BLUE, LIGHT_BLUE, TEAL, LIGHT_GREEN, YELLOW, ORANGE, RED, VIOLET, PURPLE
     - name: type | type: string | description: Role type, set by the app that created the role, for example `"plan"` for roles created by Wix Pricing Plans. Empty for roles created on the site.  | validation: maxLength 50
     - name: createdDate | type: string | description: Date and time the role was created.  | read-only: true | validation: format date-time
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: cursors | type: Cursors | description: Cursor strings that point to the next page, previous page, or both.  
        - name: next | type: string | description: Cursor string pointing to the next page in the list of results.  | validation: maxLength 16000
        - name: prev | type: string | description: Cursor pointing to the previous page in the list of results.  | validation: maxLength 16000
     - name: hasNext | type: boolean | description: Whether there are more pages to retrieve following the current page.  

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code:  | Description: The `type` value is reserved, or `paging.cursor` isn't a cursor returned by a previous call.
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code:  | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions. Site visitors and members can specify `"plan"` as `type` and no other value.


```

### Examples

### List the pricing plan groups that grant access to a page
Retrieves the groups of type `"plan"` that grant access to a members-only page. For groups of type `"plan"`, the group ID is the pricing plan ID.

```curl
curl -X GET \
'https://www.wixapis.com/members-groups/v1/groups/by-resource/c1dmp?type=plan&paging.limit=10' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.membersAccess.accessGroups.listGroupsByResource(resourceId, type, options)
 Description: Retrieves the groups of a specific type that grant access to a site resource.  Groups are what the site's dashboard calls member roles, including the roles that apps create, such as one for each pricing plan. Site members get access to a resource through the groups they belong to.  For example, to find the pricing plans that protect a members-only page, specify the page GUID as `resourceId` and `"plan"` as `type`. For groups of type `"plan"`, the group GUID is the pricing plan GUID.  The response includes groups of the current site, sorted by title. The built-in Admin and Member groups aren't included.  The list is empty if no group of the requested type grants access to the resource, for example for a page that every visitor can view, or for a resource of another site.  Site visitors and members can retrieve groups of type `"plan"` and no other type.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  resourceId, type
 Method parameters: 
   param name: resourceId | type: string | description: GUID of the resource to retrieve groups for.  This is the GUID that groups grant access to, usually a site page GUID, such as `"c1dmp"`. Page GUIDs aren't GUIDs. | required: true | validation: maxLength 50
   param name: type | type: string | description: Type of groups to retrieve. The type is set by the app that created the groups, for example `"plan"` for groups created by Wix Pricing Plans.  The value is case-insensitive. If no group of this type grants access to the resource, the list is empty. Some type values are reserved and fail with `INVALID_ARGUMENT`. Site visitors and members can specify `"plan"` and no other value. Other values fail with `PERMISSION_DENIED`. | required: true | validation: maxLength 50
   param name: options | type: ListGroupsByResourceOptions  none  
        - name: paging | type: CursorPaging | description: Cursor paging options.  A `limit` of `0` returns the default page size.  Default: `50` groups per page  
           - name: limit | type: integer | description: Maximum number of items to return in the results.  | validation: minimum 0, maximum 100, format int32
           - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 16000
 Return type: PROMISE<ListGroupsByResourceResponse>
  - name: groups | type: array<GroupInfo> | description: Groups of the requested type that grant access to the resource, sorted by title.  
     - name: _id | type: string | description: Role GUID.  | read-only: true | validation: format GUID
     - name: title | type: string | description: Role name as defined in the site's [Member Permissions](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Fmember-permissions/roles) page or one of `"Admin"` or `"Member"`.  | validation: maxLength 50
     - name: description | type: string | description: Role description, if defined in the site's dashboard.  | validation: maxLength 1500
     - name: color | type: Color | description: Role color, as defined in the site's [Member Permissions](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Fmember-permissions/roles) page.  One of:  - `"DARK_BLUE"` - `"LIGHT_BLUE"` - `"TEAL"` - `"LIGHT_GREEN"` - `"YELLOW"` - `"ORANGE"` - `"RED"` - `"VIOLET"` - `"PURPLE"`  
         - enum: UNDEFINED, DARK_BLUE, LIGHT_BLUE, TEAL, LIGHT_GREEN, YELLOW, ORANGE, RED, VIOLET, PURPLE
     - name: type | type: string | description: Role type, set by the app that created the role, for example `"plan"` for roles created by Wix Pricing Plans. Empty for roles created on the site.  | validation: maxLength 50
     - name: _createdDate | type: Date | description: Date and time the role was created.  | read-only: true 
  - name: pagingMetadata | type: CursorPagingMetadata | description: Paging metadata.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: cursors | type: Cursors | description: Cursor strings that point to the next page, previous page, or both.  
        - name: next | type: string | description: Cursor string pointing to the next page in the list of results.  | validation: maxLength 16000
        - name: prev | type: string | description: Cursor pointing to the previous page in the list of results.  | validation: maxLength 16000
     - name: hasNext | type: boolean | description: Whether there are more pages to retrieve following the current page.  

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code:  | Description: The `type` value is reserved, or `paging.cursor` isn't a cursor returned by a previous call.
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code:  | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions. Site visitors and members can specify `"plan"` as `type` and no other value.


```

### Examples

### List the pricing plan groups that grant access to a page
For groups of type "plan", the group ID is the pricing plan ID.

```javascript
import { accessGroups } from "@wix/members-access";

async function listGroupsByResource() {
  const response = await accessGroups.listGroupsByResource("c1dmp", "plan", {
    paging: { limit: 10 },
  });
}

/* Promise resolves to:
 * {
 *   "groups": [
 *     {
 *       "_id": "3e1f9a52-7c4d-4b8e-9f20-6a5d1c8b7e43",
 *       "title": "Gold Membership",
 *       "description": "Full access to all premium content.",
 *       "color": "YELLOW",
 *       "type": "plan",
 *       "_createdDate": "2024-03-12T09:15:42.000Z"
 *     },
 *     {
 *       "_id": "b84c2d17-5e9a-4f31-a6c8-0d7e3f2b9a15",
 *       "title": "Silver Membership",
 *       "description": "Access to selected premium content.",
 *       "color": "LIGHT_BLUE",
 *       "type": "plan",
 *       "_createdDate": "2024-03-12T09:18:05.000Z"
 *     }
 *   ],
 *   "pagingMetadata": {
 *     "count": 2,
 *     "hasNext": false
 *   }
 * }
 */

```

### listGroupsByResource (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { accessGroups } from '@wix/members-access';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { accessGroups },
  // Include the auth strategy and host as relevant
});


async function listGroupsByResource(resourceId,type,options) {
  const response = await myWixClient.accessGroups.listGroupsByResource(resourceId,type,options);
};
```

---