Michele Ong

Programmatically Post to Mastodon with Make

There don't appear to be any social-media schedulers that support Mastodon yet, although there are a couple cross-posters to/from Twitter. If, however, you need to programmatically post to Mastodon through some service like Make (affiliate link) or Zapier, Mastodon conveniently has an API that you can use.

Set up an Access Token

  1. Create an application at https://[YOUR MASTODON SERVER]/settings/applications by clicking on New Application.

  2. Set the Application Name, don't change the Redirect URI, and under Scopes check write:statuses and if you want to attach images write:media. You can uncheck the rest.

Once that is created, the application should now give you a Client key, Client secret, and Your access token. You only need the last.

Post a Status

If you're setting up some sort of automation service, the module you're looking for will be HTTP in Make (affiliate link), the POST webhook in Zapier, or webhook in IFTTT.

Skip the next section if you don't need to attach media to your status, but even if I'm sharing a link, I prefer to attach an image over using the Mastodon link preview.

Step 1. Upload media

Make a POST call to:

https://[YOUR MASTODON SERVER]/api/v1/media?access_token=[YOUR ACCESS TOKEN]

Set the type to multipart/form-data and attach your image (not an image URL) to the file field.

<p>My Mastodon publishing workflow on Make</p>

My Mastodon publishing workflow on Make

If like me you only have access to an image URL in your workflow, you'll also need to do some sort of file fetch. Make (affiliate link) conveniently has a 'Get a file' module for just such an occasion.

This call will return an object containing a media id that you will need for the next step.

More info: Documentation for the /media endpoint on Mastodon.

Step 2. Post the status

Make a POST call to:

https://[YOUR MASTODON SERVER]/api/v1/statuses?access_token=[YOUR ACCESS TOKEN]

Set the type to application/x-www-form-urlencoded and pass the status field containing your status message. If you are attaching an image as well, pass the media_ids[] field with the media id you retrieved in the previous step.

More info: Documentation for the /statuses endpoint on Mastodon.

Affiliate Promotion

I use Make for my personal, creator, and business automation needs. I am also an affiliate, so if you use my link to sign up for a Make account, you will also receive 1 month of Make's Pro plan free with 10,000 ops.

Published January 01, 2023