# Verify TOTP code

> Source: https://docs.clonepartner.com/api-reference/auth/verify-totp/

`POST /api/auth/verify-totp`

Completes login by verifying the TOTP code. Sets the full session cookie on success.

**Operation ID:** `verifyTotp`

## Authentication

No authentication is required.

## Request body

The request body is required.

### `application/json`

- Type: `object`
- Properties:
  - `code` (`string`, `required`)

## Success responses

### 200

TOTP verified, session established

**Content type:** `application/json`

- Type: `object`
- Properties:
  - `success` (`boolean`)

## Error responses

### 400

Missing pending session cookie or TOTP code.
Messages distinguish the two cases so the client can recover
(re-login vs re-enter code).


### 401

Not authenticated

**Content type:** `application/json`

- Reference: `Error`
  - Type: `object`
  - Properties:
    - `error` (`string`)
      - Example: `NOT_FOUND`
    - `message` (`string`)
      - Example: `Resource not found`

Example:

```json
{
  "error": "AUTH_ERROR",
  "message": "Not authenticated"
}
```

### 429

Too many requests

**Content type:** `application/json`

- Reference: `Error`
  - Type: `object`
  - Properties:
    - `error` (`string`)
      - Example: `NOT_FOUND`
    - `message` (`string`)
      - Example: `Resource not found`

Example:

```json
{
  "error": "RATE_LIMITED",
  "message": "Too many failed TOTP attempts. Try again later."
}
```

## Examples

### cURL

```bash
curl --request POST \
  --url 'https://your-envoy.example.com/api/auth/verify-totp' \
  --header 'Content-Type: application/json' \
  --data '{
  "code": "string"
}'
```

### JavaScript (fetch)

```javascript
const response = await fetch('https://your-envoy.example.com/api/auth/verify-totp', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "code": "string"
  }),
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = response.status === 204 ? null : await response.json();
console.log(data);
```
