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 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 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.
A custom integration creates the API keys you need to provide to PSGhost.
Building the PSGhost Configuration
PSGhost stores all configuration items in a configuration.json file. This JSON file includes placeholders for:
You can provide all of these values via the
Once you've saved all of the items, you can then query all of the configuration items via the
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.
Maybe you only want to find a single post you've written. With
Get-GhostPost, you can query posts by
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.
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!