Using the REST API

The Google Chat REST API provides a way for bots to establish context for their operation. You can use the API to perform the following operations:

  • List the spaces that the bot has been added to
  • List the members that belong to a space
  • Create, delete, and modify messages

To use this API, you must create a service account and use the service account to invoke the API. The service account must be authenticated before you can do this, because there is no interactive auth flow for service accounts.

For details, see the reference documentation or go directly to the documentation for specific methods:

Authorizing the service account

Before making any calls to the API, your code needs to authenticate using OAuth 2.0, with credentials for the service account associated with your bot. The authorization call will resemble this one from the async HTTP bot sample:

scopes = ['']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'service-acct.json', scopes)
http_auth = credentials.authorize(Http())

Do not try to authorize using end-user credentials.

Locating the discovery document

The discovery document for this API is located at the following URL: