Why is the html not being published?

I have a file called ghost.txt with the content below taken from the Ghost docs

{
    "posts": [{
        "title": "My test post",
        "html": "<p>My post content. Work in progress...</p>",
        "status": "published"
    }]
}

and when I publish it using this bash script

# Create a session, and store the cookie in ghost-cookie.txt

curl -c ghost-cookie.txt -d username="user@domain.com" -d password="1234567890" \
   -H "Origin: https://blog.domain.com" \
   https://blog.domain.com/ghost/api/v2/admin/session/

# Read the JSON and cookie file and publish to Ghost

content=$(<ghost.txt)

curl -b ghost-cookie.txt \
   -d "$content" \
   -H "Content-Type: application/json" \
   -H "Origin: https://blog.domain.com" \
   https://blog.domain.com/ghost/api/v2/admin/posts/?formats=html

the post gets published with the title as it should but the main html body

"html": "<p>My post content. Work in progress...</p>"

is completely missing from the post that’s created.

Why would the main html be missing from the post? As far as I can tell I’ve structured everything correctly just like the examples given in the official Ghost documentation.

@www The key point you are missing from the docs is this part:

To use HTML as the source for your content instead of mobiledoc, use the source parameter

This means that your POST request should be going to https://blog.domain.com/ghost/api/v2/admin/posts/?source=html&formats=html

We should definitely make that clearer in the docs!

2 Likes

That fixed it, thanks Kevin!

@Kevin Stumbled upon this just a few days ago. Took me some time (and careful reading :)) to figure this out.

I wanted to improve the docs, but making changes to the docs is not mentioned in the Contribution Guidelines. Is this intended?

1 Like

@cvoigt the API docs repo lives here, feel free to open a PR! https://github.com/TryGhost/docs-api

The docs contributing guidelines aren’t featured too prominently at the moment because the docs site has been going through a fair bit of refactoring and re-organisation in the background.

1 Like