Ghost is an open source blogging platform that allows users to build self-hosted or paid subscriptions.

The Ghost API

Ghost, like many other web services out there has a REST API. Using the Ghost API (ghost.org), you can manage just about everything you can via the Ghost editor (ghost.org). You can manage posts, pages, authors, tags and every other entity inside of Ghost.

The Ghost API is split into two separate APIs; Admin (docs.ghost.org) and Content (docs.ghost.org).

The Content API is an API that is read-only and allows anyone with the appropriate API key to read every entity inside of the Ghost blogging platform. The Content API allows bloggers and developers to syndicate or integrate Ghost blog content into various other sites and services.

The Admin API provides all of the same access the Content API does but with all of the bells and whistles. The Admin API gives a developer full control over all blog entities; not just read access.

Using the Admin API, you can create, modify and remove Ghost blog platform entities like posts, pages, tags, etc. This is the API I've chosen to build upon with PowerShell.

Managing the Ghost API with PowerShell

A developer could choose to manage their Ghost blog many different ways using different languages. Ghost has provided various tools (docs.ghost.org) and even a command-line utility to manage Ghost blogs. However, I know PowerShell well and wanted a way to manage my content in bulk.

Since the Ghost API is REST, you can choose just about any language to interact with it. As an example of one such tool, check out PSGhost (github.com). This is a PowerShell module I built to work with my Ghost(Pro) (ghost.org) blog.

You'll find some quick set up instructions on the README page but let's run through a quick tutorial on how to get this working.

PSGhost - Ghost Blog PowerShell Module

PSGhost has an automated release set up via AppVeyor. Every time I commit a change to GitHub, a build kicks off and publishes a new version to the PowerShell Gallery. You can install PSGhost from the PowerShell Gallery by running Install-Module PSGhost in a Windows PowerShell console (no support for PowerShell Core).

Setting up a Ghost Custom Integration

You'll also need to set up a custom integration (ghost.org) in Ghost that will allow PSGhost to authenticate and manage your Ghost blog. Setting up a custom integration is a snap. Go to the Ghost portal, click on Integrations and then on Add custom integration.

Input a name for your custom integration. You can see below that I've just labeled mine REST API.

Creating a Ghost(Pro) Custom Integrtion

A custom integration creates the API keys you need to provide to PSGhost.

Ghost custom integration

Building the PSGhost Configuration

PSGhost stores all configuration items in a configuration.json file. This JSON file includes placeholders for:

  • ContentApiKey
  • AdminApiKey
  • ApiUrl
  • UserName
  • UserPassword

You can provide all of these values via the Save-GhostConfigurationItem command.

Once you've saved all of the items, you can then query all of the configuration items via the Get-GhostConfiguration command.

Testing the Ghost API Out

Next, you can be running the various commands found in PSGhost. To query your Ghost blog settings, run Get-GhostSettings. Need to know how many blog posts you have created? No problem! Use Get-GhostPost. This command queries all posts.

PS> (Get-GhostPost).Count

Maybe you only want to find a single post you've written. With Get-GhostPost, �you can query posts by Id, Slug and Title.

PS> Get-GhostPost -Slug 'my-blog-post'
PS> Get-GhostPost -Id 'XXXXXXXX'
PS> Get-GhostPost -Title 'My Blog Post.

As of 07/06/19, PSGhost only has support for returning settings and posts but support for many other actions could be added.

Summary

If you need to automate your Ghost blog actions with the Ghost API, check out PSGhost (github.com). Even better, help me make it better by sending me some pull requests to add more functionality to it!

Join the Jar Tippers on Patreon

It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!

Become a Patron!