Mastodon filter backup howto (API + curl):

@tychotithonus@infosec.exchange

Content warning: Mastodon filter backup howto (API + curl):

UPDATE: Mastodon 4.6.0 has native support for exporting and importing filters! 🥳

If you have a non-trivial amount of effort invested in your Mastodon filters, and want to regularly grab a manual full JSON backup:

First, get your access token:

  1. Go to the "Development" area of your individual preferences on your instance.

  2. Click on "New application".

  3. For "Application name", give your "application" a simple descriptive name (I chose "filter-backup-ro", where "ro" means "read only"),

  4. For "Application website", a URL to your own website or whatever is fine - anything will do.

  5. For "Redirect URI", leave the default "urn:ietf:wg:oauth:2.0:oob", which is for "local tests".

  6. Under "Scopes", uncheck all the (few) default checked items, then check 'read:filters'.

  7. Hit 'Submit'.

  8. Go back into your newly created application and note/copy its 'Access token'.

Then, on the command line:

curl -X GET \
-H "Authorization: Bearer [your-token-here]" \
inst.example/api/v2/filters \
> filters-backup.json

Note that some instances may have an API endpoint hostname that's different from the main domain (for example, crank.infosec.exchange).

You can pipe the output to python -m json.tool if you want the JSON to be human-readable.

NOTE: If you change your app's permissions, the access token will be automatically regenerated!

And since the permissions are so nicely granular ... dropping your access token into a script, and adding a little extra to automatically name the file uniquely based on datestamp, makes for a low-risk, quick, convenient backup: gist.github.com/roycewilliams/