# List users

> Your end users, newest first.

<Endpoint method="GET" path="/v1/users" />

## Query

<ParamTable params={[
  { name: "q", type: "string", description: "Only users whose own id (external_id), name or email contains this text, in any case. Up to 100 characters." },
  { name: "limit", type: "number", description: "1 to 100, default 20." },
  { name: "after", type: "usr_…", description: "next_cursor from the previous page." }
]} />

## Request

<CodeTabs>

```bash tab="cURL"
curl "https://api.muzekit.com/v1/users?limit=20" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/users?limit=20", {
  headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` },
});
const users = await res.json();
```

```python tab="Python"
import os
import requests

users = requests.get(
    "https://api.muzekit.com/v1/users",
    params={"limit": 20},
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()
```

</CodeTabs>

The list holds this key's environment's users, newest first: everyone a session or [Create or update a user](/docs/api-reference/users-upsert) added. `q` finds users by your own id, their name or their email; to get one user by an id you know, use [Get a user](/docs/api-reference/users-get). `last_active_at` is the last time your server opened a session for the user or updated them.

## Examples

### Page through every user

Follow `next_cursor` until `has_more` is false. Use `limit=100` for the fewest calls.

<CodeTabs>

```bash tab="cURL"
AFTER=""
while :; do
  PAGE=$(curl -s "https://api.muzekit.com/v1/users?limit=100&after=$AFTER" \
    -H "Authorization: Bearer $MUZEKIT_SECRET_KEY")
  echo "$PAGE" | jq -r '.data[] | [.id, .external_id] | @tsv'
  AFTER=$(echo "$PAGE" | jq -r '.next_cursor // empty')
  [ -z "$AFTER" ] && break
done
```

```javascript tab="Node"
async function* allUsers() {
  let after = "";
  do {
    const url = `https://api.muzekit.com/v1/users?limit=100&after=${after}`;
    const page = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` },
    }).then((r) => r.json());
    yield* page.data;
    after = page.next_cursor ?? "";
  } while (after);
}

for await (const user of allUsers()) console.log(user.id, user.external_id);
```

```python tab="Python"
import os
import requests

def all_users():
    params = {"limit": 100}
    while True:
        page = requests.get(
            "https://api.muzekit.com/v1/users",
            params=params,
            headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
        ).json()
        yield from page["data"]
        if not page["has_more"]:
            break
        params["after"] = page["next_cursor"]

for user in all_users():
    print(user["id"], user["external_id"])
```

</CodeTabs>

### Search users by email or name

`q` matches part of the email, the name or your own id, in any case. It matches its text as typed, so `%` and `_` are plain characters.

<CodeTabs>

```bash tab="cURL"
curl -G https://api.muzekit.com/v1/users \
  --data-urlencode "q=@acme.com" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"
```

```javascript tab="Node"
const params = new URLSearchParams({ q: "@acme.com" });
const res = await fetch(`https://api.muzekit.com/v1/users?${params}`, {
  headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` },
});
const { data: acmeUsers } = await res.json();
```

```python tab="Python"
import os
import requests

acme_users = requests.get(
    "https://api.muzekit.com/v1/users",
    params={"q": "@acme.com"},
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()["data"]
```

</CodeTabs>

### Map Muzekit ids to your own users

Each user's `external_id` is the id your server gave it. Build a lookup once and store the `usr_…` id on your side, so later calls (such as `GET /v1/templates?user=usr_…` or uploads into the user's library) need no search.

<CodeTabs>

```bash tab="cURL"
# One page: "your id <tab> Muzekit id"
curl -s "https://api.muzekit.com/v1/users?limit=100" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq -r '.data[] | [.external_id, .id] | @tsv'
```

```javascript tab="Node"
// allUsers() from the example above
const muzekitIds = new Map();
for await (const user of allUsers()) muzekitIds.set(user.external_id, user.id);

await db.users.update("user_42", { muzekitId: muzekitIds.get("user_42") });
```

```python tab="Python"
# all_users() from the example above
muzekit_ids = {u["external_id"]: u["id"] for u in all_users()}

db.users.update("user_42", muzekit_id=muzekit_ids.get("user_42"))
```

</CodeTabs>

### Find users who stopped opening the editor

Compare `last_active_at` with a cutoff, for example to send your own reminder email. Muzekit never emails end users.

<CodeTabs>

```bash tab="cURL"
# Users on the first page with no session in 30 days
CUTOFF=$(date -u -v-30d +%Y-%m-%dT%H:%M:%S) # GNU date: -d '30 days ago'
curl -s "https://api.muzekit.com/v1/users?limit=100" \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq -r --arg c "$CUTOFF" \
    '.data[] | select((.last_active_at // "") < $c) | .external_id'
```

```javascript tab="Node"
// allUsers() from the first example
const cutoff = Date.now() - 30 * 86_400_000;
const idle = [];
for await (const user of allUsers()) {
  if (!user.last_active_at || Date.parse(user.last_active_at) < cutoff) {
    idle.push(user.external_id);
  }
}
```

```python tab="Python"
from datetime import datetime, timedelta, timezone

# all_users() from the first example
cutoff = datetime.now(timezone.utc) - timedelta(days=30)
idle = [
    u["external_id"]
    for u in all_users()
    if not u["last_active_at"]
    or datetime.fromisoformat(u["last_active_at"].replace("Z", "+00:00")) < cutoff
]
```

</CodeTabs>

For activity counts across all users per day (sessions, saves, downloads), read [Get usage](/docs/api-reference/usage-get).

## Response

```json
{
  "object": "list",
  "data": [
    {
      "object": "user",
      "id": "usr_8fK2mQ1xZpR",
      "external_id": "user_42",
      "name": "Ada",
      "email": null,
      "locale": null,
      "metadata": {},
      "last_active_at": "2026-10-16T21:35:00.000Z",
      "created_at": "2026-10-02T09:12:44.000Z"
    }
  ],
  "has_more": true,
  "next_cursor": "usr_3hT9cL0wQeB"
}
```

Each item is a [user](/docs/api-reference/users-upsert#response).
