ApexDevelopment / cohost-api

An unofficial tRPC-based wrapper API for Cohost.org
1 stars 0 forks source link
api cohost cohost-api nodejs

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

Not working

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)