(posts)
- createTopicPostPM - Creates a new topic, a new post, or a private message
- deletePost - delete a single post
- getPost - Retrieve a single post
- listPosts - List latest posts across topics
- lockPost - Lock a post from being edited
- performPostAction - Like a post and other actions
- postReplies - List replies to a post
- updatePost - Update a single post
Creates a new topic, a new post, or a private message
import { SDK } from "@lukehagar/discoursejs";
async function run() {
const sdk = new SDK();
const res = await sdk.posts.createTopicPostPM({
archetype: "private_message",
raw: "<value>",
targetRecipients: "blake,sam",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
request |
operations.CreateTopicPostPMRequestBody | ✔️ | The request object to use for the request. |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.CreateTopicPostPMResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
delete a single post
import { SDK } from "@lukehagar/discoursejs";
import { DeletePostRequest, DeletePostRequestBody } from "@lukehagar/discoursejs/dist/sdk/models/operations";
async function run() {
const sdk = new SDK();
const id: number = 188146;
const requestBody: DeletePostRequestBody = {
forceDestroy: true,
};
const res = await sdk.posts.deletePost(id, requestBody);
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
number | ✔️ | N/A |
requestBody |
operations.DeletePostRequestBody | ➖ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.DeletePostResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
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.
import { SDK } from "@lukehagar/discoursejs";
import { GetPostRequest } from "@lukehagar/discoursejs/dist/sdk/models/operations";
async function run() {
const sdk = new SDK();
const id: string = "<value>";
const res = await sdk.posts.getPost(id);
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.GetPostResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
List latest posts across topics
import { SDK } from "@lukehagar/discoursejs";
import { ListPostsRequest } from "@lukehagar/discoursejs/dist/sdk/models/operations";
async function run() {
const sdk = new SDK();
const apiKey: string = "<value>";
const apiUsername: string = "<value>";
const before: string = "<value>";
const res = await sdk.posts.listPosts(apiKey, apiUsername, before);
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
apiKey |
string | ✔️ | N/A |
apiUsername |
string | ✔️ | N/A |
before |
string | ➖ | Load posts with an id lower than this value. Useful for pagination. |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.ListPostsResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Lock a post from being edited
import { SDK } from "@lukehagar/discoursejs";
import { LockPostRequest, LockPostRequestBody } from "@lukehagar/discoursejs/dist/sdk/models/operations";
async function run() {
const sdk = new SDK();
const apiKey: string = "<value>";
const apiUsername: string = "<value>";
const id: string = "<value>";
const requestBody: LockPostRequestBody = {
locked: "<value>",
};
const res = await sdk.posts.lockPost(apiKey, apiUsername, id, requestBody);
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
apiKey |
string | ✔️ | N/A |
apiUsername |
string | ✔️ | N/A |
id |
string | ✔️ | N/A |
requestBody |
operations.LockPostRequestBody | ➖ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.LockPostResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Like a post and other actions
import { SDK } from "@lukehagar/discoursejs";
import { PerformPostActionRequest, PerformPostActionRequestBody } from "@lukehagar/discoursejs/dist/sdk/models/operations";
async function run() {
const sdk = new SDK();
const apiKey: string = "<value>";
const apiUsername: string = "<value>";
const requestBody: PerformPostActionRequestBody = {
id: 315075,
postActionTypeId: 159481,
};
const res = await sdk.posts.performPostAction(apiKey, apiUsername, requestBody);
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
apiKey |
string | ✔️ | N/A |
apiUsername |
string | ✔️ | N/A |
requestBody |
operations.PerformPostActionRequestBody | ➖ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.PerformPostActionResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
List replies to a post
import { SDK } from "@lukehagar/discoursejs";
import { PostRepliesRequest } from "@lukehagar/discoursejs/dist/sdk/models/operations";
async function run() {
const sdk = new SDK();
const id: string = "<value>";
const res = await sdk.posts.postReplies(id);
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.PostRepliesResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Update a single post
import { SDK } from "@lukehagar/discoursejs";
import { Post, UpdatePostRequest, UpdatePostRequestBody } from "@lukehagar/discoursejs/dist/sdk/models/operations";
async function run() {
const sdk = new SDK();
const id: string = "<value>";
const requestBody: UpdatePostRequestBody = {
post: {
raw: "<value>",
},
};
const res = await sdk.posts.updatePost(id, requestBody);
if (res.statusCode == 200) {
// handle response
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | N/A |
requestBody |
operations.UpdatePostRequestBody | ➖ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Promise<operations.UpdatePostResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |