> ## 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.

# Nodes, topics, and replies

> Find Nodes, browse topics, and publish topics and replies with NodeLoc’s /api/v1

`/api/v1` is the site API shared by the NodeLoc web interface and native apps. Public resources can be read anonymously. Viewer-specific permissions and writes use a site session. These examples send a native-app-style session token in `Authorization: Bearer`. Same-origin browser requests can use the `nl_session` cookie. The third-party OAuth token from Open Login grants access to authorized profile information. See [v1 overview](https://docs.nodeloc.com/en/api-reference/v1/overview.md), [Accounts and authentication](https://docs.nodeloc.com/en/api-reference/v1/accounts.md), and [Open Login](https://docs.nodeloc.com/en/api-reference/introduction.md).

The examples use a local instance. Set `BASE_URL`, `NODE_SLUG`, and `TOPIC_ID` to the instance and resources you are using. The authenticated requests assume `NODELOC_SESSION_TOKEN` is set in your environment. API paths are independent of the interface language prefix.

```bash theme={null}
BASE_URL='http://127.0.0.1:8090'
NODE_SLUG='vps'
TOPIC_ID=2
```

## Find a Node

Use `GET /api/v1/nodes` to list visible Nodes. Add `q` to search and use an empty `cursor=` to start at the beginning. Pass `next_cursor` back as `cursor` on the next request and keep the same search criteria. The final response omits `next_cursor`. For numbered pages, start with `page=1` and follow `next_page`. The default page size is 20 and `limit` accepts 1–100. Use one pagination mode per request. Without any search or pagination parameters, the response contains only `nodes`.

```bash theme={null}
curl --silent --show-error --fail-with-body --get "$BASE_URL/api/v1/nodes" \
  --data-urlencode "q=$NODE_SLUG" \
  --data-urlencode 'cursor=' \
  --data-urlencode 'limit=10'
```

Excerpt from the final page.

```json theme={null}
{
  "nodes": [
    {
      "id": 7,
      "parent_id": 1,
      "slug": "vps",
      "name": "VPS",
      "visibility": "public",
      "joined": false
    }
  ],
  "per_page": 10
}
```

Use the Node’s `slug` to fetch its details. Before posting, fetch details with the writer’s session and inspect `permissions.create_topic` and `posting`. `min_tags` is the minimum number of tags. If `tags_restricted` is true, use tags from `tag_options`.

```bash theme={null}
curl --silent --show-error --fail-with-body \
  --header "Authorization: Bearer $NODELOC_SESSION_TOKEN" \
  "$BASE_URL/api/v1/nodes/$NODE_SLUG"
```

Excerpt from the Node details for a signed-in viewer who can publish and reply.

```json theme={null}
{
  "node": {"id": 7, "slug": "vps", "joined": true},
  "posting": {
    "slow_mode_seconds": 0,
    "min_tags": 1,
    "tags_restricted": false,
    "tag_options": ["求助", "测评", "优惠"]
  },
  "permissions": {"create_topic": true, "reply": true, "moderate": false}
}
```

## Browse topics and posts

Without filters, `GET /api/v1/topics` returns home feed topics in order of most recent activity. Add `node` or `tag` to narrow the list. Topic lists, topic details, and reply lists accept a `limit` of 1–50 and default to 30.

| List | Request parameters | Next page |
| - | - | - |
| Latest or Fresh | Latest sorts by most recent activity. `sort=fresh` sorts by creation time. Filter by `node`, `tag`, `joined=1`, or `featured=1` | Pass `next_cursor` as `cursor` with the same filters and sort. The last page returns `null` |
| Hot or Rising | `sort=hot` or `sort=rising`. Both support `node` and `tag` | Pass `next_offset` as `offset`. The last page returns `null` |

```bash theme={null}
curl --silent --show-error --fail-with-body --get "$BASE_URL/api/v1/topics" \
  --data-urlencode "node=$NODE_SLUG" \
  --data-urlencode 'sort=fresh' \
  --data-urlencode 'limit=10'
```

Take a topic ID from `topics[].id`. Topic details return `topic`, one page of `posts`, `next_after`, and the viewer’s `permissions`. Posts appear in order by post number, starting with the first post at 1. Use `next_after` as the next request’s `after`. A `null` value marks the last page.

```bash theme={null}
curl --silent --show-error --fail-with-body \
  "$BASE_URL/api/v1/topics/$TOPIC_ID?after=0&limit=1"
```

Excerpt from an anonymous topic detail response.

```json theme={null}
{
  "topic": {
    "id": 2,
    "node_slug": "vps",
    "title": "What VPSes are worth buying for under $20 a year?",
    "reply_count": 4
  },
  "posts": [
    {
      "id": 6,
      "post_number": 1,
      "reply_to_post_number": null,
      "kind": "post",
      "html": "<p>I’m looking for a small server for probes. Any recommendations?</p>"
    }
  ],
  "next_after": 1,
  "permissions": {
    "reply": false,
    "moderate": false
  }
}
```

For replies only, use `GET /api/v1/topics/{id}/replies?sort=best&offset=0&limit=10`. It excludes the first post and system action records. The supported sorts are `best`, `new`, `old`, and `controversial`. Pass `next_offset` as `offset` to continue. The last page omits `next_offset`.

## Publish a topic

Send the Node’s `slug` in `node` and the Markdown body in `raw`. Titles must contain 6–255 characters, and the first post must contain at least 8 characters. Use tags that match the target Node’s rules. Change `node` and `tags` in the example if you are posting to a different Node.

```bash theme={null}
curl --silent --show-error --fail-with-body \
  --request POST "$BASE_URL/api/v1/topics" \
  --header "Authorization: Bearer $NODELOC_SESSION_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{
    "node": "vps",
    "title": "Comparing two VPS plans",
    "raw": "I am comparing two plans. How does **latency** change during peak hours?",
    "tags": ["求助"]
  }'
```

A successful creation returns HTTP 201. Keep the returned `topic.id` to open the topic or send a reply. If `held` is true, the content is awaiting review and appears publicly once approved.

```json theme={null}
{
  "topic": {"id": 42, "title": "Comparing two VPS plans"},
  "post": {
    "id": 87,
    "post_number": 1,
    "html": "<p>I am comparing two plans. How does <strong>latency</strong> change during peak hours?</p>"
  },
  "held": false
}
```

## Reply to a topic or post

Fetch topic details with the writer’s session and check `permissions.reply`. Send the reply in `raw`. To reply to a particular post in the topic, set `reply_to_post_number`. To reply to the topic itself, omit the field or set it to `0`. A `post_number` identifies a post within the topic. The `id` identifies the post across the site.

Set `TOPIC_ID` to the `topic.id` returned by the previous request. The example replies to its first post.

```bash theme={null}
TOPIC_ID='REPLACE_WITH_TOPIC_ID'
curl --silent --show-error --fail-with-body \
  --request POST "$BASE_URL/api/v1/topics/$TOPIC_ID/posts" \
  --header "Authorization: Bearer $NODELOC_SESSION_TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"raw":"Try checking latency during peak evening hours first.","reply_to_post_number":1}'
```

A successful creation returns HTTP 201.

```json theme={null}
{
  "post": {
    "id": 88,
    "post_number": 2,
    "reply_to_post_number": 1,
    "html": "<p>Try checking latency during peak evening hours first.</p>",
    "created_at": "2026-11-29T02:15:00Z"
  },
  "held": false
}
```

## Handle permissions and errors

Lists and details reflect what the viewer can access. A title may appear in a list while the body still requires sign-in or a minimum tier. Publishing checks permissions, account status, Node rules, and rate limits again at the time of the request.

| HTTP status | Example `error.code` | Meaning |
| - | - | - |
| 400 | `invalid_cursor`, `invalid_json` | The cursor or JSON is invalid. JSON validation also rejects unknown fields |
| 401 | `unauthorized` | The write requires a valid session |
| 403 | `login_required`, `trust_level_too_low`, `members_only`, `topic_closed` | The viewer cannot read, publish, or reply under the current rules |
| 404 | `not_found`, `merged` | The resource is missing or inaccessible, or the topic was merged. If the viewer can access the destination, `error.merged_into` identifies it |
| 422 | `invalid` | See `error.fields` for the invalid title, body, tags, or reply target |
| 429 | `rate_limited`, `slow_mode` | A rate or quota limit applies. When present, `Retry-After` gives the wait in seconds |

Use the HTTP status and `error.code` in application logic. `error.message` and values in `error.fields` are display text and can vary by language. In this example, `merged_into` gives the new location of the original first post.

```json theme={null}
{
  "error": {
    "code": "merged",
    "message": "This topic has been merged into another topic",
    "merged_into": {"topic_id": 43, "post_number": 7}
  }
}
```


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