The Admin API SDK documentation I can't find elsewhere...

Some missing documentation bits for the Ghost API, including the members endpoint.

The Admin API SDK documentation I can't find elsewhere...
Photo by Hans-Peter Gauster / Unsplash

I switched from writing my own fetch calls to using Ghost's Javascript SDK for accessing the Admin API. Mostly, it's awesome. It's saved me from having to suss out how to create a JWT that Ghost will accept, and the refactoring to use it made my code more readable and fewer lines. So, great.

The problem is, the documentation didn't get me quite as far as I needed to go. So, without further ado, here are some commands I've sorted out, that weren't clear enough or well documented enough in the official docs.

At this writing, the official Admin API documentation is here: https://ghost.org/docs/admin-api/, and the documentation for the SDK is here: https://ghost.org/docs/admin-api/javascript/

And now, my notes on how to do things I didn't see there:

How to edit a member:

api.members.edit({id:'63bb7c8e756b27003d3c1c33',name: 'Kate2'}); 

id is required. Anything else you pass in is a change to the member. I haven't worked out how to pass in changes to subscriptions or tiers or pricing with the members API. I'm not sure it's possible.

Here's how to change Ghost subscription prices using the Stripe API.

Edit tags on a post:

api.post.edit({id: 'yourpostid', tags: [array,of,tag,slugs]})

Super important: You have to pass all the tags on the post. The full set of tags will be whatever you pass in, so both addition and deletion require a little pre-processing.

Adding a new user with a complimentary subscription:

// set tierID and provide GhostAPI config earlier in the process...

api.members.add(
    {email: '[email protected]', 
    name: 'six API source',
    "subscriptions": [
        {
            "id": "",
            "tier": {
                "slug": "default-product",
                "active": true,
                "expiry_at": "2023-01-20T00:00:00.000Z"
            },
            "plan": {
                "id": "",
                "nickname": "Complimentary",
                "interval": "year",
                "currency": "USD",
                "amount": 0
            },
            "status": "active",
            "price": {
                "id": "",
                "price_id": "",
                "nickname": "Complimentary",
                "amount": 0,
                "interval": "year",
                "type": "recurring",
                "currency": "USD",
                "tier": {
                    "id": "",
                    "tier_id": tierID
                }
            },
            "offer": null
        },
        
    ],
    "tiers": [
        {
          "id": tierID,
          "expiry_at": "2023-01-20T00:00:00.000Z"
        }
      ],


}).then(result => console.log(result))

Linking a member with their existing Stripe subscription

Uploading a CSV via cloud function. I'm pretty sure this is the wrong way to do it, but it's the only way I've gotten it working.