Quickstart
These are the basic steps to follow to interact with the Ghost Content API in your TypeScript project.
Get your Ghost API Key and Ghost version number
Connect to your ghost blog and create a new Integration to get your Content API Key.
You will need the URL of your Ghost Blog and the Content API Key
To know which Ghost Version you are using go in the Settings and click on top right button "About Ghost":
Here the version is "v5.47.0"
Installation
pnpm add @ts-ghost/content-api
(Optional) Create .env
variable
GHOST_URL="https://myblog.com"
GHOST_CONTENT_API_KEY="e9b414c5d95a5436a647ff04ab"
Use in your TypeScript file
import { TSGhostContentAPI } from "@ts-ghost/content-api";
const api = new TSGhostContentAPI(
process.env.GHOST_URL || "",
process.env.GHOST_CONTENT_API_KEY || "",
"v5.47.0"
);
export async function getBlogPosts() {
const response = await api.posts
.browse({
limit: 10,
})
.fields({
title: true,
slug: true,
id: true,
})
.fetch();
if (!response.success) {
throw new Error(response.errors.join(", "));
}
// Response data is typed correctly with only the requested fields
// {
// title: string;
// slug: string;
// id: string;
// }[]
return response.data;
}