Skip to content

Instantly share code, notes, and snippets.

@oyekanmiayo
Created September 11, 2022 22:49
Show Gist options
  • Save oyekanmiayo/21a52c453bd8754203ce6bcd389bc969 to your computer and use it in GitHub Desktop.
Save oyekanmiayo/21a52c453bd8754203ce6bcd389bc969 to your computer and use it in GitHub Desktop.
How to call slack API
// See https://developers.google.com/apps-script/guides/services/external
// and https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
function fetchListOfChannels() {
var options = {
'method' : 'get',
'contentType': 'application/json',
'headers': {
'Authorization': 'Bearer <access_token>',
}
};
var url = "https://slack.com/api/conversations.list"
+ "?types=private_channel"
+ "&pretty=1";
var response = UrlFetchApp.fetch(url, options);
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data);
for (var i = 0; i < data.channels.length; i++){
Logger.log(data.channels[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment