0

I am trying to list members of a Google Chat space using the Google REST API from my TypeScript backend. Currently, I am facing difficulties in implementing this functionality, this is my code:

const { google } = require('googleapis');

async function authenticate() {
  const auth = new google.auth.GoogleAuth({
    keyFile: './pmtest-112533-5b83338226fd.json',
    scopes: ['https://www.googleapis.com/auth/chat.spaces'],
  });

  return await auth.getClient();
}

async function getSpacesList() {
  const client = await authenticate();

  const chat = google.chat({ version: 'v1', auth: client });

  return await chat.spaces.list();
}

getSpacesList()
  .then(response => {
    console.log('response:', response.data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

and I have this error message:

GaxiosError: Google Chat app not found. To create a Chat app, you must turn on the Chat API and configure the app in the Google Cloud console.

What could be the problem?

console.google screenshot

  • Does this answer your question? [Send message to Google Chat using the REST API (Google example not working in 2020)](https://stackoverflow.com/questions/63495912/send-message-to-google-chat-using-the-rest-api-google-example-not-working-in-20) – Manas Khandelwal Jul 13 '23 at 18:23
  • No, I am trying to work with API REST, that link is about App Script. – Kintaro OE Jul 17 '23 at 23:25

1 Answers1

0

The error message is very clear. You need to turn on the Chat API and configure the app in the Google Cloud console before trying to hit their API.

To enable the Chat API, you can visit the following link:

https://console.cloud.google.com/flows/enableapi?apiid=chat.googleapis.com

Additionally, you need a Google Workspace account with access to Google Chat. The Google Chat API will not work with a free Google account (Gmail).

Also, please ensure that your credentials are correct and associated with the project that has already enabled the Google Chat API.

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73
  • I have a Google Workspace account with access to Google Chat. The error I had was due to missing configuration in my Chat: https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat?project=xxxxxx. Now the error I'm facing is "This Chat app is not a member of this space." I suppose it's because I need to add the service account email to my Space or perhaps add the App I'm creating from the Space. However, my app doesn't appear in the list of apps because I don't know how to make it public for my organization. Do you know how I can resolve this issue? – Kintaro OE Jul 17 '23 at 23:22
  • You need to use a service account with domain-wide delegation enabled. Then the chat app will be able to see your space. – TryingToLearn Jul 18 '23 at 21:51