> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nodeloc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Search, uploads, and notifications

> Search content, upload files, manage notifications, and subscribe to unread counts

These examples use a local instance. For authenticated calls, set `NODELOC_SESSION_TOKEN` to an existing NodeLoc session token or use the session cookie from a same-origin browser. See the [Community API v1 overview](https://docs.nodeloc.com/en/api-reference/v1/overview.md) for authentication and common errors.

```bash theme={null}
BASE_URL='http://127.0.0.1:8090'
```

## Search

`GET /api/v1/search` accepts anonymous requests. Results reflect what the current viewer can access.

| Parameter | Use |
| - | - |
| `q` | Required search query. An empty query returns `422 invalid` for `q`. |
| `type` | Defaults to `all`, a preview of each result type. Use `posts`, `topics`, `users`, `nodes`, or `tags` to browse one type. |
| `node` | Restrict post and topic results to a Node `slug`. An inaccessible Node can return `404`. |
| `sort` | Posts sort by relevance by default. Use `new` to sort newest first. |
| `page` | Starts at 1, with 20 results per page and a maximum page of 10. |
| `offset` and `limit` | For posts and topics, sending either parameter selects this pagination mode. `limit` defaults to 20 and accepts 1–50. The server selects `floor(offset / limit) + 1`, capped at page 10. |

```bash theme={null}
curl --silent --show-error --fail-with-body --get "$BASE_URL/api/v1/search" \
  --data-urlencode 'q=VPS' \
  --data-urlencode 'type=posts' \
  --data-urlencode 'node=vps' \
  --data-urlencode 'page=1'
```

The response includes `posts`, `topics`, `users`, `nodes`, and `tags` arrays. `topics` groups matching posts by topic and can contain fewer entries than `posts`. Follow `has_more` and the returned `next_page` or `next_offset`. The last page omits the continuation fields.

```json theme={null}
{
  "q": "VPS",
  "type": "posts",
  "page": 1,
  "has_more": false,
  "posts": [{"id": 6, "topic_id": 2, "post_number": 1, "node_slug": "vps"}],
  "topics": [{"id": 2, "title": "Comparing annual VPS plans"}],
  "users": [],
  "nodes": [],
  "tags": []
}
```

Search allows 30 requests per minute per account or per IP for anonymous requests. If it returns `429 rate_limited`, wait the number of seconds in `Retry-After`.

## Upload images and attachments

`POST /api/v1/uploads` requires a session. Send `file` in a `multipart/form-data` request. JPEG, PNG, GIF, and WebP images are accepted by default. For a non-image attachment such as a PDF, add the form field `kind=attachment`. The account needs the `uploads.attach` permission. The single-file limit is 15 MiB.

```bash theme={null}
curl --silent --show-error --fail-with-body \
  --request POST "$BASE_URL/api/v1/uploads" \
  --header "Authorization: Bearer $NODELOC_SESSION_TOKEN" \
  --form 'file=@./photo.jpg'
```

cURL generates the multipart `Content-Type` header and boundary. A successful upload returns HTTP 201 and an `upload` object.

```json theme={null}
{
  "upload": {
    "id": 321,
    "url": "/uploads/original/ab/abcdef0123456789abcdef0123456789abcdef01.jpg",
    "width": 1200,
    "height": 800,
    "image": true,
    "filename": "photo.jpg",
    "size": 348123
  }
}
```

`url` is relative to the site, and `size` is in bytes. Attachments return `image: false` with `null` dimensions. Use the URL in an image or download link in your [post’s Markdown](https://docs.nodeloc.com/en/api-reference/v1/content.md). File validation returns `422 invalid` with details in `error.fields.file`. Missing attachment permission returns `403 trust_level_too_low`. Exceeding the daily upload limit returns `429 upload_daily_limit`.

## List notifications and mark them read

`GET /api/v1/notifications` returns the signed-in user’s notifications. Omit `filter` for all notifications, or use `unread`, `reply`, `mention`, `vote`, `follow`, `points`, `system`, or `moderation`. `limit` defaults to 30 and accepts 1–50. Pass `next_before` as `before` on the next request. A `null` value marks the end. `unread` is the account’s total unread count.

```bash theme={null}
curl --silent --show-error --fail-with-body \
  --header "Authorization: Bearer $NODELOC_SESSION_TOKEN" \
  "$BASE_URL/api/v1/notifications?filter=unread&limit=10"
```

```json theme={null}
{
  "notifications": [
    {
      "id": 240,
      "kind": "reply",
      "topic_id": 2,
      "post_number": 3,
      "post_id": 57,
      "data": {"reply_to": "topic"},
      "read": false
    }
  ],
  "unread": 1,
  "next_before": null
}
```

Send a notification `id` from the list to `POST /api/v1/notifications/read` to mark one notification read. `{"up_to_id":240}` marks notifications with IDs up to and including 240. `{}` marks all notifications. Success returns HTTP 204 with an empty body.

```bash theme={null}
curl --silent --show-error --fail-with-body \
  --request POST "$BASE_URL/api/v1/notifications/read" \
  --header "Authorization: Bearer $NODELOC_SESSION_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"id":240}'
```

## Subscribe to the unread count

`GET /api/v1/notifications/stream` uses Server-Sent Events (SSE). It sends the current unread count when you connect and an updated total when notifications change. A same-origin browser can use `EventSource` to listen for `unread`. A native client can use an SSE client that sends the Bearer header.

```bash theme={null}
curl --silent --show-error --fail-with-body --no-buffer \
  --header "Authorization: Bearer $NODELOC_SESSION_TOKEN" \
  --header 'Accept: text/event-stream' \
  "$BASE_URL/api/v1/notifications/stream"
```

```text theme={null}
event: unread
data: {"unread":1}

: ping

```

Parse the event’s `data` as JSON and use its `unread` value to update the badge. If the notification list is open, fetch it again. The server sends a `: ping` comment about every 25 seconds and closes connections after at most 30 minutes. After reconnecting, use the first `unread` event to update the badge and refresh any open lists.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.