Files
discoursejs/docs/sdks/posts

Posts

(posts)

Available Operations

createTopicPostPM

Creates a new topic, a new post, or a private message

Example Usage

import { SDK } from "@lukehagar/discoursejs";

const sdk = new SDK();

async function run() {
  const result = await sdk.posts.createTopicPostPM({
    archetype: "private_message",
    raw: "<value>",
    targetRecipients: "blake,sam",
  });

  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsCreateTopicPostPM } from "@lukehagar/discoursejs/funcs/postsCreateTopicPostPM.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsCreateTopicPostPM(sdk, {
    archetype: "private_message",
    raw: "<value>",
    targetRecipients: "blake,sam",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.CreateTopicPostPMRequestBody ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CreateTopicPostPMResponseBody>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

deletePost

delete a single post

Example Usage

import { SDK } from "@lukehagar/discoursejs";

const sdk = new SDK();

async function run() {
  await sdk.posts.deletePost(188146, {
    forceDestroy: true,
  });

  
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsDeletePost } from "@lukehagar/discoursejs/funcs/postsDeletePost.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsDeletePost(sdk, 928159, {
    forceDestroy: true,
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
id number ✔️ N/A
requestBody operations.DeletePostRequestBody N/A
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<void>

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";

const sdk = new SDK();

async function run() {
  const result = await sdk.posts.getPost("<value>");

  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsGetPost } from "@lukehagar/discoursejs/funcs/postsGetPost.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsGetPost(sdk, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.GetPostResponseBody>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

listPosts

List latest posts across topics

Example Usage

import { SDK } from "@lukehagar/discoursejs";

const sdk = new SDK();

async function run() {
  const result = await sdk.posts.listPosts("<value>", "<value>");

  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsListPosts } from "@lukehagar/discoursejs/funcs/postsListPosts.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsListPosts(sdk, "<value>", "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

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.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ListPostsResponseBody>

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";

const sdk = new SDK();

async function run() {
  const result = await sdk.posts.lockPost("<value>", "<value>", "<value>");

  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsLockPost } from "@lukehagar/discoursejs/funcs/postsLockPost.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsLockPost(sdk, "<value>", "<value>", "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
apiKey string ✔️ N/A
apiUsername string ✔️ N/A
id string ✔️ N/A
requestBody operations.LockPostRequestBody N/A
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.LockPostResponseBody>

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";

const sdk = new SDK();

async function run() {
  const result = await sdk.posts.performPostAction("<value>", "<value>");

  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsPerformPostAction } from "@lukehagar/discoursejs/funcs/postsPerformPostAction.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsPerformPostAction(sdk, "<value>", "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
apiKey string ✔️ N/A
apiUsername string ✔️ N/A
requestBody operations.PerformPostActionRequestBody N/A
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.PerformPostActionResponseBody>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

postReplies

List replies to a post

Example Usage

import { SDK } from "@lukehagar/discoursejs";

const sdk = new SDK();

async function run() {
  const result = await sdk.posts.postReplies("<value>");

  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsPostReplies } from "@lukehagar/discoursejs/funcs/postsPostReplies.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsPostReplies(sdk, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.PostRepliesResponseBody[]>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

updatePost

Update a single post

Example Usage

import { SDK } from "@lukehagar/discoursejs";

const sdk = new SDK();

async function run() {
  const result = await sdk.posts.updatePost("<value>");

  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { SDKCore } from "@lukehagar/discoursejs/core.js";
import { postsUpdatePost } from "@lukehagar/discoursejs/funcs/postsUpdatePost.js";

// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore();

async function run() {
  const res = await postsUpdatePost(sdk, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
id string ✔️ N/A
requestBody operations.UpdatePostRequestBody N/A
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.UpdatePostResponseBody>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /