# Return all contacts

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

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

Return all contacts in a user's address book.

**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. |
| `email` | string | No | Returns the contacts containing the specified email address. |
| `phone_number` | string | No | (Google, IMAP, iCloud, Yahoo, and EWS only) Returns contacts containing the specified phone number. |
| `source` | string | No | Returns the specified contacts from the user's address book, domain, or any auto-generated contacts from messages. If you want to filter for multiple sources, pass a comma-separated list (for example, `source=address_book,inbox`).  EWS doesn't support `inbox`. Compound source filters are supported for IMAP and iCloud only. |
| `group` | string | No | (Not supported for EWS) Returns the contacts included in the specified Contact Group. |
| `recurse` | string | No | (Microsoft Only) When `true`, returns the contacts in the specified Contact Group subgroups. The recursion goes only one level deep. |

### 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 - Contacts

- `request_id` (string) - The request ID.
- `data` (array)
  - `birthday` (string) - The contact's birthday in [ISO-8601 format](https://en.wikipedia.org/wiki/ISO_8601#Calendar_dates).
  - `company_name` (string) - The name of the company that the contact is affiliated with (for example, their workplace).
  - `emails` (array,null) - The contact's email addresses. May be `null` if the contact has no email addresses. Treat `null` the same as an empty array.
  - `given_name` (string) - The contact's given name.
  - `grant_id` (string) - The ID of grant for the connected user.
  - `groups` (array,null) - The contact's group memberships. May be `null` if the contact has no group memberships. Treat `null` the same as an empty array.
  - `id` (string) - A globally unique object identifier for Microsoft accounts. An email address for Google accounts.
  - `im_addresses` (array,null) - The contact's IM addresses. May be `null` if the contact has no IM addresses. Treat `null` the same as an empty array.
  - `job_title` (string) - The contact's occupation or job title.
  - `manager_name` (string) - The name of the contact's manager.
  - `middle_name` (string) - The contact's middle name.
  - `nickname` (string) - A custom nickname for the contact.
  - `notes` (string) - Notes about with the contact (for example, their favorite food).
  - `object` (string) - The response object type.
  - `office_location` (string) - The location of the office where the contact works.
  - `phone_numbers` (array,null) - The contact's phone numbers. May be `null` if the contact has no phone numbers. Treat `null` the same as an empty array.
  - `physical_addresses` (array,null) - The contact's physical addresses. May be `null` if the contact has no physical addresses. Treat `null` the same as an empty array.
  - `picture_url` (string) - A URL that links to the contact's picture.
  - `source` (string) - The source of the contact. For iCloud and IMAP grants, the source is `inbox` if the contact is 
parsed from a message. If the contact is created or updated using the Nylas API, its source is 
`address_book`.
  - `suffix` (string) - (Not supported for EWS) The suffix of a contact's name, if applicable.
  - `surname` (string) - The contact's surname.
  - `web_pages` (array,null) - The contact's web pages. May be `null` if the contact has no web pages. Treat `null` the same as an empty array.
- `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' \
  --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 fetchContacts() {
  try {
    const identifier = "<NYLAS_GRANT_ID>";
    const contacts = await nylas.contacts.list({
      identifier,
      queryParams: {},
    });

    console.log("Recent Contacts:", contacts);
  } catch (error) {
    console.error("Error fetching drafts:", error);
  }
}

fetchContacts();

```

### Python SDK

```python
from nylas import Client

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

grant_id = "<NYLAS_GRANT_ID>"

contacts = nylas.contacts.list(
  grant_id,
)

print(contacts)
```

### Ruby SDK

```ruby
require 'nylas'	

nylas = Nylas::Client.new(api_key: "<NYLAS_API_KEY>")
contacts, _ = nylas.contacts.list(identifier: "<NYLAS_GRANT_ID>")

contacts.each {|contact|
  puts "Name: #{contact[:given_name]} #{contact[:surname]} | " \
      "Email: #{contact[:emails][0][:email]} | ID: #{contact[:id]}"
}
```

### Java SDK

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

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

    for(Contact contact : contacts.getData()) {
      System.out.println(contact);
      System.out.println("\n");
    }
  }
}

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient

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

  for(contact in contacts.data){
    println(contact)
  }
}

```
