Help Posting Replies to Tweets via X (Twitter) API Using OAuth2 in HTTP Request Node

I’m trying to use the HTTP Request node in n8n to reply to tweets using the official X (Twitter) API with OAuth2 authentication. I’ve successfully fetched the tweet IDs and generated the reply text using a code node.

Now I’m trying to post a reply like this:

json

CopyEdit

{
  "text": "{{ $json.output }}",
  "reply": {
    "in_reply_to_tweet_id": "{{ $('Code').item.json.tweetId }}"
  }
}

I’m using POST https://api.twitter.com/2/tweets with:

  • X OAuth2 API credential
  • JSON/RAW Parameters turned ON
  • Send Body = ON
  • Body Content Type = JSON

But I keep getting the error:
“JSON parameter needs to be valid JSON” or sometimes “Requests with bodies must have content-type of application/json.”

I’ve confirmed:

  • The OAuth2 app has tweet.write scope
  • The tweet ID is valid
  • The JSON structure matches X’s API docs
  • I’m not sending headers manually (leaving them to OAuth2)

Not sure what I’m missing — any help appreciated!

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

nock me, when solv

Hi @kadian666, you need to add one header for the POST method in your case.
The header is Content-Type: application/json, to implement this with n8n, see image below.

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