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

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. I'm not sure it's possible.

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: 'fakeuser6@fake.tld', 
    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))