Search code examples
javascripttypescriptgoogle-cloud-platformgoogle-apigoogle-chat

Error: Google Chat app not found while listing members using Google REST API in TypeScript


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


Solution

  • 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.