openapi
🏗 Welcome to your new SDK! 🏗
It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:
- 🛠 Make your SDK feel handcrafted by customizing it
- ♻️ Refine your SDK quickly by iterating locally with the Speakeasy CLI
- 🎁 Publish your SDK to package managers by configuring automatic publishing
- ✨ When ready to productionize, delete this section from the README
SDK Installation
NPM
npm add openapi
Yarn
yarn add openapi
SDK Example Usage
Example
import { SDK } from "openapi";
async function run() {
const sdk = new SDK();
const res = await sdk.backups.createBackup({
withUploads: false,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Available Resources and Operations
backups
- createBackup - Create backup
- downloadBackup - Download backup
- getBackups - List backups
- sendDownloadBackupEmail - Send download backup email
badges
- adminListBadges - List badges
- createBadge - Create badge
- deleteBadge - Delete badge
- listUserBadges - List badges for a user
- updateBadge - Update badge
groups
- 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
users
- 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
admin
- 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
categories
- createCategory - Creates a category
- getCategory - Show category
- getSite - Get site info
- listCategories - Retrieves a list of categories
- listCategoryTopics - List topics
- updateCategory - Updates a category
invites
- createInvite - Create an invite
- inviteToTopic - Invite to topic
topics
- 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
notifications
- getNotifications - Get the notifications that belong to the current user
- markNotificationsAsRead - Mark notifications as read
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
privateMessages
- 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 - Search for a term
site
- getSite - Get site info
tags
- 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
uploads
- 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
Error Handling
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 "openapi";
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();
Server Selection
Select Server by Index
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) |
Example
import { SDK } from "openapi";
async function run() {
const sdk = new SDK({
serverIdx: 0,
});
const res = await sdk.backups.createBackup({
withUploads: false,
});
if (res.statusCode == 200) {
// handle response
}
}
run();
Variables
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
Override Server URL Per-Client
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 "openapi";
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();
Custom HTTP Client
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 { openapi } from "SDK";
import axios from "axios";
const httpClient = axios.create({
headers: {'x-custom-header': 'someValue'}
})
const sdk = new SDK({defaultClient: httpClient});
Development
Maturity
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.
Contributions
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!