- Classes
- Enums
cohost-api / Exports / Client
A Cohost API client. Instantiate this class to interact with the Cohost API.
• new Client(): Client
Creates a new Cohost API client. Requires no arguments.
• loggedIn: boolean
= false
Whether the client is logged in.
• user: null
| User
= null
The currently logged in user. Once logged in, can be used to access the user's information and projects.
▸ login(email
, password
): Promise
<null
| User
>
Logs in to Cohost, creating a new session.
Name | Type | Description |
---|---|---|
email |
string |
The email of the User. |
password |
string |
The User's password. |
Promise
<null
| User
>
The logged in User, or null if the login failed.
cohost-api / Exports / EditedProject
A class representing a project on Cohost that the user has editing privileges for.
-
↳
EditedProject
- atomFeedURL
- avatarShape
- avatarURL
- dek
- description
- displayName
- flags
- frequentlyUsedTags
- handle
- headerPreviewURL
- headerURL
- id
- loggedOutPostVisibility
- privacy
- pronouns
- url
- addAttachment
- createDraft
- createPost
- deletePost
- getPosts
- likePost
- publishDraft
- unlikePost
- updatePost
• atomFeedURL: string
• avatarShape: string
• avatarURL: string
• dek: string
The project subheading.
• description: string
The description/bio of the project.
• displayName: string
The display name, which shows up on the timeline.
• flags: string
[]
• frequentlyUsedTags: string
[]
• handle: string
The handle of the project, without the @.
• headerPreviewURL: string
• headerURL: string
• id: number
The unique ID of the project.
• loggedOutPostVisibility: Privacy
Project.loggedOutPostVisibility
• privacy: Privacy
• pronouns: string
• url: string
▸ addAttachment(post
, filepath
): Promise
<number
>
Adds an attachment to a post. This must be done after the post is created. This is a limitation of the Cohost API.
Name | Type | Description |
---|---|---|
post |
Post |
The post to add the attachment to. |
filepath |
string |
The path to the file to upload. |
Promise
<number
>
The ID of the attachment.
▸ addAttachment(post
, filename
, mimeType
, attachment
, width
, height
): Promise
<number
>
Adds an attachment to a post. This must be done after the post is created. This is a limitation of the Cohost API.
Name | Type | Description |
---|---|---|
post |
Post |
The post to add the attachment to. |
filename |
string |
The name of the file to upload. |
mimeType |
string |
The MIME type of the file. |
attachment |
Buffer |
A Buffer containing the file to upload. |
width |
number |
The width of the image. |
height |
number |
The height of the image. |
Promise
<number
>
The ID of the attachment.
▸ createDraft(post
): Promise
<Post
>
Creates a draft of a post in the project.
Name | Type | Description |
---|---|---|
post |
Post |
The post to send to the project's drafts. |
Promise
<Post
>
The post with its postId set.
▸ createPost(post
): Promise
<Post
>
Publishes a post to the project.
Name | Type | Description |
---|---|---|
post |
Post |
The post to publish. |
Promise
<Post
>
The post with its postId set.
▸ deletePost(post
): Promise
<void
>
Deletes a post from the project.
Name | Type | Description |
---|---|---|
post |
number | Post |
The post or ID of the post to delete. |
Promise
<void
>
▸ getPosts(page?
, options?
): Promise
<any
>
Gets a page of posts from the project. The Cohost API returns 20 posts per page.
Name | Type | Default value | Description |
---|---|---|---|
page |
number |
0 |
The page of posts to get. Defaults to 0. |
options |
Object |
undefined |
Options for filtering the returned posts. |
options.hideAsks |
boolean |
undefined |
- |
options.hideReplies |
boolean |
undefined |
- |
options.hideShares |
boolean |
undefined |
- |
options.pinnedPostsAtTop |
boolean |
undefined |
- |
Promise
<any
>
An array of TimelinePosts from the project.
▸ likePost(post
): Promise
<void
>
Gives a like from this project to a post.
Name | Type | Description |
---|---|---|
post |
number | Post |
The post to like. |
Promise
<void
>
▸ publishDraft(draftPost
): Promise
<void
>
Publishes a post from the project's drafts.
In the future, this function will also accept a number as the first argument, which will be the ID of the draft post to publish.
Name | Type | Description |
---|---|---|
draftPost |
Post |
The draft post to publish. |
Promise
<void
>
▸ unlikePost(post
): Promise
<void
>
Removes a like from this project to a post.
Name | Type | Description |
---|---|---|
post |
number | Post |
The post to unlike. |
Promise
<void
>
▸ updatePost(postToUpdate
, newPost
): Promise
<void
>
Updates a post in the project.
Name | Type | Description |
---|---|---|
postToUpdate |
number | Post |
The post or ID of the post to update. |
newPost |
Post |
The new post data. |
Promise
<void
>
cohost-api / Exports / Post
A class representing a post on Cohost.
This class does not contain all the data that a post can have. See the TimelinePost class for a more complete representation of a post.
This class is not used for creating posts. Instead, use the PostBuilder class to create a new post.
• content: Object
Name | Type |
---|---|
adultContent |
boolean |
blocks |
object [] |
cws |
string [] |
headline |
string |
postState |
PostState |
tags |
string [] |
• postId: number
• projectHandle: string
cohost-api / Exports / PostBuilder
A class for creating Post objects.
Example usage:
let postBuilder = new PostBuilder("Hello, world!");
postBuilder.addMarkdownBlock("This is a test post from cohost-api.");
postBuilder.addTag("cohost-api");
let finishedPost = postBuilder.build();
• new PostBuilder(headline?
, adultContent?
): PostBuilder
Creates a new PostBuilder, used for easily constructing a Post object.
Name | Type | Default value | Description |
---|---|---|---|
headline |
string |
"" |
The headline for the post. Appears at the top of a post. Defaults to an empty string. |
adultContent |
boolean |
false |
Whether the post contains adult content. Defaults to false. |
▸ addBlock(type
, block
): PostBuilder
Adds a block of content to the post. Only use this if you are familiar with the types of content blocks that Cohost supports. Otherwise, use addMarkdownBlock()
.
Name | Type | Description |
---|---|---|
type |
string |
The type of content block to add. |
block |
object |
The content of the block. |
The PostBuilder object, for chaining.
▸ addCw(cw
): PostBuilder
Adds a content warning to the post.
Name | Type | Description |
---|---|---|
cw |
string |
The content warning to add to the post. |
The PostBuilder object, for chaining.
▸ addMarkdownBlock(content
): PostBuilder
Adds a block of markdown text to the post.
Name | Type | Description |
---|---|---|
content |
string |
The markdown string to add to the post. |
The PostBuilder object, for chaining.
▸ addTag(tag
): PostBuilder
Adds a #tag to the post.
Name | Type | Description |
---|---|---|
tag |
string |
The #tag to add to the post. You do not need to include the # symbol. |
The PostBuilder object, for chaining.
▸ build(): Post
Builds the Post object from the data in the PostBuilder.
The Post object.
cohost-api / Exports / Project
A class representing a project on Cohost. A user can have multiple projects.
Do not instantiate this class directly. Projects can only be obtained from the API. cohost-api does not yet support creating new projects.
-
Project
- atomFeedURL
- avatarShape
- avatarURL
- dek
- description
- displayName
- flags
- frequentlyUsedTags
- handle
- headerPreviewURL
- headerURL
- id
- loggedOutPostVisibility
- privacy
- pronouns
- url
• atomFeedURL: string
• avatarShape: string
• avatarURL: string
• dek: string
The project subheading.
• description: string
The description/bio of the project.
• displayName: string
The display name, which shows up on the timeline.
• flags: string
[]
• frequentlyUsedTags: string
[]
• handle: string
The handle of the project, without the @.
• headerPreviewURL: string
• headerURL: string
• id: number
The unique ID of the project.
• loggedOutPostVisibility: Privacy
• privacy: Privacy
• pronouns: string
• url: string
▸ getPosts(page?
, options?
): Promise
<any
>
Gets a page of posts from the project. The Cohost API returns 20 posts per page.
Name | Type | Default value | Description |
---|---|---|---|
page |
number |
0 |
The page of posts to get. Defaults to 0. |
options |
Object |
undefined |
Options for filtering the returned posts. |
options.hideAsks |
boolean |
undefined |
- |
options.hideReplies |
boolean |
undefined |
- |
options.hideShares |
boolean |
undefined |
- |
options.pinnedPostsAtTop |
boolean |
undefined |
- |
Promise
<any
>
An array of TimelinePosts from the project.
cohost-api / Exports / User
The currently logged in user. Do not instantiate this class; instead, use the login()
method of the Client class to log in.
This class is not used for any other users because the Cohost API does not provide a way to get other users; it only provides other users' projects.
• email: string
The email address of this user.
• id: number
The unique ID of this user.
• projects: EditedProject
[] = []
The projects that this user is able to edit.
▸ getFollowers(offset?
, limit?
): Promise
<Project
[]>
Gets the projects that follow the current project. Use switchProject()
to change the current project.
This method is paginated, and the default offset is 0 and the default limit is 10.
Name | Type | Default value | Description |
---|---|---|---|
offset |
number |
0 |
How many projects to skip. |
limit |
number |
10 |
The maximum number of projects to get. |
Promise
<Project
[]>
The followers of this project.
▸ getFollowing(sortOrder
, offset?
, limit?
, beforeTimestamp?
): Promise
<Project
[]>
Gets the projects that the current project follows. Use switchProject()
to change the current project.
Name | Type | Default value | Description |
---|---|---|---|
sortOrder |
SortOrder |
undefined |
What order to sort the projects in. |
offset |
number |
0 |
How many projects to skip. |
limit |
number |
10 |
The maximum number of projects to get. |
beforeTimestamp |
number |
undefined |
Not sure yet. Likely has to do with the last time the project posted. |
Promise
<Project
[]>
The projects that this project follows.
▸ liked(post
): any
Checks if the current project has liked a post. Use switchProject()
to change the current project.
Name | Type | Description |
---|---|---|
post |
number | Post |
The post to check if the project has liked. |
any
Whether the project has liked the post.
▸ switchProject(project
): void
Switches the currently active project to the given project. This is relevant for API calls related to notifications and getting the "liked" state of posts.
Name | Type | Description |
---|---|---|
project |
EditedProject |
The project to switch to. |
void
cohost-api / Exports / PostState
Whether a post is a draft or published.
• DRAFT = 0
• PUBLISHED = 1
cohost-api / Exports / Privacy
• PRIVATE = "private"
• PUBLIC = "public"
cohost-api / Exports / SortOrder
• ALPHA_ASC = "alpha-asc"
• ALPHA_DESC = "alpha-desc"
• FOLLOWED_ASC = "followed-asc"
• FOLLOWED_DESC = "followed-desc"
• RECENTLY_POSTED = "recently-posted"