Getting started with the Mastodon APIs – notifications

The docs for the Mastodon APIs are pretty good, but there’s a surprising lack of working examples online (compared to using the Twitter APIs) which means starting out I’ve been stumped several times already trying to work out how to what seem to be simple things.

Publishing a new status (a ‘Toot’, equivalent in Twitter terms to a ‘Tweet’), is easy enough with POST /statuses . Getting a list of who has mentioned you in a status was not that obvious though.

I took a look at getting my timeline with various options, using GET /timelines, before realizing what I was probably looking for was GET /notifications which can be filtered by various types, including mentions, using

GET /notifications?types[]=mention

Note the types array parameter with [] following the name. I haven’t seen this convention used before, but this is described in the docs here.

Most of the APIs returning statuses look like this:

{
      id: 'unique-id',
      type: 'mention',
      created_at: '2022-11-20T04:46:33.902Z',
      account: {
        // details about the account that posted this status
      },
      status: {
        id: 'unique-id-for-this-status',
        created_at: '2022-11-20T04:46:22.000Z',
        in_reply_to_id: null,
        in_reply_to_account_id: null,
        content: {
          //content of the status here, as HTML
        }

Note that the type=mention here, as this is what we filtered for with the types=[] parameter.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.