I have been searching through a lot of forums to understand if it's possible to fetch the members from a google space. However, I couldn't find any relevant source that I could rely on. https://developers.google.com/chat/api/reference/rest/v1/spaces.members/list - This is one official documentation page, but was not able to follow since no sample codes/explanations were provided. Could someone shed some light on this topic?
Asked
Active
Viewed 190 times
1 Answers
1
In Google Apps Script you can use UrlFetchApp.fetch()
to create the API call. This is the code:
function listMembers() {
var spaceId = "YOUR_SPACE_ID"
var url = 'https://chat.googleapis.com/v1/spaces/' + spaceId + '/members';
var options = {
'method': 'GET',
'muteHttpExceptions': true,
'headers': {
'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
}
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
You'll need to:
- Link the Google Apps Script project to an Standard GCP Project: https://developers.google.com/apps-script/guides/cloud-platform-projects#access_a_standard
- Enable the Google Chat API in the GCP project: https://console.cloud.google.com/marketplace/product/google/chat.googleapis.com
- Add the following scopes to the appscript.json manifest in your Google Apps Script project:
"oauthScopes": [
"https://www.googleapis.com/auth/chat.memberships",
"https://www.googleapis.com/auth/script.external_request"
]
Note:
This API is only available in the Google's Developer Preview Program, running this code without being part of the program will show you this error:
{
"error": {
"code": 403,
"message": "The Google Cloud project isn't allowed to call this API. To call this API, join the Google Workspace Developer Preview program.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "See the Developer Preview Program page.",
"url": "https://developers.google.com/workspace/preview"
}
]
}
]
}
}

Bryan Monterrosa
- 1,385
- 1
- 3
- 13