Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Mastodon Automated Postings using the API

May 16, 2023 — Gregg Szumowski

You can post to Mastodon using their API using cURL.

Create or Find Your Access Token

Once you have a Mastodon account, you need your account's access token. The steps you need to get that:

  1. Sign into your Mastodon account
  2. Click on In the "Preferences" link.
  3. On the bottom left corner of that page, click the "Development" link.
  4. On the "Your Applications" page, click the blue NEW APPLICATION button.
  5. Give your application a name, and decide what kind of access you want to have when you connect to your account via the Mastodon API (iread, write, and follow are the defaults). You can always change this later.
  6. At the bottom of the page, click the blue SUBMIT button.
  7. You will be directed back to the Your applications page, but now you should see your application name. Click that.
  8. In your application's page, there are three tokens. For this tutorial, you need the Your access token one. Note: if your access token is ever compromised, you can click regenerate, and your old access token will stop working, and you'll be shown a new one.

Post a Status Update using cURL


$ curl https://mastodon.sdf.org/api/v1/statuses -H 'Authorization: Bearer put-your-api-token-here' -F 'status=Hello, World'

Tags: curl, mastodon, api, motd