Skip to content

Ghostlyzer/GhostLyzer.Module.GhostApi

Repository files navigation


GhostLyzer
Ghost CMS API .NET SDK

An easy to use C# Wrapper for the Ghost CMS API built on top of .NET.

CodeFactor

Key FeaturesHow To UseCreditsLicense

Key Features

At the moment the wrapper supports the following features in the Ghost API. I am working on a new feature to include member functionality.

How To Use

Interested in getting started working with data from your Ghost blog? Awesome! Install the NuGet in your project and use it as shown below.

Accessing the Content API

If you need to access the Content API, all you need is the URL of your site and a Content API Key, available on the "Integrations" page. Once you have those pieces of information, you can access any "public" content on your blog.

var ghost = new GhostLyzer.Module.GhostApi.GhostContentAPI("https://blog.christian-schou.dk", "<content-api-key-from-ghost-integration>");
var settings = ghost.GetSettings();

Console.WriteLine($"Welcome to {settings.Title}: {settings.Description}\r\n");
Console.WriteLine($"Navigation: {string.Join(", ", settings.Navigation.Select(x => x.Label))}");

Output:

Welcome to Tech with Christian: A Pragmatic Software & DevOps Engineer sharing his knowledge with the internet.

Navigation: ReadMe, C#, .NET, Docker, Account

Accessing the Admin API

If you need to access the Admin API, all you need is the URL of your site and an Admin API Key, also available on the "Integrations" page. Once you have those pieces of information, you can access any "private" content.

var ghost = new GhostLyzer.Module.GhostApi.GhostAdminAPI("https://blog.christian-schou.dk", 
    "5cf706fd7d4b35066550627a:9e5ed2b90e40f68573b0cdaf4aef666b047fc9837ad285b2e219eed5501bae53");
var site = ghost.GetSite();

Console.WriteLine($"Welcome to <a href='{site.Url}'>{site.Title}</a>\r\n");
Console.WriteLine($"Running Ghost v{site.Version}");

Output:

Welcome to <a href='https://blog.christian-schou.dk/'>Tech with Christian</a>

Running Ghost v5.79

You can optionally pass in a version number for the API (i.e. 4.0), or omit it to default to the latest (currently 5.0). You are on your own here, if you break the integration, I cannot help you as I simply don't have the time right now. You are more than welcome to fork the project, implement the changes, and make a pull request.

Running the Tests

The tests are set to run against an actual instance of a live Ghost blog, using a valid API key. There are details in the TestBase.cs class that you'll need to fill in, such as a valid API key, valid post ID, valid post slug, etc... I would recommend you set up a new environment variable with your key as that would avoid you to submit any secrets to your repo, making yourself vulnerable.

Credits

This software uses the following open-source packages:

Credit To The Original Author

This solution is a rewrite of the original GhostSharp project by grantwinney. GhostSharp supports up to .NET 6. This project adds support for .NET 8, async requests, and an updated way of making the requests along with less complexity in the logic behind the requests. If you compare the two of them you would easily find similarities, and that's because it's heavily inspired by what Grant has done in the original project.

I would like to thank Grant for making a great project like GhostSharp! ✌️

License

MIT