Migrating from Ghost SDK

Introduction

Ghost SDK is a great library to interact with the Ghost Content API. It is a very mature library, but if you prefer a more strongly typed and checked library you can use this one. Generally speaking, the API is very similar, but there are some differences.

Common "gotchas"

Filtering posts by author or tag is not supported. You can only filter by authors or tags (plural).

import { TSGhostAdminAPI, type Post } from "@ts-ghost/admin-api";
 
const api = new TSGhostAdminAPI(env.GHOST_URL, env.GHOST_ADMIN_API_KEY, "v5.0");
 
let posts: Post[] = [];
let cursor = await api.posts
  .browse({ filter: "tags:hash-tag" })
  .include({ authors: true, tags: true })
  .fetch();
if (result.success) {
  posts = result.data;
}
return posts

Why ?

The Ghost Content API is a bit inconsistent in the way it handles filtering. For example, you can filter by authors but also by author. The same goes for tags and tag. But in the result author and tag are not present, it's only primary_author, authors, primary_tag, tags. So ts-ghost tries to be more consistent and only supports filtering by attributes present on the result object.