> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce/force-password-reset.md).

# Force Password Reset

Bulk password reset flow. For users whose email addresses are listed in an uploaded Excel (`.xlsx`) file, this flow:

* Deletes their auth tokens (logging them out of all active sessions)
* Deletes their active sessions
* Clears the `UserProfile.old_passwords` list

The operation runs **asynchronously** (Celery). The upload endpoint immediately returns a `cache_key`; you then poll a separate status endpoint for the result.

{% hint style="info" %}
If the `FORCE_PASSWORD_RESET_CHECK_ACTIVE` dynamic setting is enabled, users whose `old_passwords` are cleared by this flow will not be able to log in until they reset their password. Users without a `UserProfile` are not affected.
{% endhint %}

## <mark style="color:red;">Authorization</mark>

All endpoints require admin (staff) permissions — `permissions.IsAdminUser`.

```http
Authorization: Token <ADMIN_TOKEN>
```

{% stepper %}
{% step %}

### <mark style="color:red;">Start a Password Reset</mark>

```http
POST /api/v1/users/force-password-reset/
Content-Type: multipart/form-data
```

| Field  | Type | Required | Description                                                                                                            |
| ------ | ---- | -------- | ---------------------------------------------------------------------------------------------------------------------- |
| `file` | file | Yes      | An `.xlsx` file. The first column must contain email addresses. If the first row is the `email` header, it is skipped. |

#### <mark style="color:red;">Excel Format</mark>

| email               |
| ------------------- |
| <user1@example.com> |
| <user2@example.com> |

The header row is optional; if the first cell is `email`, it is skipped automatically.

#### <mark style="color:red;">curl</mark>

```bash
curl -X POST "https://<HOST>/api/v1/users/force-password-reset/" \
  -H "Authorization: Token <ADMIN_TOKEN>" \
  -F "file=@emails.xlsx"
```

#### <mark style="color:red;">Success Response —</mark> <mark style="color:red;"></mark><mark style="color:red;">`200 OK`</mark>

```json
{
  "cache_key": "3f1c9e4a-2b7d-4d1e-9c3a-8f0b2a1d5e6c",
  "total": 2,
  "processed": 0,
  "is_ready": false,
  "result": null,
  "error_message": null
}
```

Use the returned `cache_key` to query the status.

#### <mark style="color:red;">Error Responses —</mark> <mark style="color:red;"></mark><mark style="color:red;">`400 Bad Request`</mark>

```json
{ "detail": "An Excel file must be uploaded in the 'file' field." }
```

```json
{ "detail": "Could not parse the uploaded file. Please upload a valid .xlsx file." }
```

```json
{ "detail": "No emails found in the file." }
```

{% endstep %}

{% step %}

### <mark style="color:red;">Check Status (poll)</mark>

```http
GET /api/v1/users/force-password-reset-status/?cache_key=<CACHE_KEY>
```

#### <mark style="color:red;">curl</mark>

```bash
curl -X GET "https://<HOST>/api/v1/users/force-password-reset-status/?cache_key=3f1c9e4a-2b7d-4d1e-9c3a-8f0b2a1d5e6c" \
  -H "Authorization: Token <ADMIN_TOKEN>"
```

#### <mark style="color:red;">In Progress —</mark> <mark style="color:red;"></mark><mark style="color:red;">`200 OK`</mark>

```json
{
  "cache_key": "3f1c9e4a-2b7d-4d1e-9c3a-8f0b2a1d5e6c",
  "total": 250,
  "processed": 100,
  "is_ready": false,
  "result": null,
  "error_message": null
}
```

#### <mark style="color:red;">Completed —</mark> <mark style="color:red;"></mark><mark style="color:red;">`200 OK`</mark>

```json
{
  "cache_key": "3f1c9e4a-2b7d-4d1e-9c3a-8f0b2a1d5e6c",
  "total": 2,
  "processed": 2,
  "is_ready": true,
  "result": {
    "processed_email_count": 2,
    "found_user_count": 2,
    "deleted_token_count": 2,
    "deleted_session_count": 1,
    "updated_profile_count": 2,
    "missing_emails": []
  },
  "error_message": null
}
```

`missing_emails`: emails present in the file for which no matching user was found in the system.

#### <mark style="color:red;">Finished With an Error —</mark> <mark style="color:red;"></mark><mark style="color:red;">`200 OK`</mark>

```json
{
  "cache_key": "3f1c9e4a-2b7d-4d1e-9c3a-8f0b2a1d5e6c",
  "total": 2,
  "processed": 0,
  "is_ready": true,
  "result": null,
  "error_message": "<error message>"
}
```

#### <mark style="color:red;">Not Found / Expired</mark> <mark style="color:red;"></mark><mark style="color:red;">`cache_key`</mark> <mark style="color:red;"></mark><mark style="color:red;">—</mark> <mark style="color:red;"></mark><mark style="color:red;">`404 Not Found`</mark>

```json
{
  "cache_key": "3f1c9e4a-2b7d-4d1e-9c3a-8f0b2a1d5e6c",
  "is_ready": false,
  "error_message": "Not found or expired."
}
```

If the `cache_key` parameter is not sent at all, an empty body is returned with `404`.
{% endstep %}
{% endstepper %}

## <mark style="color:red;">Response Fields (state)</mark>

| Field           | Type         | Description                                                |
| --------------- | ------------ | ---------------------------------------------------------- |
| `cache_key`     | string       | The key identifying the operation.                         |
| `total`         | int          | Total number of emails read from the file.                 |
| `processed`     | int          | Number of emails processed so far.                         |
| `is_ready`      | bool         | Whether the operation has finished (including errors).     |
| `result`        | object\|null | Populated once the operation completes (see fields below). |
| `error_message` | string\|null | The error message, if any.                                 |

### <mark style="color:red;">`result`</mark> <mark style="color:red;"></mark><mark style="color:red;">contents</mark>

| Field                   | Description                                            |
| ----------------------- | ------------------------------------------------------ |
| `processed_email_count` | Number of emails processed.                            |
| `found_user_count`      | Number of matching users found.                        |
| `deleted_token_count`   | Number of auth tokens deleted.                         |
| `deleted_session_count` | Number of active sessions deleted.                     |
| `updated_profile_count` | Number of profiles whose `old_passwords` were cleared. |
| `missing_emails`        | List of emails for which no matching user was found.   |

## <mark style="color:red;">Notes</mark>

* Emails are normalized with `strip().lower()`; matching is done case-insensitively.
* The operation proceeds in chunks of 100; `processed` is updated at each step.
* Cache TTL: 2 hours. After this period, the status can no longer be queried using the `cache_key`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://apidocs.akinon.com/commerce/force-password-reset.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
