21 KiB
Posts
(posts)
Available Operations
- 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
createTopicPostPM
Creates a new topic, a new post, or a private message
Example Usage
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();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.CreateTopicPostPMRequestBody | ✔️ | The request object to use for the request. |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Response
Promise<operations.CreateTopicPostPMResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |
deletePost
delete a single post
Example Usage
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();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
number | ✔️ | N/A |
requestBody |
operations.DeletePostRequestBody | ➖ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Response
Promise<operations.DeletePostResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |
getPost
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.
Example Usage
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();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Response
Promise<operations.GetPostResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |
listPosts
List latest posts across topics
Example Usage
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();
Parameters
| 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. |
Response
Promise<operations.ListPostsResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |
lockPost
Lock a post from being edited
Example Usage
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();
Parameters
| 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. |
Response
Promise<operations.LockPostResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |
performPostAction
Like a post and other actions
Example Usage
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();
Parameters
| 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. |
Response
Promise<operations.PerformPostActionResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |
postReplies
List replies to a post
Example Usage
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();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Response
Promise<operations.PostRepliesResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |
updatePost
Update a single post
Example Usage
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();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | ✔️ | N/A |
requestBody |
operations.UpdatePostRequestBody | ➖ | N/A |
config |
AxiosRequestConfig | ➖ | Available config options for making requests. |
Response
Promise<operations.UpdatePostResponse>
Errors
| Error Object | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4xx-5xx | / |