Get post HTML content using Ghost Content API v3

I was trying to retrieve the HTML for an unpublished post - this should be possible right?

This is my basic query.<post_id>/?key=<key>

I tried this on a post that was published, and it works. But I cannot get the HTML for the unpublished post. Is there some other easy way to do this?

Edit: The <key> is my content API key from an integration I made, and I found the <post_id> in Ghost admin in the URL of my post.

The request returns a 404 error:

    "errors": [
            "message": "Post not found.",
            "errorType": "NotFoundError"

@MLFromScratch the Content API is a public API and therefore unpublished posts are not available, otherwise anyone viewing a Content API powered site could read all of your drafts.

What is the use-case for fetching an unpublished post? If this is server-side you can use the Admin API to fetch all posts both published and unpublished.

I’m making a post on IBM as a contractor - and they basically just need the HTML to publish it. I’m curious if there is a better way to deliver the article to them, than going through the admin API though.

This makes a lot of sense. I was just not aware of the admin API, so I will make a small script to solve this. Thank you for your help Kevin! :slight_smile:

Hmm, if you wanted to avoid a script there are a couple of options.

  1. Open the post preview and copy/paste the relevant html section
  2. Have web inspector open when opening a post in the editor, find the network request which loads the post, right-click and choose “Copy as fetch” then switch to the Console tab and paste. Before hitting Enter you’ll want to add the ?formats=html query param and add .then(response => response.json()).then(console.log) to the end of the statement. A little long-winded but saves writing a script or getting admin api credentials for one-off things :slight_smile:

Hi again Kevin, I just got the admin API to work through a Python script.

Do you by chance know if there is an easy way to save the images in the article?