May 19, 2023

Use subscriber emails as a PK!

(NERD ALERT: If you don't use the API, this post is not for you.)

If you do use the API, you might have run into a small frustration which is this:

You're trying to sync some existing corpus of subscribers (say, your userbase) with Buttondown's list. So every time someone registers an account, they become a Buttondown susbcriber.

This is easy: you just make a POST request to /v1/subscribers with their email address and you're done.

But what if you want to then change something about them? Let's say you want to add a tag to them (to reflect the fact that they're a churn risk) or you want to delete them (because they've deleted their account.)

You can't do that, because you don't know their subscriber ID. You'd have to either store that subscriber ID in your database (not the end of the world, but kind of annoying) or search for them with /v1/subscribers? and then grab their ID (again, not the end of the world, but kind of annoying.)

Now there is a better way!

Just use their email address as a PK. You can call, e.g. DELETE /v1/subscribers/ and it will Just Work.

This doesn't let you do anything you couldn't already do, but it should make integration, like, 10% easier. And that adds up.