# POST /auth/second-factor/recovery-codes

First published 14 Oct 2026 (release 0.2.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the auth group.

Replace the caller's second-factor recovery codes

- Who may call it: administrator, reseller, customer
- Token scope, any of: all
- Answers: 200 OK

Supply current_password and authenticate with a session or API token that has the all scope. The operation returns 409 if the caller has no confirmed second factor. POST /auth/second-factor/confirm returns the initial recovery codes.

All previous recovery codes stop working immediately. The response contains eight new single-use recovery codes, shown only once. Each code can replace an authenticator app code for one sign-in.

## As a command

- [urbestack-user-second-factor-codes](https://urbestack.com/docs/commands/urbestack-user-second-factor-codes.md): Replaces the user's recovery codes with eight new codes and prints them once.

## Request body

JSON, the type [CurrentPassword](https://urbestack.com/docs/api/types/CurrentPassword.md).

- `current_password` (string, up to 128 characters, required)

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/auth/second-factor/recovery-codes" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "current_password": "text"
  }'
```

Response, 200 OK:

```
{
  "enabled": true,
  "recovery_codes": [
    "text"
  ],
  "recovery_codes_left": 1
}
```

## Errors

- 400: --name is required
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: Username '<value>' is reserved
- 401: Authentication required
- 404: User '<name>' not found
- 409: User '<name>' has no second factor; the recovery codes come with turning one on
