I'm encountering a 400
error when attempting to send a message to Twitch's IRC chat using the StreamElements API.
This is my current code, and I am aware that it is incorrect. I'm struggling with passing the message to Twitch in order for it to be accepted. I am currently learning AJAX and plan to learn jQuery in the future, but I would appreciate assistance using vanilla JavaScript.
var data = {"message": "test"};
var token = "secret"
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.streamelements.com/kappa/v2/bot/5eab1a7fc644de5b0169703c/say");
xhr.setRequestHeader("accept", "application/json");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("Authorization", `Bearer ${token}`);
xhr.send(data);