Mastodon filter backup howto (API + curl):
Royce Williams :ifin: @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:
Go to the "Development" area of your individual preferences on your instance.
Click on "New application".
For "Application name", give your "application" a simple descriptive name (I chose "filter-backup-ro", where "ro" means "read only"),
For "Application website", a URL to your own website or whatever is fine - anything will do.
For "Redirect URI", leave the default "urn:ietf:wg:oauth:2.0:oob", which is for "local tests".
Under "Scopes", uncheck all the (few) default checked items, then check 'read:filters'.
Hit 'Submit'.
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]" \
https://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: https://gist.github.com/roycewilliams/d6462a23cbee520848a3c7c33c5fe870