## Messages (`messages`)

In-app messages and announcements; admins publish announcements and tenants read and mark them as read.

Authentication: Admin only · Docs: https://www.gocdn888.com/en/docs/api/messages

### GET `/api/v2/messages`

List messages · Authentication: User (some parameters admin only)

Query parameters:

| Field | Type | Required | Description |
|---|---|---|---|
| `page` | integer |  | Page number, starting from 1 Default: 1 |
| `page_size` | integer |  | Items per page Default: 20 |
| `sort` | string |  | Sort fields, comma-separated; prefix `-` for descending, e.g. `-created_at,id` |
| `tenant_id` | integer |  | Admin only: filter by tenant (a malformed value returns 422). Ignored for tenant credentials, which only see their own tenant's data |
| `tenant_ids` | string |  | Admin only: only these tenants, comma-separated positive integers, at most 200 after deduplication (more, or a malformed value, returns 422); a single ID works too. Filters only and does not switch the request scope; combined with tenant_id and other filters as an intersection. A tenant credential sending a non-empty value gets 403 |
| `type` | string |  | Message type, such as announcement or cert-expire. |
| `site_id` | integer |  | Site ID |
| `site_ids` | string |  | Filter by sites: comma-separated positive integers, at most 200 after deduplication (more, or a malformed value, returns 422); a single ID works too; combined with other filters as an intersection |
| `read` | boolean |  | Read filter. false returns unread only (same scope as the bell unread count, announcements excluded) and true returns read only within that scope; omit for no filter. For administrators the state is the administrator's own. |

```sh
curl "https://panel.example.com/api/v2/messages" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### POST `/api/v2/messages`

Publish announcement · Authentication: Admin only

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `content` | string |  | Message body. Announcements are sanitized with an allow-list before saving (paragraphs, headings, bold, italic, lists, quotes, http(s) links); scripts, event attributes, images and tables are removed. |
| `is_external` | boolean |  | When true, clicking jumps to url and url is required; otherwise content is required. |
| `is_important` | boolean |  | Whether to mark it as important (an "Important" tag before the title). |
| `is_pinned` | boolean |  | Whether it is pinned. A newly pinned one goes first in the pinned group; reorder with PUT /messages/pin-order. |
| `is_popup` | boolean |  | Whether to show it as a pop-up. |
| `is_show` | boolean |  | Whether the message is visible. |
| `sort` | integer |  | Order within the pinned group (smaller first); meaningful only for pinned announcements. The server puts a newly pinned one first; reorder with PUT /messages/pin-order. |
| `title` | string | Yes | Message title. |
| `url` | string |  | Link opened on click when is_external is true. |

```sh
curl -X POST "https://panel.example.com/api/v2/messages" \
  -H "X-API-Key: $GOCDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content":"今晚 23 点维护。","title":"维护通知"}'
```

### PUT `/api/v2/messages/pin-order`

Reorder pinned announcements · Authentication: Admin only

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `ids` | integer[] | Yes | Pinned announcement ids in the desired order (first is shown first). |

```sh
curl -X PUT "https://panel.example.com/api/v2/messages/pin-order" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### POST `/api/v2/messages/read`

Mark messages as read · Authentication: User

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `ids` | integer[] |  | Pinned announcement ids in the desired order (first is shown first). |

```sh
curl -X POST "https://panel.example.com/api/v2/messages/read" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### GET `/api/v2/messages/{id}`

Get message · Authentication: User (some parameters admin only)

```sh
curl "https://panel.example.com/api/v2/messages/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### PUT `/api/v2/messages/{id}`

Update message · Authentication: Admin only

Request body:

| Field | Type | Required | Description |
|---|---|---|---|
| `content` | string |  | Message body. Announcements are sanitized with an allow-list before saving (paragraphs, headings, bold, italic, lists, quotes, http(s) links); scripts, event attributes, images and tables are removed. |
| `is_external` | boolean |  | When true, clicking jumps to url and url is required; otherwise content is required. |
| `is_important` | boolean |  | Whether to mark it as important (an "Important" tag before the title). |
| `is_pinned` | boolean |  | Whether it is pinned. A newly pinned one goes first in the pinned group; reorder with PUT /messages/pin-order. |
| `is_popup` | boolean |  | Whether to show it as a pop-up. |
| `is_show` | boolean |  | Whether the message is visible. |
| `sort` | integer |  | Order within the pinned group (smaller first); meaningful only for pinned announcements. The server puts a newly pinned one first; reorder with PUT /messages/pin-order. |
| `title` | string |  | Message title. |
| `url` | string |  | Link opened on click when is_external is true. |

```sh
curl -X PUT "https://panel.example.com/api/v2/messages/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

### DELETE `/api/v2/messages/{id}`

Delete message · Authentication: Admin only

```sh
curl -X DELETE "https://panel.example.com/api/v2/messages/{id}" \
  -H "X-API-Key: $GOCDN_API_KEY"
```

Messages object:

| Field | Type | Required | Description |
|---|---|---|---|
| `content` | string |  | Message body. Announcements are sanitized with an allow-list before saving (paragraphs, headings, bold, italic, lists, quotes, http(s) links); scripts, event attributes, images and tables are removed. |
| `count` | integer |  | Number of unread messages. |
| `created_at` | string |  | Created at (read-only) |
| `id` | integer |  | Record ID (read-only) |
| `ids` | integer[] | Yes | Pinned announcement ids in the desired order (first is shown first). |
| `is_external` | boolean |  | When true, clicking jumps to url and url is required; otherwise content is required. |
| `is_important` | boolean |  | Whether to mark it as important (an "Important" tag before the title). |
| `is_pinned` | boolean |  | Whether it is pinned. A newly pinned one goes first in the pinned group; reorder with PUT /messages/pin-order. |
| `is_popup` | boolean |  | Whether to show it as a pop-up. |
| `is_show` | boolean |  | Whether the message is visible. |
| `read` | boolean |  | Whether the message has been read. (read-only) |
| `read_count` | integer |  | Number of tenants that have read it (tenants only, administrators excluded; returned to administrators only). (read-only) |
| `site_id` | integer |  | Site ID (read-only) |
| `sort` | integer |  | Order within the pinned group (smaller first); meaningful only for pinned announcements. The server puts a newly pinned one first; reorder with PUT /messages/pin-order. |
| `tenant_id` | integer |  | Recipient tenant; empty for announcements. (read-only) |
| `title` | string |  | Message title. |
| `title_args` | object |  | Arguments of the title key: name → string, number, or a clause {key, args} (a clause is looked up in the dictionary and filled the same way, and may nest). (read-only) |
| `title_key` | string |  | Title key (the Chinese sentence with {name} placeholders). When set, the panel looks it up in the UI-language dictionary and fills the placeholders from title_args; when null (old messages, announcements, edited titles) the panel shows title as is. (read-only) |
| `type` | string |  | announcement = announcement; others are notification types (such as cert-expire, package-expire). (read-only) |
| `updated_at` | string |  | Updated at (read-only) |
| `url` | string |  | Link opened on click when is_external is true. |
