Slack API chat.update returns 'not_authed' error Slack API chat.update returns 'not_authed' error json json

Slack API chat.update returns 'not_authed' error


You need to put token to header instead of json payload if using application/json. Here is doc for this.

So you request should look like this:

POST /api/chat.update HTTP/1.1Authorization: Bearer xoxp-xxx-xxx-xxx-xxxContent-Type: application/json;charset=UTF-8{    "channel": "xxx",    "text": "Hello ~World~ Welt",    "ts": "xxx"}

Note: there is no token field in payload.


Well according to the link your provided, Slack does not accept JSON data (weird).

Also, after playing around with their tester, Slack seems to be doing a GET request on https://slack.com/api/chat.update with query parameters attached like this:

https://slack.com/api/chat.update?token=YOUR_TOKEN&ts=YOUR_TIME&channel=YOUR_CHANNEL&text=YOUR_TEXT_URL_ENCODED&pretty=1

So use this code:

var response_payload = {    "token" : access_token,    "ts" : message_ts,    "channel" : channel_id,    "text" : "Approved! you are a winner!"  }function httpGet(theUrl){    var xmlHttp = new XMLHttpRequest();    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request    xmlHttp.send( null );    return xmlHttp.responseText;}response_url = encodeURI("https://slack.com/api/chat.update?token=" + response_payload['token'] + "&ts=" + response_payload['ts'] + "&channel=" + response_payload['channel'] + "&text=" + response_payload['text'] +"&pretty=1");httpGet(response_url);


Ok! thankyou all for your input.. certainly I have learned a little more. After tweeting at slack_api my original code more or less worked as is.. I had to JSON.parse(payload); the payload in order to then access the object parameters within.. the full example is as below.

function post_update(url, payload) {  var options =  {    'method': 'post',    "payload" : payload,  };  var result = UrlFetchApp.fetch(url, options);  return result.getContentText();}function doPost(e) {  var payload = e.parameter.payload;  var json = JSON.parse(payload);  response_url = "https://slack.com/api/chat.update";  // get object elements  var action = json.actions[0].value;  var user = json["user"].name;  var message_ts = json["message_ts"];  var channel_id = json["channel"].id;  if (action == 'approved') // payload if action is 'approved'  {    var response_payload = {      "token" : access_token,      "ts" : message_ts,      "channel" : channel_id,      "text" : "Approved! *" + invitation_name + "* has been sent an invite!",      "attachments" : JSON.stringify([{          "text": ":white_check_mark: Approved by @" + user,           }])      }  }  if (action == 'denied') // payload if action is 'denied'  {    var response_payload = {      "token" : access_token,      "ts" : message_ts,      "channel" : channel_id,      "text" : "Denied. *" + invitation_name + "* has been declined an invite",      "attachments" :JSON.stringify([{          "text": ":exclamation: Declined by @" + user,          }])    }  }  post_update(response_url, response_payload);  return ContentService.createTextOutput().setMimeType(ContentService.MimeType.JSON);}