0

Retrieve a single post

by
Published Oct 17, 2025

This endpoint can be used to get the number of likes on a post using the `actions_summary` property in the response. `actions_summary` responses with the id of `2` signify a `like`. If there are no `actions_summary` items with the id of `2`, that means there are 0 likes. Other ids likely refer to various different flag types.

Script discourse Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Discourse = {
3
  apiKey: string;
4
  defaultHost: string;
5
  apiUsername: string;
6
};
7
/**
8
 * Retrieve a single post
9
 * This endpoint can be used to get the number of likes on a post using the
10
`actions_summary` property in the response. `actions_summary` responses
11
with the id of `2` signify a `like`. If there are no `actions_summary`
12
items with the id of `2`, that means there are 0 likes. Other ids likely
13
refer to various different flag types.
14

15
 */
16
export async function main(auth: Discourse, id: string) {
17
  const url = new URL(`https://${auth.defaultHost}/posts/${id}.json`);
18

19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      "API-KEY": auth.apiKey,
23
      "API-USERNAME": auth.apiUsername,
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33