# Email a step-up code

> Source: https://truto.one/docs/api-reference/admin/step-up/send-email-code/

`POST /auth/step-up/email-code`

Resource: **Step-up**

Emails the signed-in user a 6-digit code for answering a step-up prompt whose `step_up_factors` includes `email_code`. Send the prompt's `step_up_action` as `action`: the code only works for that action. It expires after 10 minutes and works once. A new send for the same action replaces that action's previous code; a code for another action is kept. Retry the gated request with it as `email_code`.

At most one send per 60 seconds and five per hour for each action, and ten per hour per user across all actions; beyond that the call answers 429 with a `Retry-After` header in seconds. A send the mail provider refuses answers 503 and does not count.

No code is sent while the user is locked out of step-up (five failed proofs in 15 minutes): the call answers 429 with `step_up_locked: true`, a message naming the wait, and `Retry-After` until the lock ends. These refusals do not count against the send limits.

**Session only.** An API token or tenant token is rejected with 403, and so is a session that is impersonating another user.

## Request body

- **`action`** _(string)_
  The change a step-up guards, as `step_up_action` names it. `passkey_remove` guards `DELETE /auth/passkey/{id}`. `api_token_delete` and `team_member_invite` guard actions taken in the Truto dashboard.
  Allowed: `passkey_register`, `passkey_remove`, `api_token_create`, `api_token_delete`, `team_member_invite`, `mcp_oauth_consent`, `mcp_server_create`, `mfa_enable`, `mfa_disable`, `mfa_reset`, `backup_codes_regenerate`

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | Unknown `action`, a body that is not JSON, or the account is not asked for an email code (it has an authenticator app, or its organization enforces SSO). |
| `401` | Not signed in. |
| `403` | Not a browser session, or the session is impersonating. |
| `429` | A code for this action was sent less than 60 seconds ago, five were sent for it in the last hour, or ten were sent for any action in the last hour. Or the user is locked out of step-up, and then the body has `step_up_locked` set to true. |
| `503` | The mail provider refused the send. No code is stored, and the send is not counted, so it can be retried at once. |

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/auth/step-up/email-code' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "action": "passkey_register"
}'
```

### JavaScript

```javascript
const body = {
  "action": "passkey_register"
};

const response = await fetch('https://api.truto.one/auth/step-up/email-code', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/auth/step-up/email-code"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "action": "passkey_register"
}

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