How to look up a Mastodon account’s ID using Shortcuts

Working with Mastodon's API means handling profiles from across the fediverse — this shortcut lets you make a web request to the "Lookup account" endpoint to get the universal ID for any user.

When working with the fediverse and Mastodon links, one is regularly dealing with accounts from a variety of instances, each with its own set of URLs for every account.

That means, when using the Mastodon API, it’s especially important to identify each user by their unique ID rather than dealing with different handles and instance URLs, which would otherwise get very messy very quickly.

Screenshot of Mastodon "Lookup acccount" API endpoint documentation.

To solve this problem, Mastodon has implemented a Lookup account functionality, a public endpoint that allows anyone with a Mastodon link to send a web request and return the ID for that user.

To take advantage of this in Shortcuts, I built Look up Mastodon account ID, one of my shortcuts that accepts any fediverse link as input (or gets one that’s been copied to your clipboard) and returns the account ID value – here’s how it works:

To start, my shortcut builds off the method I’ve developed for scraping Mastodon instance and handle data from fediverse links — you’ll be able to take a link from input and end up with variables for the Instance and Handle.

Then, create your request to the Lookup account endpoint by passing a URL for https://{Instance}/api/v1/accounts/lookup?acct={Handle}` into theGet Contents of URL` action – that will send a web request to Mastodon’s API and retrieve the data for you.

From that, the API will return a dictionary of data that includes values like id, username, acct, and display_name.

By using Get Dictionary Value to retrieve the id, we can output the value and end up with the unique identifier for that user that can be used elsewhere in the Mastodon API.

I’ve also included the Stop and Output action to show an alert when the shortcut is run standalone so you can see the name and ID for the account (when it’s not be used elsewhere).


Originally, this function was built particularly for my shortcut to save Mastodon accounts to Lists — checking whether or not the account was already on a List required the Account ID, not just the handle.

However, this shortcut can be used in any Mastodon API shortcut when working with various instances — if you need to look up an account, use this shortcut as a function using Run Shortcut, set the link as the Input, and you can retrieve the account ID immediately.

Get the free Look up Mastodon account ID shortcut in the otherwise members-only Mastodon Lists folder of my Shortcuts Library.

Featured Shortcuts

shortcut-look-up-mastodon-account-id-icon.webp
Look up Mastodon account ID
Isolates a Mastodon handle from a link and looks up the account identifier.

Posts You Might Like

How to use Mastodon’s API to open your Lists with Shortcuts
Building up your Lists in Mastodon is important – so is accessing them quickly when you need them. Using Apple's Shortcuts app, I built a tool that makes a web request to Mastodon's API and lets you return all your Lists to open from.
File a radar
Guides you through the process of filing Feedback to Apple (previously called Radar). This explains the process in a pop-up, has you type up the problem through a series of prompts before even starting a new ticket, then guides you again on how to easily fill out the form, before finally opening into Feedback.
How to save Mastodon accounts to Lists using Shortcuts
When working with Mastodon accounts, there's only one place to add them to a List — the profile. With Shortcuts, I've built a tool that lets you add someone to a list from your timeline, a status post, or any link.