Chat/messages endpoint thinks sender_id does not match OAuth token

Hey guys, I am very very new to Twitch’s API (so new in fact that it was in the last 5 hours that I became a dev, made an app, and set everything up) so I would very much appreciate some help from someone who knows what they are doing :rofl:

I started by running the following command in CMD:

curl -X POST “https://api.twitch.tv/helix/chat/messages” -H “Authorization: Bearer ” -H “Client-Id: ” -H “Content-Type: application/json” -d “{"broadcaster_id": "", "sender_id": "", "message": "Hello, world! twitchdevHype"}”

(Obviously is just a substitute for what I actually put there, same for the )

Which gave me the error:

{“error”:“Unauthorized”,“status”:401,“message”:“The ID in sender_id must match the user ID found in the request’s OAuth token.”}

So I also tried running:

curl -X POST “https://api.twitch.tv/helix/chat/messages” -H “Authorization: Bearer ” -H “Client-Id: ” -H “Content-Type: application/json” -d “{"broadcaster_id": "", "sender_id": "", "message": "Hello, world! twitchdevHype"}”

Since it looked like I maybe should’ve used that instead, but yet I got this error again:

{“error”:“Unauthorized”,“status”:401,“message”:“The ID in sender_id must match the user ID found in the request’s OAuth token.”}

What am I doing wrong?? (I have terrible luck when it comes to APIs, please help me if you can :grin:)

WAIT WAIT, I FIGURED IT OUT!

Apparently broadcaster_id and sender_id were not supposed to be the Client ID or OAuth token. I saw in another post somewhere that I was supposed to used the get/users endpoint to find out the id via my account name, and the only reason I find that post was because I was trying to run another code in my command prompt and was hit with:

{
“data”: ,
“error”: “Bad Request”,
“message”: “broadcaster_id: must be numeric”,
“status”: 400
}

I hope this helps someone else out there!

To close the loop

broadcaster_id channeID (aka userID) of the target channel you want to send a message to
sender_id userID of the user you want to send a message as

ClientID goes in the header.
The authorization token in the header must of been generated via the same clientID.

So for example for barrycarlyon to send a message in cohhcarnage chat

  • Client-ID = hozgh446gdilj5knsrsxxz8tahr3koz
  • Authorization = Bearer SomeToken
  • broadcaster_id = 26610234
  • sender_id = 15185913

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