I face an issue when trying to GET messages for a specific Google Chat Space using APIs.
I try to use the spaces.messages/list endpoint from the official Google API.
✅ When I try to POST a new message with the same code / scope, it works.
❌ When I fo the GET method to retrieve messages, I get a 404 error message (see below).
My code
function getMessagesInSpaceAPI() {
var service = OAuth2.createService('chat')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
.setPrivateKey(SERVICE_ACCOUNT_PRIVATE_KEY)
.setClientId(SERVICE_ACCOUNT_EMAIL)
.setPropertyStore(PropertiesService.getUserProperties())
.setScope('https://www.googleapis.com/auth/chat.messages');
if (!service.hasAccess()) {
Logger.log('Authentication error: %s', service.getLastError());
return;
} else {
Logger.log('token = ' + service.getAccessToken())
}
// GET MESSAGE
var res = UrlFetchApp.fetch('https://chat.googleapis.com/v1/spaces/AAAAzf4hBOQ/messages', {
method: 'GET',
followRedirects: true,
muteHttpExceptions: true,
headers: { 'Authorization': 'Bearer ' + service.getAccessToken() },
contentType: 'application/json'
});
Logger.log(res)
}
Output
{
"error": {
"code": 404,
"message": "Method not found.",
"status": "NOT_FOUND"
}
}
(tried in Google App Script debugger and also in Postman, same result)