Trouble using the Ghost admin API

I’ve been trying to use the Ghost Admin API (self-hosted) by two means:

  1. HTTP to the REST api directly
  2. Using the SDK (@tryghost/admin-api)

I’ve created a custom integration, and I’m trying to use the admin api key. I get 403 responses in both cases. Is this supposed to work, or am I missing a key negotiation step (i.e. OAuth or similar)?

For token auth you need to generate JWTs. The @tryghost/admin-api should do that for you though. If you provide the full error response that would be useful as the error message will tell you what’s wrong.

1 Like

{
“message”: “Request failed with status code 403”,
“name”: “Error”,
“stack”: “Error: Request failed with status code 403\n at createError (/Users/adriaan/clause-blog/process-content/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/Users/adriaan/clause-blog/process-content/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/Users/adriaan/clause-blog/process-content/node_modules/axios/lib/adapters/http.js:236:11)\n at IncomingMessage.emit (events.js:203:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)”
}

@adriaan_pelzer that’s the generic error from the request library, are you able to get the response data that’s coming from Ghost’s API?

@Kevin That is the response from the admin-api module; it’s the entire error being thrown, nothing omitted.

I have reverted to using sessions, as the front end does.
It would be good, however, to get this working at some point.

Could you point me to ghost docs or an example detailing getting a JWT token, as that could be another viable route.

@Kevin Apologies - just noticed you’ve already sent the JWT docs in the first response. That should suffice, thanks!