Mastodon github.com/rknightuk proven.lol/aaecd5

Get Mastodon Account ID from Username

posts 2023-01-27

Note: Every Mastodon has an RSS feed you can use to get statuses if you don't need the data in JSON format https://example.social/@foobar.rss.

If you want to get a user's statuses from Mastodon you can't just look these up with the username. You need, to quote the documentation, "the ID of the Account in the database". To get this, we can use the lookup endpoint that will return what we need:

# for an account on example.social
curl https://example.social/api/v1/accounts/lookup?acct=foobar

# also works for remote accounts
curl https://example.social/api/v1/accounts/lookup?acct=[email protected]

Assuming the username is valid, you will receive a response like this:

{
"id": "1234567891011121314",
"acct": "foobar",
"username": "foobar"
// ...
}

Then you can use that ID to make a request for a users statuses:

curl https://example.instance/api/v1/accounts/1234567891011121314/statuses

Popular Posts

Analytics powered by Fathom