npm add @lukehagar/discoursejs
yarn add @lukehagar/discoursejs
import { SDK } from "@lukehagar/discoursejs";
async function run() {
const sdk = new SDK();
const res = await sdk.backups.createBackup({
withUploads: false,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
- createBackup - Create backup
- downloadBackup - Download backup
- getBackups - List backups
- sendDownloadBackupEmail - Send download backup email
- adminListBadges - List badges
- createBadge - Create badge
- deleteBadge - Delete badge
- listUserBadges - List badges for a user
- updateBadge - Update badge
- addGroupMembers - Add group members
- createGroup - Create a group
- deleteGroup - Delete a group
- getGroup - Get a group
- listGroupMembers - List group members
- listGroups - List groups
- removeGroupMembers - Remove group members
- updateGroup - Update a group
- activateUser - Activate a user
- adminGetUser - Get a user by id
- adminListUsers - Get a list of users
- anonymizeUser - Anonymize a user
- changePassword - Change password
- createUser - Creates a user
- deactivateUser - Deactivate a user
- deleteUser - Delete a user
- getUser - Get a single user by username
- getUserEmails - Get email addresses belonging to a user
- getUserExternalId - Get a user by external_id
- getUserIdentiyProviderExternalId - Get a user by identity provider external ID
- listUserActions - Get a list of user actions
- listUserBadges - List badges for a user
- listUsersPublic - Get a public list of users
- logOutUser - Log a user out
- refreshGravatar - Refresh gravatar
- sendPasswordResetEmail - Send password reset email
- silenceUser - Silence a user
- suspendUser - Suspend a user
- updateAvatar - Update avatar
- updateEmail - Update email
- updateUser - Update a user
- updateUsername - Update username
- activateUser - Activate a user
- adminGetUser - Get a user by id
- adminListUsers - Get a list of users
- anonymizeUser - Anonymize a user
- deactivateUser - Deactivate a user
- deleteUser - Delete a user
- logOutUser - Log a user out
- refreshGravatar - Refresh gravatar
- silenceUser - Silence a user
- suspendUser - Suspend a user
- createCategory - Creates a category
- getCategory - Show category
- getSite - Get site info
- listCategories - Retrieves a list of categories
- listCategoryTopics - List topics
- updateCategory - Updates a category
- createInvite - Create an invite
- inviteToTopic - Invite to topic
- bookmarkTopic - Bookmark topic
- createTopicPostPM - Creates a new topic, a new post, or a private message
- createTopicTimer - Create topic timer
- getTopic - Get a single topic
- getTopicByExternalId - Get topic by external_id
- inviteToTopic - Invite to topic
- listLatestTopics - Get the latest topics
- listTopTopics - Get the top topics filtered by period
- removeTopic - Remove a topic
- setNotificationLevel - Set notification level
- updateTopic - Update a topic
- updateTopicStatus - Update the status of a topic
- updateTopicTimestamp - Update topic timestamp
- getNotifications - Get the notifications that belong to the current user
- markNotificationsAsRead - Mark notifications as read
- 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
- getUserSentPrivateMessages - Get a list of private messages sent for a user
- listUserPrivateMessages - Get a list of private messages for a user
- search - Search for a term
- getSite - Get site info
- createTagGroup - Creates a tag group
- getTag - Get a specific tag
- getTagGroup - Get a single tag group
- listTagGroups - Get a list of tag groups
- listTags - Get a list of tags
- updateTagGroup - Update tag group
- abortMultipart - Abort multipart upload
- batchPresignMultipartParts - Generates batches of presigned URLs for multipart parts
- completeExternalUpload - Completes a direct external upload
- completeMultipart - Complete multipart upload
- createMultipartUpload - Creates a multipart external upload
- createUpload - Creates an upload
- generatePresignedPut - Initiates a direct external upload
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Example
import { SDK } from "@lukehagar/discoursejs";
async function run() {
const sdk = new SDK();
let res;
try {
res = await sdk.backups.createBackup({
withUploads: false,
});
} catch (err) {
if (err instanceof errors.SDKError) {
console.error(err); // handle exception
throw err;
}
}
if (res.statusCode == 200) {
// handle response
}
}
run();
You can override the default server globally by passing a server index to the serverIdx: number
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://{defaultHost} |
defaultHost (default is discourse.example.com ) |
import { SDK } from "@lukehagar/discoursejs";
async function run() {
const sdk = new SDK({
serverIdx: 0,
});
const res = await sdk.backups.createBackup({
withUploads: false,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Some of the server options above contain variables. If you want to set the values of those variables, the following optional parameters are available when initializing the SDK client instance:
defaultHost: string
The default server can also be overridden globally by passing a URL to the serverURL: str
optional parameter when initializing the SDK client instance. For example:
import { SDK } from "@lukehagar/discoursejs";
async function run() {
const sdk = new SDK({
serverURL: "https://{defaultHost}",
});
const res = await sdk.backups.createBackup({
withUploads: false,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
The Typescript SDK makes API calls using the axios HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom AxiosInstance
object.
For example, you could specify a header for every request that your sdk makes as follows:
import { @lukehagar/discoursejs } from "SDK";
import axios from "axios";
const httpClient = axios.create({
headers: {'x-custom-header': 'someValue'}
})
const sdk = new SDK({defaultClient: httpClient});
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!