# Return all grants

> **GET** `https://api.us.nylas.com/v3/grants`

Source: https://developer.nylas.com/docs/reference/api/manage-grants/get-all-grants/

Returns all grants in your Nylas application.

**Authentication:** NYLAS_API_KEY

## Parameters

### Query parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `account_id` | string | No | Returns grants with a matching v2 Nylas account ID. Only applicable for grants migrated from Nylas v2. |
| `account_ids` | string | No | Returns grants with a matching list of v2 Nylas account IDs. Only applicable for grants migrated from Nylas v2. |
| `before` | integer | No | Returns grants whose `created_at` value is less than or equal to the defined value, in seconds using the Unix timestamp format. |
| `email` | string | No | Returns grants with a matching `email`. |
| `grant_status` | string | No | Filters for only valid or invalid grants. |
| `ip` | string | No | Returns grants with a matching IP address. |
| `limit` | integer | No | The maximum number of grants to return. See [Pagination](/docs/reference/api/#pagination) for more information. |
| `offset` | integer | No | The offset value for the request. See [Pagination](/docs/reference/api/#pagination) for more information. |
| `order_by` | string | No | The order in which Nylas should sort results for the request. |
| `provider` | string | No | Returns grants with a matching `provider`. |
| `since` | integer | No | Returns grants whose `created_at` value is greater than or equal to the defined value, in seconds using the Unix timestamp format. |
| `sort_by` | string | No | The field Nylas should use to sort results for the request. |
| `workspace_id` | string | No | Returns grants in the specified workspace. |

## Responses

### 200 - Success. Returns an array of Grant objects.

- `request_id` (string) - The request ID.
- `data` (array)
  - `account_id` (string) - The v2 Nylas account ID. This field appears only if the grant was created by migrating a v2
connected account.
  - `blocked` (boolean) - When `true`, indicates that the grant is blocked from accessing the Nylas APIs.
  - `created_at` (integer) **(required)** - When the grant was created, in seconds using the Unix timestamp format.
  - `email` (string) - The email address associated with the grant. If the provider supports `id_token` and exposes the
user's email address, Nylas automatically extracts this value.
  - `grant_status` (string) - Specifies whether the grant is valid or the user needs to re-authenticate.
  - `id` (string) **(required)** - A unique identifier for the grant.
  - `ip` (string) - The user's client IP address. Mostly useful for
[Hosted OAuth](/docs/v3/auth/hosted-oauth-apikey/).
  - `name` (string) - The user's display name.
  - `provider` (string) **(required)** - The provider that the user authenticated with.
  - `provider_user_id` (string) - The user's provider ID. This field might be changed at any time by the provider.
  - `scope` (array) **(required)** - An array of [granular scopes](/docs/dev-guide/scopes/) associated with the grant. If none are
specified, Nylas uses the default scopes from the
[connector](/docs/reference/api/connectors-integrations/).
  - `settings` (object) - A list of settings associated with the grant. The contents of this object might differ between
grants or depending on the provider.
  - `email_aliases` (array) - An array of found email aliases for this grant. Only returned if special query parameter `expose_aliases` for 
[Get Grant](/docs/reference/api/manage-grants/get_grant_by_id/) is used and set to `true`.
Applicable only for Google and Microsoft grants.
  - `state` (string) - The initial state that was set as part of the authentication process. Nylas passes this value
back to your project without modifying it. You can use this field for verification, or to track
information about the user.
  - `updated_at` (integer) - When the user last authenticated their grant, in seconds using the Unix timestamp format.
Initially, this value is the same as `created_at`.
  - `user_agent` (string) - The user's [client or browser information](https://www.useragents.me/). Mostly useful for
[Hosted OAuth](/docs/v3/auth/hosted-oauth-apikey/).
  - `workspace_id` (string) - The ID of the Workspace the grant belongs to, if any. For grants from providers other than
Agent Accounts, Nylas may omit this field when the grant is in the application's default
workspace.
  - `credential_id` (string) - The ID of the Credential the grant is associated with. Grant will use this Credential for provider communication.
- `limit` (integer)
- `offset` (integer)

### 401 - Error: Not authenticated

- `request_id` (string) **(required)** - ID of the request
- `error` (object) **(required)** - Error object
  - `type` (string) - Type of error
  - `message` (string) - Informative error message
  - `provider_error` (object) - (OPTIONAL) informative error message from provider's side

### 404 - Error: not found

- `request_id` (string) **(required)** - ID of the request
- `error` (object) **(required)** - Error object
  - `type` (string) - Type of error
  - `message` (string) - Informative error message
  - `provider_error` (object) - (OPTIONAL) informative error message from provider's side

## Code samples

### cURL

```bash
curl --request GET \
--url 'https://api.us.nylas.com/v3/grants?limit=3&provider=google' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <NYLAS_API_KEY>' \
```

### Node.js SDK

```javascript
import Nylas from "nylas";

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

async function listGrants() {
  try {
    const grants = await nylas.grants.list();

    console.log("Grants found:", grants);
  } catch (error) {
    console.error("Error finding grants:", error);
  }
}

listGrants();

```

### Python SDK

```python
from nylas import Client

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

grants = nylas.grants.list()

print(grants)

```

### Ruby SDK

```ruby
# frozen_string_literal: true

# Load gems
require 'nylas'

# Initialize Nylas client
nylas = Nylas::Client.new(
  api_key: '<NYLAS_API_KEY>'
)

grants, _ = nylas.grants.list()

grants.each do |grant|
  puts "#{grant}\n\n"
end

```

### Java SDK

```java
// Import Nylas packages
import com.nylas.NylasClient;
import com.nylas.models.*;
import java.util.List;

public class read_grants {
  public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError {
    NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();
    ListResponse<Grant> grants = nylas.grants().list();

    for(Grant grant : grants.getData()){
      System.out.println(grant);
    }
  }
}
```

### Kotlin SDK

```kotlin
// Import Nylas packages
import com.nylas.NylasClient

fun main(args: Array<String>) {
  val nylas: NylasClient = NylasClient(
      apiKey = "<NYLAS_API_KEY>"
  )

  val grants = nylas.grants().list().data;
  
  for(grant in grants){
    println(grant)
  }
}

```
