Get post using id with Admin API

When I use the Admin API to get a post I’m getting a “Post not found” response:

{"errors"=>[{"message"=>"Resource not found error, cannot read post.", "context"=>"Post not found.", "type"=>"NotFoundError", "details"=>nil, "property"=>nil, "help"=>nil, "code"=>nil, "id"=>"[snip]", "ghostErrorCode"=>nil}]}

The URL I’m hitting is as per the documentation:

GET /admin/posts/{id}/

Apart from the URL, the code I’m using is identical to the same as I use to get all posts, which works perfectly. Also getting by slug:

GET /admin/posts/slug/{slug}/

The post ids I’m using have been checked and double-checked. I’ve even used the ‘all posts’ response to find an id to insert into the ‘single post’ request, but I still get “Post not found”.

I can’t use the Content API because some of the posts I’m querying aren’t published.

Is it possible to GET a single post using the Admin API? Is there anything extra that you have to do (e.g. body content) to access this data?

Thanks.

P

Sounds like it should be working but it’s hard to know what to suggest without seeing a code snippet or something to review?

Thanks, Hannah, appreciate your help.

I’m happy to share the code, but if I simply remove the /id/{id} part of the call, it works and I get all posts. This suggests the authentication and the code is good?

I received a somewhat cryptic email that included this:

Integration expected Ghost version: v4.0
Current Ghost version: v5.24
Failed request URL: /ghost/api/admin/posts/id/63890c0a403630003df7c802/

(I’ve replaced the id in the email with a current id)

Does this help?

Note - I’m currently in my trial period on Ghost(Pro) and the post is unpublished (in case that makes a difference).

Regards,
Paul

Ah ok, I see the problem - there is no /posts/id/{id}/ endpoint - it’s just /posts/{id}/

Is there a reason you’re not using the provided SDK? The SDK would solve all issues with URL formation for you!

Thanks again, Hannah. You were right, but I’d already spotted and fixed that.

The actual problem was that I was using the id variable to build the URL, and this was already being used in the code generating a token.

I changed this to post_id and it’s now working fine.

Thanks again for your help.