Help

Post to Mastodon

2862 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Jason_F
6 - Interface Innovator
6 - Interface Innovator

I am adding Mastodon as an end point for my social needs.

I would like to replicate my Twitter automations and post to Mastodon. Does anyone have any idea how to create a webhook to do that?

4 Replies 4
autumn
6 - Interface Innovator
6 - Interface Innovator

I think this should be possible with an automation!

You can make a POST request to the Mastodon API using the Run Script action in an automation. Here's the documentation for the fetch() method.

Jason_F
6 - Interface Innovator
6 - Interface Innovator

I wish I was smart enough to figure this out.  Would you mind giving me a sample of the script with this dummy Mastodon status update code?

# Set up

Mastodon mastodon = Mastodon( access_token = 'token.secret', api_base_url = 'https://botsin.space/' ) mastodon.status_post("hello world!")
Jason_F
6 - Interface Innovator
6 - Interface Innovator

Autumn I wanted to follow up with this and see if you would be able to send me an example of the script. I am not a coder and that is where I fall short.

autumn
6 - Interface Innovator
6 - Interface Innovator

Hey Jason! It looks like I didn't have notifications turned on for replies on here. Sure I can totally share some sample code: 

let newStatusToPost = 'Hello World!'

let response = await fetch('https://mastodon.social/api/v1/statuses', {
    method: 'POST',
    body: JSON.stringify({status: newStatusToPost}),
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer YOUR_MASTODON_ACCESS_TOKEN'
    },
});

You'll need to change the mastodon.social part of the url to whatever the url for the mastodon you're posting to is. (that's probably not the right term for it, but I'm not very familiar with mastodon terminology)