Creating a post using API doesn't set markdown text correctly

Hello,
I am currently using the ghost api v0.1 and working on getting the /posts functionality working to create a post, however, I am having issues with the markdown being set correctly.

I have authenticated fine, have the access_token and the post is being created. The one thing that is not being set is the body of the post.

Using Postman, here is what I am sending as the url: http://<my-site>/ghost/api/v0.1/posts/?access_token=<my-token>

Here is the body in the post request:

{
        "posts":
        [
            {
                "title": "Auto API Post",
                "markdown": "This is the best day every \n\n  ###Here we have a list: \n *One item \n *Two items ",
                "meta_title": "A test meta title post from the api",
                "meta_description": "This is the meta description where all of the description of the post should go"
            }
        ]
    }

and here is the response I get with the html key empty:

    {
        "posts": [
            {
                "id": "5c2a55c1e822d5141a7dff80",
                "uuid": "96d792f4-0855-46ae-9fa7-868657515665",
                "title": "Auto API Post",
                "slug": "auto-api-post",
                "html": "<p></p>",
                "comment_id": "5c2a55c1e822d5141a7dff80",
                "feature_image": null,
                "featured": false,
                "page": false,
                "status": "draft",
                "locale": null,
                "visibility": "public",
                "meta_title": "A test meta title post from the api",
                "meta_description": "This is the meta description where all of the description of the post should go",
                "created_at": "2018-12-31T17:45:37.000Z",
                "created_by": "1",
                "updated_at": "2018-12-31T17:45:37.000Z",
                "updated_by": "1",
                "published_at": null,
                "published_by": null,
                "custom_excerpt": null,
                "codeinjection_head": null,
                "codeinjection_foot": null,
                "og_image": null,
                "og_title": null,
                "og_description": null,
                "twitter_image": null,
                "twitter_title": null,
                "twitter_description": null,
                "custom_template": null,
                "author": "1",
                "primary_author": null,
                "url": "/404/",
                "primary_tag": null
            }
        ]
    }

Additionally, here is a screenshot from GUI indicating that it is working, but there is no body text.
post_notext

As I understand it, the API is still under development but hoping there is something I can do to fix this. Any help would be much appreciated thank you.

Ghost stores posts using mobiledoc - it doesn’t store a post in markdown. If you want to use markdown, use the following template:

{"version":"0.3.1","atoms":[],"cards":[["markdown",{"markdown":"YOUR_MARKDOWN"}]],"markups":[],"sections":[[10,0],[1,"p",[]]]}

Replace YOUR_MARKDOWN with your markdown.

When you make the API request, make sure the mobiledoc field contains the content generated using the template.

Thank you @vikaspotluri123. Just a few clarifying questions:

  1. Do I use mobiledoc to generate the content you mentioned (using the template)?
  2. Is the key mobiledoc added as a property on the body posts object? If so what does it replace, if anything?
  3. I am curious what the final body of post request would look like given the new mobiledoc info
  4. Lastly, is there any other way/format to not have to use mobiledoc?

Thanks!!

  1. I’m not sure I follow what you’re asking; hopefully this answers your question: mobiledoc is a standardized way of storing posts, and it supports different “cards” (some defined by Ghost) such as html, mobiledoc and image. Since you’re trying to store markdown, I provided a template which contains one markdown card. The template is a JSON object, since that’s part of the mobiledoc spec, so be sure to escape as needed! I suggest using native json in whatever language you’re using, and the corresponding serializer.

  2. The mobiledoc key would replace the markdown key in your code

  3. Your best bet when interacting with the API is monitoring network requests as you use the admin interface. Installing ghost locally is well documented if you need an instance to tinker with. By doing so, you can see what’s sent and received by the admin interface.

  4. Nope, the purpose of mobiledoc is to make document storage extensible yet lightweight. The mobiledoc is “compiled” into html when you create a post.

1 Like

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