Plaintext value is empty using the API

When I make an API request and limit the return fields with fields, the plaintext value is empty.

http://localhost:2368/ghost/api/v3/content/posts/?key=85467c3d1c68865f197862c2ea&limit=all&fields=id,title,plaintext&formats=plaintext

It does return the value if I removed the fields parameters.

http://localhost:2368/ghost/api/v2/content/posts/?key=85467c3d1c68865f197862c2ea&limit=all&formats=plaintext

Ghost Version 3.1.0

Is there anything I’m missing?

Thanks

Any thoughts about this?

Just did a quick check for this and it all worked as expected for v3 Content API (note you have v2 on both of your screenshots)
Was verifying the output with the following test (added it to this suite):

    it('posts with plaintext field', function () {
        return request
            .get(localUtils.API.getApiQuery(`posts/?key=${validKey}&limit=all&fields=id,title,plaintext&formats=plaintext`))
            .set('Origin', testUtils.API.getURL())
            .expect('Content-Type', /json/)
            .expect('Cache-Control', testUtils.cacheRules.private)
            .expect(200)
            .then((res) => {
                localUtils.API.checkResponse(res.body.posts[0], 'post', null, null, ['id', 'title', 'plaintext']);
            });
    });

I tried this on the latest master.

Anything specific about the html content in posts missing the plaintext? Can’t really think of why this would not work :slight_smile:

Yes, tried it with the v3 and it is not working too.

Also, if I removed formats=plaintext and only provides the fields, plaintext and html are also empty.

http://localhost:2368/ghost/api/v3/content/posts/?key=85467c3d1c68865f197862c2ea&limit=all&fields=id,title

If I want to return only the id and html for example, the html is empty.

http://localhost:2368/ghost/api/v3/content/posts/?key=85467c3d1c68865f197862c2ea&limit=all&fields=id,html

It’s pretty hard to pinpoint the issue here :thinking: Could you try doing similar request on a new instance and if it does’t happen they try to import some of the data from your current instance?
My current thinking is:

  1. It might be something with the data
  2. There were some modifications in the code itself (did you do anything custom?
  3. Maybe something database specific? Which version are you running? Is it MySQL or SQLite?

Would be helpful if you could provide more information about the environment the instance is running in. Also try running the request using plain curl, so we can eliminate browser extension doing something strange.

I’m trying on a local Mac development setup.

I also created a Ghost Pro instance to try on it (https://ahmadajmi.ghost.io/). So, with the default content, there is no issue and everything is working fine, but when I deleted the instance content from Delete all content and then imported my content file, the issue happens.

https://ahmadajmi.ghost.io/ghost/api/v3/content/posts/?key=d5a590c82cf4f68fd771094add&limit=all&fields=id,title,plaintext&formats=plaintext

With the imported content, I tried this time to delete all the posts one by one to see that it might be a content issue, but still the issue still happens. After deleting all posts, I created a new post to check but still got plaintext empty.

To make things working again, I deleted my content from Delete all content and then imported the original Ghost Pro one and it worked again.

The content file:

https://gist.githubusercontent.com/ahmadajmi/083e9cec037e7c8e3c669cb883e21c59/raw/4bdedd02a424bcb85d9351cf76a8ae080ba3e889/ghost-content.json

I’m thinking maybe some data fields are inserted to the database from my own file which could make the issue other than about the content of the posts.

@ahmadajmi the export file you provided seems to be broken :confused: looks like the same content has been duplicated twice :wink:

On the note. I have tested this scenario with your data and then with some of my own. Was able to reproduce this issue when requesting posts with fields=id,title,plaintext through Content API while having “members” enabled. Will try and investigate it quickly and will post here if I find a fix for it.

Have started a PR wit a possible fix here - 🐛 Fixed empty html/plaintext fields for narrow fields parameter by naz · Pull Request #11505 · TryGhost/Ghost · GitHub.

As a quick workaround for this issue add visibility to your fields query parameter like so fields=id,title,plaintext,visibility

1 Like

You are right, it looks like plaintext is only empty when we have “members” enabled.

Adding visibility fixed it. I tried it with the following example and plaintext is now visible. Awesome!

http://penang.aspirethemes.com/ghost/api/v3/content/posts/?key=54b8d91a38fddd678292d417e7&limit=all&fields=id,title,url,created_at,feature_image,visibility&formats=plaintext

Thanks a lot!

1 Like