Skip to content

Instantly share code, notes, and snippets.

@chris-79
Last active March 22, 2023 18:45
Show Gist options
  • Save chris-79/8443322d93745678edfb4f117d3b1d0f to your computer and use it in GitHub Desktop.
Save chris-79/8443322d93745678edfb4f117d3b1d0f to your computer and use it in GitHub Desktop.

The key components you need are 1) a URL to an image and 2) a status message to go along with it (though this could probably be "" (null/a blank string) for a media-only post).

Screenshot → https://share.cleanshot.com/ktY34JSnbpGMwyTJQMjs

Assuming you follow along in my screenshot…

  1. Set a webhook as the beginning of the flow

    1. Copy that generated URL ("A" in the screenshot)
    2. Send an initial request to that webhhok so it knows what to expect* (!important, don't skip)
  2. (Optional) Add a "Match pattern" Text parser step and ensure the following ("B" in the screenshot)…

    1. Regex pattern: ([^\/]+\.[\w]{3,4})(\?.+)?$ (this looks for a 3-4 letter file extension in the URL)
    2. Global match, Case sensitive, Multiline, and Singleline should be "No"
    3. Continue should be "No" so that the flow stops if there's no match
    4. Text should be the captured URL from the Webhook
  3. Add a "Get a file" HTTP step ("C" in the screenshot)

    1. Text should be the captured URL from the Webhook
  4. Add a "Make a request" HTTP step

    1. Set URL to https://[something.social]/api/v1/media
      (replace [something.social] with your Mastodon server domain name)
    2. Set Method to "POST"
    3. Set 2 Headers
      1. Set Name to "Authorization" and Value to "Bearer [eyJ0eXAiOiJKV1QiLCJhbGciOiJSU…]"
        (replace '[eyJ0eXAiOiJKV1QiLCJhbGciOiJSU…]' with your access token (how to get one (or just Google it))
      2. Set Name to "Content-Type" and Value to "multipart/form-data"
    4. Set Body type to "Multipart/form-data"
    5. Set 1 Field
      1. Set Field type to "File", set Key to "file", set File to "HTTP - Get a file" from Step 3
    6. Set Parse response to "Yes" (!important for step 5.v.b)
  5. Add another "Make a request" HTTP step

    1. Set URL to https://[something.social]/api/v1/statuses
    2. Set Method to "POST"
    3. Set 2 Headers
      1. Set Name to "Authorization" and Value to "Bearer [eyJ0eXAiOiJKV1QiLCJhbGciOiJSU…]" (same as Step 4)
      2. Set Name to "Content-Type" and Value to "multipart/form-data"
    4. Set Body type to "Multipart/form-data"
    5. Set 2 Fields
      1. Set Field type to "Text", set Key to "status", set Value to "title" from the initial Webhook
      2. Set Field type to "Text", set Key to "media_ids[]", set Value to the "data.id" from Step 4 above

* I send the Webhook data from IFTTT with a POST to my Make.com webhook URL. The Content Type is "application/json" and the Body is { "title": "{{Title}}","url": "{{ImageURL}}" }

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment