# Return all Contact Groups

> **GET** `https://api.us.nylas.com/v3/grants/{grant_id}/contacts/groups`

Source: https://developer.nylas.com/docs/reference/api/contacts/list-contact-groups/

(Not supported for EWS) Return a list of all Contact Groups associated with a grant.

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | No | The maximum number of objects to return. See [Pagination](/docs/reference/api/#pagination) for more information. |
| `page_token` | string | No | An identifier that specifies which page of data to return. You can get this value from the `next_cursor` response field. See [Pagination](/docs/reference/api/#pagination) for more information. |
| `select` | string | No | Specify fields that you want Nylas to return, as a comma-separated list (for example, `select=id,updated_at`). This allows you to receive only the portion of object data that you're interested in. You can use `select` to optimize response size and reduce latency by limiting queries to only the information that you need. |

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `grant_id` | string | Yes | ID of the grant to access. Use `/me/` to refer to the grant associated with an access token. |

## Responses

### 200 - Contact Groups

- `request_id` (string) - The request ID.
- `data` (array)
  - `grant_id` (string) - The ID of grant for the connected user.
  - `group_type` (string) - The Contact Group type.
  - `id` (string) - A globally unique object identifier for Microsoft accounts. An email address for Google accounts.
  - `name` (string) - The Contact Group display name.
  - `object` (string) - The response object type.
  - `path` (string) - The Contact Group's path.
- `next_cursor` (string,null) - A cursor pointing to the next page of results for the request.

### 400 - Bad Request

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 401 - Unauthorized

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 429 - Rate Limit

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.

### 504 - Provider Failure

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.

## Code samples

### cURL

```bash
curl --compressed --request GET \
  --url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/contacts/groups' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --header 'Content-Type: application/json'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

const nylas = new Nylas({
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
});

async function listContactGroups() {
  try {
    const groups = await nylas.contacts.groups({
      identifier: "<NYLAS_GRANT_ID>",
    });

    console.log("Contact groups:", groups);
  } catch (error) {
    console.error("Error listing contact groups:", error);
  }
}

listContactGroups();

```

### Python SDK

```python
from nylas import Client

nylas = Client(
    "<NYLAS_API_KEY>",
    "<NYLAS_API_URI>"
)

grant_id = "<NYLAS_GRANT_ID>"

contact_groups = nylas.contacts.list_groups(
  grant_id,
)

print(contact_groups)
```

### Ruby SDK

```ruby
require 'nylas'	

nylas = Nylas::Client.new(api_key: "<NYLAS_API_KEY>")
groups = nylas.contacts.list_groups(identifier: "<NYLAS_GRANT_ID>")

puts groups
```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.*;

public class ReadContactGroups {
  public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError {
    NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();
    ListResponse<ContactGroup> groups = nylas.contacts().listGroups("<NYLAS_GRANT_ID>");
    
    System.out.println(groups);
  }
}

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient

fun main(args: Array<String>) {

  val nylas: NylasClient = NylasClient(apiKey = "<NYLAS_API_KEY>")
  var groups = nylas.contacts().listGroups("<NYLAS_GRANT_ID>")

  print(groups)
}
```
