Opaque "Validation error" when attempting to save a member

Stack trace:

Validation error, cannot save member.
ValidationError: Validation error, cannot save member.
    at /home/thorn/programming/desktop/news-website/node_modules/@tryghost/admin-api/lib/admin-api.js:463:33
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async POST (/home/thorn/programming/desktop/news-website/src/routes/api/members/add/+server.ts:32:19)
    at async render_endpoint (file:///home/thorn/programming/desktop/news-website/node_modules/@sveltejs/kit/src/runtime/server/endpoint.js:42:20)
    at async resolve (file:///home/thorn/programming/desktop/news-website/node_modules/@sveltejs/kit/src/runtime/server/index.js:354:17)
    at async respond (file:///home/thorn/programming/desktop/news-website/node_modules/@sveltejs/kit/src/runtime/server/index.js:229:20)
    at async file:///home/thorn/programming/desktop/news-website/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:444:22

Code I am attempting to execute

    const api = new GhostAdminAPI({
        url: 'https://thorne-wolf.ghost.io',
        key: ghostAdminApiKey,
        version: "v5.0"
    });
    let finalPayload = {
        "members": [
            {
                "email": "jamie@ghost.org",
            }
        ]
    }
    let response = await api.members.add(finalPayload)

I have a separate working example with the content api (const api = new GhostContentAPI({ url: 'https://thorne-wolf.ghost.i - Pastebin.com) that works.

Regarding the payload, I have tried a few alternatives but none proved fruitful. I can provide them if requested but I suspect they would not be useful to someone who already knows the correct format. LMK what I might be doing wrong.

Thanks!

It should be noted that I have tried v3.0 v4.0 v5.0, but I can’t really find in the docs where the actual current version is listed.

Since you’re using the JavaScript SDK, you can just use {email: "name@email.com"} as your payload. Additionally, the validation error can occur if you’ve already added the member to your site, so make sure you’re testing with a new email address.

const res = await api.members.add({ email: "name@email.com" })

Thanks @RyanF. It would be great if the error message to explain what failed validation. In this case, there’s only one field but other other cases there could be several options to sort through.

1 Like