Skip to content

ApexDevelopment/cohost-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cohost-api

An unofficial API wrapper for cohost.org that uses tRPC.

cohost-api is in very early development!

Usage

npm install cohost-api

import { Client, PostBuilder } from "cohost-api";

const client = new Client();

async function demo() {
  // Log in to Cohost
  let user = await client.login("EMAIL_ADDRESS", "YOUR_PASSWORD");
  // Get the first project
  let project = user?.projects[0];

  if (!project) {
    console.log("Couldn't log in :(");
    return;
  }

  // Switch to the project (not always necessary, but good practice as some endpoints require it)
  user?.switchProject(project);

  // Create new post
  let post = new PostBuilder();
    .addMarkdownBlock("hello from cohost-api!")
    .build();

  // Send to Cohost
  project.createDraft(post); // or use .createPost() to publish it immediately

  // Attach a file
  // This must be done after the post is created/drafted due to how the Cohost API works
  project.addAttachment(post, "file.png");
}

demo(); // Check your Cohost page!

API Reference

The API reference can be found in this document.

What works, and what doesn't

Working

  • Getting your projects' profile information
  • Creating posts & post drafts
  • Uploading attachments
  • Editing existing posts & post drafts
  • Liking and unliking posts
  • Getting a list of a project's posts
  • Getting a list of followers for a project
  • Getting a list of projects followed by your project

Not working

  • Editing a project's profile information
  • Sharing other users' posts to your project (i.e. reblogging)
  • Getting a project's notifications
  • Anything else not explicitly mentioned

Glossary

Term Definition
Project A page viewable as a Cohost profile with an @handle.
User A Cohost account with an email address and password. Users can have multiple projects, the same way a Tumblr account can have multiple blogs.
Draft A post which has not been published, but still belongs to a project, and can be viewed via a direct link.

Reasons not to use this (yet)

  • The Cohost tRPC API is undocumented and not meant for public use.
  • The Cohost tRPC API can change at any time and break this package.
  • This package is in flux and breaking changes will happen all the time until it is stable.
  • The documentation for this package is incomplete, so using it might be confusing.

About

An unofficial tRPC-based wrapper API for Cohost.org

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published