url: skill-speed.ghost.io
API version: 5.0
Hosted: on Ghost platform
I want my Next.js website to have a button which creates members.
The problem is when I make the POST, I get an error:
{
message: 'Request not understood error, cannot save member.',
context: "No root key ('members') provided.",
type: 'BadRequestError',
details: null,
property: null,
help: null,
code: null,
id: '2db3b970-d68d-11ee-8b3b-41aef59088a6',
ghostErrorCode: null
}
I don’t understand what the root key is. As you will see, I make sure the members
property is in the request payload.
Here’s my snippet of the button submit-handler:
'use server'
import jwt from 'jsonwebtoken'
const APIKEY = "API KEY"
const clickHandler = async () => {
const [id, secret] =
APIKEY.split(
':',
)
// Create the token (including decoding secret)
const token = jwt.sign({}, Buffer.from(secret, 'hex'), {
keyid: id,
algorithm: 'HS256',
expiresIn: '5m',
audience: `/admin/`,
})
const url = 'https://skill-speed.ghost.io/ghost/api/admin/members'
const headers = { Authorization: `Ghost ${token}` }
const payload = {
members: [
{
email: 'jayrey.go@gmail.com',
},
],
}
const result = await fetch(url, {
body: JSON.stringify(payload),
headers,
method: 'POST',
})
const body = await result.json()
console.log(`clickHandler -- res`, body)
}
export default clickHandler