Help to connect to Mastodon via oauth2

Hello,
I’m trying to connect Mastodon to n8n via oauth2 but I’m having troubles, probably because of my inexperience.
From the Mastodon panel:

N8N oauth2 config

When I click on connect:

mastodon4

And here the last screen from n8n that I don’t know how to configure.

Could someone please help me to connect to Mastodon? I’ve also opened a node request.
Thank you

Hey @theRAGEhero,

Mastodon is telling you the Redirect URI is not correct, Looking at what you have set up the value you put in Application Website should be in the Redirect URI field. That should solve that issue and hopefully get it working.

Hello @Jon, thank you!

Now I can authorize my app but I still have an error.

image

image

Hey @theRAGEhero,

It could be the access token url, you have hidden the value so I assume it isn’t a url like it should be in n8n.

You are right, it’s not an url. :sweat_smile: Where should I find it?
Thanks

Looking at the Mastadon docs it should be “https://mastodon.example/oauth/token

So I’ve changed that value but still an error. :frowning:

image

Thank you a lot.

I have this working for a different site that uses Oath2.

Do you have an API key that is given to you?

I am not familiar with Mastadon but with the one I use you need to add your API key as a Header in the main screen.

Your credentials screen looks correct to me.

{
  "nodes": [
    {
      "parameters": {
        "authentication": "oAuth2",
        "url": "https://api.xxx.com/co/v1/co",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "XX-Api-Subscription-Key",
              "value": "xxxxxxxxxxxxxxxxxxxxxxxxxx"
            }
          ]
        },
        "queryParametersUi": {
          "parameter": [
            {
              "name": "code",
              "value": "P"
            },
            {
              "name": "include_inactive",
              "value": "false"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        260,
        440
      ],
      "credentials": {
        "oAuth2Api": {
          "id": "2",
          "name": "BB"
        }
      }
    }
  ],
  "connections": {}
}
````{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        110,
        450
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "url": "https://api.xxx.com/code/v1/code/70180/phones",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Bb-Api-Subscription-Key",
              "value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            }
          ]
        },
        "queryParametersUi": {
          "parameter": [
            {
              "name": "code",
              "value": "Phone"
            },
            {
              "name": "include_inactive",
              "value": "false"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        260,
        440
      ],
      "credentials": {
        "oAuth2Api": {
          "id": "2",
          "name": "BB"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "\nconst value = items[0].json.value\n\nreturn value.map(value => ({ json: value }))"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        240,
        640
      ]
    },
    {
      "parameters": {
        "functionCode": "// Code here will run only once, no matter how many input items there are.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function\nconst newItems = []\n// Loop over inputs and add a new field called 'myNewField' to the JSON of each one\nfor (item of items) {\n  if(item.json.type===\"Fax\")\n    newItems.push({json: item.json});\n  \n}\n\n// You can write logs to the browser console\nconsole.log('Done!');\n\nreturn newItems;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        640
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}`

Have you tried setting Authentication to Body? It might be worth making sure you have the correct values in Client ID (ends with D_A) and Client Secret (ends with 5YY).

I got it working with this Credential setup:


Using HTTP node with this config:


I hope it can help others

2 Likes

Thanks @rduarte! Funny enough I was also building a Mastodon bot the other day. Registered my app via curl, then pretty much what you were doing! Thanks for sharing :slight_smile:

1 Like

Wonderful, thank you.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.