Publishing with a single POST request to `/posts`


#1

Hello,

I am posting to local Ghost server by POSTing to /posts. I am expecting the post to be visible on the homepage, but I am unable to see the post on the homepage without a workaround.

How would I go about publishing a post via a single POST request to /posts?

Below are the expected, actual, and workaround scenarios.

Expected:

GIVEN a valid access token
—AND a user of role Author
WHEN POSTing to /post
—AND request body is

{
        posts: [
            {
                title: "My API post " + Date.now(),
                "mobiledoc": "{\"version\":\"0.3.1\",\"markups\":[],\"atoms\":[],\"cards\":[[\"card-markdown\",{\"cardName\":\"card-markdown\",\"markdown\":\"Some Text\"}]],\"sections\":[[10,0]]}",
                status: "published",
                author_id: "5adf9b67-e1d2-481f-a348-"
            }
        ]
    }

—AND Bearer token is set in the headers
THEN post is saved to db
—AND post status is published
—AND post is visible on homepage

Actual:

GIVEN a valid access token
—AND a user of role Author
WHEN POSTing to /posts
—AND request body is

{
        posts: [
            {
                title: "My API post " + Date.now(),
                "mobiledoc": "{\"version\":\"0.3.1\",\"markups\":[],\"atoms\":[],\"cards\":[[\"card-markdown\",{\"cardName\":\"card-markdown\",\"markdown\":\"Some Text\"}]],\"sections\":[[10,0]]}",
                status: "published",
                author_id: "5adf9b67-e1d2-481f-a348-"
            }
        ]
    }

—AND Bearer token is set in the headers
THEN post is saved to db
—AND post status is published
—AND post is not visible on homepage

I am able to workaround this problem by making a simple PUT request to /posts/:id right after the post has been created. I’d prefer not make this second request if possible.

Workaround

GIVEN a valid access token
—AND a user of role Author
WHEN POSTing to /posts
—AND request body is

{
        posts: [
            {
                title: "My API post " + Date.now(),
                "mobiledoc": "{\"version\":\"0.3.1\",\"markups\":[],\"atoms\":[],\"cards\":[[\"card-markdown\",{\"cardName\":\"card-markdown\",\"markdown\":\"Some Text\"}]],\"sections\":[[10,0]]}",
                status: "published",
                author_id: "5adf9b67-e1d2-481f-a348-"
            }
        ]
    }

—AND Bearer token is set in the headers
—AND PUTing to /posts/:id with :id created from previous request
—AND request body is

{
    posts: [
        {
            id: postId,
        }
    ]
}

THEN post is saved to db
—AND post status is published
—AND post is visible on homepage


#2

Hey!

Sorry for late response :innocent:

I can confirm this behaviour. Will be fixed and released later today.

A different workaround:

  • send "page":false when creating the post resource

#3

Should be fixed in 1.24.6 :innocent:Let us know!


#4

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.