0

I am new to Javascript , currently writing up a script which sending some string as JSON to Mattermost incoming hook(Mattermost only accept JSON data) . I've tested it with curl , it works without any issues, the command is below :

curl -i -X POST -H 'Content-Type: application/json' -d '{"text": "Hello, this is some text\nThis is more text. :tada:"}'http://mattermost.test.nz/hooks/xxxxxxxxxxxxxxxxxxx

This is the script that I wrote, it's not sending the data to the endpoint for some reason, I've tried to figure it out myself but it's just not working . Please can anyone help..

var xmlhttp = new XMLHttpRequest();
var url = "http://mattermost.test.nz/hooks/xxxxxxxxxxxxxxxxxxx";
var data = {"test"};
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/json; charset=UTF-8");
xmlhttp.send(JSON.stringify(data));
Vikash Patel
  • 1,328
  • 9
  • 28
Dennis.Z
  • 47
  • 3
  • In the first query, it seems that you are sending something like {text:"myText"}, and on the second only {"myText"}. Do you have the server's log and the information status of the request ? – Akah Jun 12 '18 at 06:30
  • The first command just an example, I am using that command as a test and it works. Mattermost only support JSON – Dennis.Z Jun 13 '18 at 00:03
  • Yes, but why on the second example you don't send the same json structure ? And could you show us the response from the server ? – Akah Jun 13 '18 at 05:37
  • Why is this tagged with Alfresco? – Jeff Potts Jun 15 '18 at 03:05
  • as this script will be run on Alfresco server , and I not sure if this is the right way to do it – Dennis.Z Jun 18 '18 at 02:31

0 Answers0