Draft content is not available via the Content API otherwise all your drafts would be available publicly. You need to use the Admin API if you want to fetch drafts.
Hi @Kevin Thank you for answering. So problem with the admin API is Authentication.
So i want to access and preview the draft URL for my own blogs. I am consuming ghost content API for that but for the draft preview i have to consume admin url and which giives me 403. How can someone authenticate admin api via fetch. I am using Next js 13.4 app router.
Infact @Kevin I am also facing the same issue in my case I want to access the draft on the production just using the API keys where I dont need additional authentication, in my knowledge ghost provides 3 types and API key is one of them, but I cant access it directly using the admin api
{
errors: [
{
message: 'Authorization failed',
context: 'Unable to determine the authenticated user or integration. Check that cookies are being passed through if using session authentication.',
type: 'NoPermissionError',
details: null,
property: null,
help: null,
code: null,
id: '90bee4b0-bf5c-11ee-9bfb-7f6f535c7e92',
ghostErrorCode: null
}
]
}
which should not be the case when I use directly keys provided on the ghost app. any workaround for the same issue?
Hey @Cathy_Sarisky I tried the same what it is written in the Documentation still It gives the same error Which I have posted above any workaround do lmk.
Thanks in advance!!
This does not work, since you cannot pass an admin API key through a key query parameter.
There are three ways to authenticate with the admin API. Cathy linked to the documentation above.
Opening the URL in a browser will work, however, when you’re logged in to your Ghost admin, since your browser then has an authentication cookie. So, that’s potentially why it looks like it works in your browser. You are implicitly using one of the three authentication methods. That has nothing to do with the key parameter though.
const api = new GhostAdminAPI({
url: host,
version: 'v5.0',
key: admin_key,
});
const getPost = async (id) => {
return await api.posts.read({
id
});
}
@Keval_Rathod this should also answer your question from yesterday. If you want to use fetch directly instead of the sdk, you just have to pass your admin token to the Authorization header.