---
title: "Connect the email assistant with an email code"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.nicer.travel/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect the email assistant with an email code

Path: Nicer API › Assistant

`POST /agent/email-connection`

URL: `https://api.nicer.travel/agent/email-connection`

Connects the caller's email to the email assistant, reports whether it is connected, or disconnects it, by action: status answers whether it is connected; start checks the captcha token and emails the caller a six-digit code, answering a session; finish takes that session and the code and, when they match the caller's account, keeps a sign-in for the email assistant on the server; disconnect ends it. The sign-in it keeps is encrypted on the server and never sent back. Any signed-in person with an email on their account may call it, for their own email only. Errors: 400 ERROR_EMAIL_REQUIRED for an account without an email; 403 ERROR_UNAUTHORIZED for a captcha that fails or a code of another account; 400 ERROR_INVALID_CODE for a code that expired.

## Authentication

- `bearerAuth`, http bearer, header `Authorization`, format `JWT`

## Request body

_Required._

Every option has:

- `action` (`<option>.action`; string, required)

One of the following, each adding:

- `object` (`agent.emailConnection.1`)
- `object` (`agent.emailConnection.2`)
  - `captchaToken` (`agent.emailConnection.2.captchaToken`; string, required)
    - maxLength: `2048` · minLength: `1`
- `object` (`agent.emailConnection.3`)
  - `session` (`agent.emailConnection.3.session`; string, required)
    - maxLength: `4096` · minLength: `1`
  - `code` (`agent.emailConnection.3.code`; string, required)
    - pattern: `^\d{6}$`
- `object` (`agent.emailConnection.4`)

## Example request

```json
{
  "action": "status"
}
```

## Code samples

### JavaScript SDK

```javascript
import { createClient } from "@nicertravel/sdk";

const nicer = createClient({
  baseUrl: "https://api.nicer.travel",
  token: process.env.NICER_TOKEN,
});

await nicer.agent.emailConnection({
  "action": "status"
});
```

### Nicer CLI

```bash
nicer agent email-connection --input - <<'JSON'
{
  "action": "status"
}
JSON
```

### cURL

```bash
curl --request POST \
  --url https://api.nicer.travel/agent/email-connection \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "action": "status"
}
'
```

### TypeScript

```typescript
const url = 'https://api.nicer.travel/agent/email-connection';
const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer <token>'
  },
  body: JSON.stringify({action: 'status'})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.nicer.travel/agent/email-connection"

payload = { "action": "status" }
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

OK

#### Example

```json
{
  "connected": true,
  "email": "string",
  "session": "string"
}
```

- `connected` (`agent.emailConnection.response.200.connected`; boolean, required)
- `email` (`agent.emailConnection.response.200.email`; any of, required)
  - any of the following: `string`, `null`
- `session` (`agent.emailConnection.response.200.session`; string, optional)

### 400

Request failed. `errorCode` is stable; `errorMessage` is for humans.

#### Example

```json
{
  "errorCode": "string",
  "errorMessage": "string"
}
```

- `errorCode` (`agent.emailConnection.response.400.errorCode`; string, required)
- `errorMessage` (`agent.emailConnection.response.400.errorMessage`; string, required)

### 401

Request failed. `errorCode` is stable; `errorMessage` is for humans.

#### Example

```json
{
  "errorCode": "string",
  "errorMessage": "string"
}
```

- `errorCode` (`agent.emailConnection.response.401.errorCode`; string, required)
- `errorMessage` (`agent.emailConnection.response.401.errorMessage`; string, required)

### 403

Request failed. `errorCode` is stable; `errorMessage` is for humans.

#### Example

```json
{
  "errorCode": "string",
  "errorMessage": "string"
}
```

- `errorCode` (`agent.emailConnection.response.403.errorCode`; string, required)
- `errorMessage` (`agent.emailConnection.response.403.errorMessage`; string, required)


Source: https://docs.nicer.travel/api/Assistant/agent.emailConnection/index.md
