# Google Chat API & Chat MCP Documentation - Full Corpus > Official developer documentation, REST/gRPC API references, and Model Context Protocol (MCP) tool definitions for building Google Chat apps, AI agents, and integrations on Google Workspace. ## How AI coding agents should use this documentation - **Fetch clean Markdown (`.md.txt`):** Every internal documentation page on `developers.google.com/workspace/...` is available as clean Markdown by appending `.md.txt` before any `?query` or `#fragment` (or by sending the HTTP header `Accept: text/markdown`). - **Always use Cards v2 (`cardsV2`), never Cards v1:** When constructing card messages or dialogs, always populate `Message.cardsV2` (`CardWithId` wrapping `google.apps.card.v1.Card`). Never generate deprecated `Message.cards` (Cards v1) payloads. - **Choose the right authentication model:** Use **App authentication** (service account with scope `https://www.googleapis.com/auth/chat.bot`) when acting as the Chat app itself (including sending `cardsV2` messages). Use **User authentication** (OAuth 2.0 scopes such as `chat.messages`, `chat.spaces`, `chat.memberships`) when acting on behalf of a human user; user-authenticated `messages.create` calls support `text`, whereas `cardsV2` requires app authentication. Use **Incoming webhooks** only for one-way notifications into a single space without interactive callbacks. - **Google Chat MCP Server (`chatmcp.googleapis.com`):** Connect MCP hosts to `https://chatmcp.googleapis.com/mcp/v1` with OAuth 2.0 bearer tokens to invoke official Chat tools (`list_messages`, `search_messages`, `search_conversations`, `send_message`, `list_memberships`, `mark_as_read`, `mark_as_unread`, `update_notification_settings`, `get_notification_settings`). - **Message size & formatting syntax:** Maximum `Message` payload size is 32,000 bytes. For `Message.text`, Chat API supports standard Markdown (`MARKUP_SYNTAX_MARKDOWN`, default for newly created and unconfigured apps) and Chat markup (`MARKUP_SYNTAX_CHAT`: `*bold*`, `_italic_`, `~strikethrough~`, ``, ``, default for existing configured apps and incoming webhooks). --- Source: https://developers.google.com/workspace/chat/overview.md.txt # Develop with Google Chat This page provides an overview of the Google Chat API and Google Chat apps. ## Google Chat API overview The Chat API consists of [gRPC services or REST resources and methods](https://cloud.google.com/apis/docs/client-libraries-explained) that grant access to Chat, including spaces, space members, messages, message reactions, message attachments, space events, and user read states. ### Concepts The following section defines the services, resources, and methods for the Chat API: *Spaces* : *Spaces* are places where people and apps can converse and share files. There are several types of spaces. Direct messages (DMs) are 1:1 conversations between two users or a user and a Chat app. Group chats are conversations between three or more users and Chat apps. Named spaces are persistent places where people send messages, share files, and collaborate. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.Space) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.md.txt) : For example usage, see: * [Create a space](https://developers.google.com/workspace/chat/create-spaces.md.txt) * [Set up a space](https://developers.google.com/workspace/chat/set-up-spaces.md.txt) * [Get a space](https://developers.google.com/workspace/chat/get-spaces.md.txt) * [List spaces](https://developers.google.com/workspace/chat/list-spaces.md.txt) * [Update a space](https://developers.google.com/workspace/chat/update-spaces.md.txt) * [Delete a space](https://developers.google.com/workspace/chat/delete-spaces.md.txt) * [Find a direct message (DM)](https://developers.google.com/workspace/chat/find-direct-message-in-spaces.md.txt) *Members* : *Members* are users and Chat apps that have joined or are invited to a space. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.Membership) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.members.md.txt) : For example usage, see: * [Create a membership](https://developers.google.com/workspace/chat/create-members.md.txt) * [Get a membership](https://developers.google.com/workspace/chat/get-members.md.txt) * [List memberships](https://developers.google.com/workspace/chat/list-members.md.txt) * [Update a membership](https://developers.google.com/workspace/chat/update-members.md.txt) * [Delete a membership](https://developers.google.com/workspace/chat/delete-members.md.txt) *Messages* : *Messages* include [text](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages.md.txt) and [card](https://developers.google.com/workspace/chat/api/reference/rest/v1/cards.md.txt) communications posted in spaces. Messages can have files attached to them. People can react to messages by appending emoji to them. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.Message) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages.md.txt) : For example usage, see: * [Create a message](https://developers.google.com/workspace/chat/create-messages.md.txt) * [Get a message](https://developers.google.com/workspace/chat/get-messages.md.txt) * [List messages](https://developers.google.com/workspace/chat/list-messages.md.txt) * [Update a message](https://developers.google.com/workspace/chat/update-messages.md.txt) * [Delete a message](https://developers.google.com/workspace/chat/delete-messages.md.txt) *Reactions* : *Reactions* represent the emoji people use to react to a message, such as 👍, 🚲, and 🌞. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.Reaction) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages.reactions.md.txt) : For example usage, see: * [Create a reaction](https://developers.google.com/workspace/chat/create-reactions.md.txt) * [List reactions](https://developers.google.com/workspace/chat/list-reactions.md.txt) * [Delete a reaction](https://developers.google.com/workspace/chat/delete-reactions.md.txt) *Custom emoji* : *Custom emoji* represent custom emoji created and shared within the organization in Google Chat. Custom emoji can be included in the content of a message or used to react to a message. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.CustomEmoji) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/customEmojis.md.txt) : For example usage, see: * [Create a custom emoji](https://developers.google.com/workspace/chat/create-custom-emoji.md.txt) * [Delete a custom emoji](https://developers.google.com/workspace/chat/delete-custom-emoji.md.txt) * [Get details about a custom emoji](https://developers.google.com/workspace/chat/get-custom-emoji.md.txt) * [List custom emojis in an organization](https://developers.google.com/workspace/chat/list-custom-emojis.md.txt) *Sections* : *Sections* are ways for users to group their conversations and customize the list of spaces displayed in the Google Chat navigation panel. There are predefined system sections and user-defined custom sections. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.Section) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/users.sections.md.txt) : For example usage, see: * [Create a section](https://developers.google.com/workspace/chat/create-section.md.txt) * [Update a section](https://developers.google.com/workspace/chat/update-section.md.txt) * [Delete a section](https://developers.google.com/workspace/chat/delete-section.md.txt) * [Change the position of a section](https://developers.google.com/workspace/chat/position-section.md.txt) * [List sections](https://developers.google.com/workspace/chat/list-sections.md.txt) * [List spaces in a section](https://developers.google.com/workspace/chat/list-section-items.md.txt) * [Move a space to a different section](https://developers.google.com/workspace/chat/move-section-item.md.txt) *Media and attachments* : *Media* represents a file uploaded to Google Chat, like images, videos, and documents. : Media resource reference (Unavailable in RPC): * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/media.md.txt) : *Attachments* are instances of media (files) attached to messages. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.Attachment) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages.attachments.md.txt) : For example usage, see: * [Upload media as an attachment](https://developers.google.com/workspace/chat/upload-media-attachments.md.txt) * [Download media as an attachment](https://developers.google.com/workspace/chat/download-media-attachments.md.txt) * [Get an attachment](https://developers.google.com/workspace/chat/get-media-attachments.md.txt) *Space events* : *Space events* represent changes to a space or its child resources, including its members, messages, and reactions. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.SpaceEvent) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.spaceEvents.md.txt) : For example usage, see: * [Get space read state](https://developers.google.com/workspace/chat/get-space-read-state.md.txt) * [Update space read state](https://developers.google.com/workspace/chat/update-space-read-state.md.txt) * [Get thread read state](https://developers.google.com/workspace/chat/get-thread-read-state.md.txt) *User read states* : *User read states* are singleton resources that represent details about a specified user's last read message in a Google Chat space or a message thread. : Space read state resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.SpaceReadState) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/users.spaces.md.txt) : Thread read state resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.ThreadReadState) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/users.spaces.threads.md.txt) : For example usage, see: * [Get space read state](https://developers.google.com/workspace/chat/get-space-read-state.md.txt) * [Update space read state](https://developers.google.com/workspace/chat/update-space-read-state.md.txt) * [Get thread read state](https://developers.google.com/workspace/chat/get-thread-read-state.md.txt) *User space notification settings* : *User space notification settings* are singleton resources that represent a specified user notification settings in a Google Chat space. : Resource reference: * [RPC reference](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1.md.txt#google.chat.v1.SpaceNotificationSetting) * [REST reference](https://developers.google.com/workspace/chat/api/reference/rest/v1/users.spaces.spaceNotificationSetting.md.txt) ### Authentication Calling the Chat API requires authentication. Each Chat API method requires either [user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user.md.txt) (to perform actions or access data on behalf of a user) or [app authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app.md.txt) (to perform actions or access data as a Chat app). Some methods support both user authentication and app authentication. To learn more about authentication in Chat, see [Authentication overview](https://developers.google.com/workspace/chat/authenticate-authorize.md.txt). ### Client libraries The recommended way for most developers to call the Google Chat API is with our officially supported [Cloud Client Libraries](https://developers.google.com/workspace/chat/libraries.md.txt) for your preferred language, like Python, Java, or Node.js. If you're coding with Google Apps Script, use the [Advanced Chat service](https://developers.google.com/apps-script/advanced/chat.md.txt) instead of installing a client library. ## Build Chat apps The Chat API lets you build Google Chat apps that bring your services and resources right into Google Chat. You can build Chat apps to do any of the following: + Retrieve information based on structured or free text queries entered by the user. + Generate incident reports or other artifacts, using information provided by the user. + Enhance team collaboration, such as providing "team memory" or scheduling resources. You can design your Chat app using several different architecture styles, including the following: * **Interactive apps**: Respond to user interaction, such as @mentions or slash commands, and present information or guide users through a workflow with cards and dialogs. * **Command-line apps or webhooks**: Send proactive messages, such as alarms or notifications, from another system into a space. Users can't directly interact with this type of app. * **Event-driven apps**: Subscribe to and react to activity in a Chat space, such as a new member joining. In response to an event, the app can send a message or perform another action. For details about designing your Chat app, see [Choose a Google Chat app architecture](https://developers.google.com/workspace/chat/structure.md.txt). ## Related topics * [Integrate Chat using AI assistance](https://developers.google.com/workspace/chat/build-with-ai.md.txt). * [Explore Google Chat app samples](https://developers.google.com/workspace/chat/samples.md.txt). * [Build interactive Google Chat apps](https://developers.google.com/workspace/chat/interact-users-overview.md.txt). * [Choose a Google Chat app architecture](https://developers.google.com/workspace/chat/structure.md.txt).
Want to see the Google Chat API in action?
The Google Workspace Developers channel offers videos about tips, tricks, and the latest features.
--- Source: https://developers.google.com/workspace/chat/build-with-ai.md.txt # Integrate Google Chat using AI assistance Streamline your Google Chat apps and Google Chat API development by pairing AI coding tools with official Chat documentation, machine-readable Markdown indexes, and Model Context Protocol (MCP) servers. This guide explains how to ground your AI coding assistant in up-to-date Chat developer documentation using the **Developer Knowledge API** and curated Markdown endpoints, and how to connect the **Chat MCP server** to read and act on Chat resources. ## Why use AI assistance with official documentation? General-purpose AI models can confuse deprecated Chat card formats, mix up user and app OAuth scopes, or rely on outdated API schemas. Grounding your AI assistant with official Google developer tools solves these challenges: * **Official documentation grounding**: by connecting to the [Developer Knowledge API](https://developers.google.com/knowledge.md.txt) or referencing the curated Chat `llms.txt` index, your agent verifies Cards v2 syntax, authentication scopes, and webhook payloads against current documentation. * **Reduced token overhead**: instead of scraping full HTML pages, your agent fetches compact Markdown snippets and `.md.txt` guides tailored for language models. * **Fewer hallucinations**: grounded agents check official REST, gRPC, and MCP schemas on `developers.google.com` before generating code. * **Actionable execution**: combine documentation search with the Chat MCP server and the `gcloud` command-line tool so your agent can enable APIs, inspect spaces, and test messages on your behalf. ## The Chat AI toolkit Depending on your workflow, you can equip your AI coding assistant with four complementary layers of support: 1. **Documentation search (Developer Knowledge MCP server)**: connects your assistant to live Google developer documentation across supported domains, including `developers.google.com`. 1. **Machine-readable documentation** (`llms.txt` and `.md.txt`): gives coding agents, prompt files, and research tools direct plain-text indexes and per-page Markdown for Chat. 1. **Documentation search skills**: provides reusable instructions that teach compatible coding agents when and how to query official Google developer documentation. 1. **Google Workspace actions (Chat MCP server)**: allows authorized AI applications to list spaces, search messages, and send messages through `https://chatmcp.googleapis.com/mcp/v1`. ## Supported AI coding clients You can use these tools with AI coding assistants and research environments that support MCP servers, HTTP Markdown fetching, or agent skills, including: * **Google Antigravity** * **Cursor** * **Visual Studio Code** (with MCP-compatible extensions) * **Claude Code** * **Google AI Studio** and **NotebookLM** ## Step-by-step setup guide Follow these steps to configure your AI coding assistant for Chat development. ### Step 1: Install documentation search skills To help your AI coding assistant search official Chat documentation, install the Developer Knowledge documentation search skill. In compatible coding clients, prompt your assistant to install the skill: ```markdown Install the official Google Developer Knowledge documentation search skill into this workspace. ``` If you prefer to install the skill manually from your terminal, run: ```sh npx skills add google/skills --skill retrieving-developer-knowledge ``` ### Step 2: Connect the Developer Knowledge MCP server The Developer Knowledge MCP server is a remote HTTP MCP server at `https://developerknowledge.googleapis.com/mcp` that lets your coding assistant query current documentation from `developers.google.com` using the `search_documents`, `get_documents`, and `answer_query` tools. Before you connect, [create an API key](https://developers.google.com/knowledge/mcp.md.txt#choose-auth) restricted to the Developer Knowledge API. If you use Antigravity, you can install the server from the built-in MCP store and authenticate with your Google credentials. #### AI-assisted setup Ask your coding assistant to add the MCP server to your client configuration: ```markdown Add the Google Developer Knowledge MCP server (https://developerknowledge.googleapis.com/mcp) to my MCP configuration, using the X-Goog-Api-Key header with my API key. ``` #### Manual configuration To configure the server manually, add the following entry to your client's MCP configuration file (for example, `.cursor/mcp.json` or `.vscode/mcp.json`), replacing YOUR_API_KEY with your API key: ```json { "mcpServers": { "google-developer-knowledge": { "url": "https://developerknowledge.googleapis.com/mcp", "headers": { "X-Goog-Api-Key": "YOUR_API_KEY" } } } } ``` Some clients use a different key for the server URL (for example, `serverUrl` in Antigravity). For client-specific instructions, see [Connect to the Developer Knowledge MCP server](https://developers.google.com/knowledge/mcp.md.txt). ### Step 3: Connect the Chat MCP server If you want your AI assistant to interact directly with Chat conversations - such as listing memberships, searching messages, or sending test messages - enable `chat.googleapis.com` and `chatmcp.googleapis.com` in your Google Cloud project and connect to the remote endpoint at `https://chatmcp.googleapis.com/mcp/v1`. For OAuth credential setup and client configuration steps, see [Configure the Chat MCP server][chat-mcp-guide]. ## Ground your agent with machine-readable documentation If your tool doesn't use MCP servers, or if you maintain project instruction files such as `AGENTS.md` or `CLAUDE.md`, point your assistant directly to Chat's machine-readable documentation endpoints: * **Curated documentation index** (`llms.txt`): use the [Chat `llms.txt` index][chat-llms-txt] (`https://developers.google.com/workspace/chat/llms.txt`) for a compact map of Chat guides, REST and gRPC references, MCP tools, and key API guardrails (such as using `cardsV2` instead of deprecated `cards`, and choosing between app and user OAuth scopes). * **Full documentation bundle** (`llms-full.txt`): load the [Chat `llms-full.txt` corpus][chat-llms-full-txt] (`https://developers.google.com/workspace/chat/llms-full.txt`) into large-context tools such as Google AI Studio or NotebookLM when you want all Chat guides and the reference directory in a single file. * **Per-page Markdown** (`.md.txt` and `Accept: text/markdown`): append `.md.txt` to any Chat documentation URL (for example, `https://developers.google.com/workspace/chat/create-messages.md.txt`), click **Copy page** at the top of a page, or open its menu and select **View as Markdown**. Agents that send `Accept: text/markdown` receive Markdown automatically on canonical URLs. For example, you can add the following block to your repository's `AGENTS.md` or `CLAUDE.md` file: ```markdown ## Google Chat API documentation - Start from https://developers.google.com/workspace/chat/llms.txt to locate relevant guides, REST/gRPC schemas, and Chat MCP tool references. - Fetch individual pages as Markdown by appending `.md.txt` (or sending `Accept: text/markdown`). - Always use Cards v2 (`Message.cardsV2`), never deprecated Cards v1. ``` ## Recommended prompting workflows Combine official documentation lookup with specific implementation goals so your agent verifies schemas before writing code. ### Effective prompt patterns * **Specify the documentation domain**: ask your assistant to check official Chat documentation before generating payloads or OAuth code. * *Example*: *"Search official Chat docs on `developers.google.com` for app authentication in a Chat app, then configure credentials in my Python service."* * **Verify card and interaction schemas first**: have your agent confirm Cards v2 widget fields before editing UI handlers. * *Example*: *"Check `/workspace/chat/create-messages` and the Cards v2 reference for interactive button click payloads, summarize the JSON structure, and add an approval card to `bot.js`."* * **Pair documentation with Chat MCP actions**: combine documentation lookup with live MCP tool calls to verify and test. * *Example*: *"Look up the Chat message formatting rules in official docs, then use `send_message` to post a formatted release summary to my test space."* ### General iterative workflow 1. **Research**: ask your agent to search official Chat documentation or read `/workspace/chat/llms.txt` for the feature you want to build. 1. **Plan**: have the agent propose an architecture, OAuth scope selection, and file plan based on the retrieved documentation. 1. **Execute**: let the agent generate code, install client libraries, or run `gcloud` setup commands. 1. **Verify**: ask the agent to check its card JSON and API calls against official Chat API references and run local tests. ## Next steps * [Configure the Chat MCP server][chat-mcp-guide] * [Explore the Developer Knowledge API and MCP server](https://developers.google.com/knowledge.md.txt) * [Develop with Chat overview](https://developers.google.com/workspace/chat/overview.md.txt) * [Try Chat app samples and tutorials][chat-samples] [chat-mcp-guide]: https://developers.google.com/workspace/chat/api/guides/configure-mcp-server.md.txt [chat-llms-txt]: https://developers.google.com/workspace/chat/llms.txt [chat-llms-full-txt]: https://developers.google.com/workspace/chat/llms-full.txt [chat-samples]: https://developers.google.com/workspace/chat/samples.md.txt --- Source: https://developers.google.com/workspace/chat/api/guides/quickstart/apps-script.md.txt # Google Apps Script quickstart Create a [Google Apps Script](https://developers.google.com/apps-script/overview.md.txt) that makes requests to the Google Chat API. Quickstarts explain how to set up and run an app that calls a Google Workspace API. This quickstart uses a simplified authentication approach that is appropriate for a testing environment. For a production environment, we recommend learning about [authentication and authorization](https://developers.google.com/workspace/guides/auth-overview.md.txt) before [choosing the access credentials](https://developers.google.com/workspace/guides/create-credentials.md.txt#choose_the_access_credential_that_is_right_for_you) that are appropriate for your app. In Apps Script, Google Workspace quickstarts use [Advanced Google services](https://developers.google.com/apps-script/guides/services/advanced.md.txt) to call Google Workspace APIs and handle some details of the authentication and authorization flow. ## Objectives + Configure the environment. + Create and configure the script. + Run the script. ## Prerequisites * [A Google Cloud project](https://developers.google.com/workspace/guides/create-project.md.txt). * Access to Google Drive ## Configure your Cloud project If you're using a new Google Cloud project to complete this quickstart, you need to configure it and add yourself as a test user. If you've already completed these steps for your Cloud project, skip to the next section. ### Open your Cloud project in the Google API Console If it's not open already, open the Cloud project that you intend to use for this sample:
  1. In the Google API Console, go to the Select a project page.

    Select a Cloud project

  2. Select the Google Cloud project you want to use. Or, click Create project and follow the on-screen instructions. If you create a Google Cloud project, you might need to turn on billing for the project.
### Turn on the Chat API Before using Google APIs, you need to turn them on in a Google Cloud project. You can turn on one or more APIs in a single Google Cloud project. ### Configure the OAuth consent screen
  1. In the Google API Console, go to Menu menu > Google Auth platform > Branding.

    Go to Branding

  2. If you have already configured the Google Auth platform, you can configure the following OAuth Consent Screen settings in Branding, Audience, and Data Access. If you see a message that says Google Auth platform not configured yet, click Get Started:
    1. Under App Information, in App name, enter a name for the app.
    2. In User support email, choose a support email address where users can contact you if they have questions about their consent.
    3. Click Next.
    4. Under Audience, select Internal.
    5. Click Next.
    6. Under Contact Information, enter an Email address where you can be notified about any changes to your project.
    7. Click Next.
    8. Under Finish, review the Google API Services User Data Policy and if you agree, select I agree to the Google API Services: User Data Policy.
    9. Click Continue.
    10. Click Create.
  3. For now, you can skip adding scopes. In the future, when you create an app for use outside of your Google Workspace organization, you must change the User type to External. Then add the authorization scopes that your app requires. To learn more, see the full Configure OAuth consent guide.
### Configure the Google Chat app Note: To perform read-only API calls with user authentication, such as `GetSpace` or `ListMessages`, you don't need to configure a Google Chat app. You only need to enable the API and create an OAuth client. To perform create, update, and delete Google Chat API calls, you must configure a Google Chat app. For any write requests, Google Chat attributes the Google Chat app in the UI using the following information. 1. In the Google API Console, go to the Chat API **Configuration** page: [Go to Chat API Configuration page](https://console.developers.google.com/apis/api/chat.googleapis.com/hangouts-chat) 1. Under **Application info**, enter the following information: 1. In the **App name** field, enter `Chat API quickstart app`. 1. In the **Avatar URL** field, enter `https://developers.google.com/chat/images/quickstart-app-avatar.png`. 1. In the **Description** field, enter `Quickstart for calling the Chat API`. 1. Under **Interactive features**, click the **Enable interactive features** toggle to the off position to disable interactive features for the Chat app. 1. Click **Save**. ## Create the script 1. Create a new script in the Apps Script editor by going to [script.google.com/create](https://script.google.com/create). 1. Replace the contents of the script editor with the following code:
  1. Click Save .
  2. Click Untitled project, type Quickstart, and click Rename.
## Configure the script ### Copy the Cloud project number
  1. In the Google API Console, go to Menu menu > IAM & Admin > Settings.

    Go to IAM & Admin Settings

  2. In the Project number field, copy the value.
### Link your Google Cloud project 1. Open the Apps Script project. 1. Click **Project Settings** settings. 1. Under **Google Cloud Platform (GCP) Project**, click **Change project**. 1. In **GCP project number**, paste the Google Cloud project number. 1. Click **Set project**. ### Enable the Google Chat API Open the Apps Script project. 1. Click **Project Settings** settings. 1. Under **General settings**, enable **Show "appsscript.json" manifest file in editor**. 1. Click **Editor** code, select the file `appscript.json`, and replace the contents with the following code: ## Run the sample In the Apps Script editor, click **Run**. The first time you run the sample, it prompts you to authorize access: 1. Click **Review permissions**. 1. Choose an account. 1. Click **Allow**. The script's execution log appears at the bottom of the window.
## Next steps * [Google Apps Script Advanced Services documentation](https://developers.google.com/apps-script/guides/services/advanced.md.txt) * [Try the Google Workspace APIs in the APIs explorer](https://developers.google.com/workspace/explore.md.txt) --- Source: https://developers.google.com/workspace/chat/api/guides/quickstart/java.md.txt # Java quickstart Create a Java command-line application that makes requests to the Google Chat API. Quickstarts explain how to set up and run an app that calls a Google Workspace API. This quickstart uses a simplified authentication approach that is appropriate for a testing environment. For a production environment, we recommend learning about [authentication and authorization](https://developers.google.com/workspace/guides/auth-overview.md.txt) before [choosing the access credentials](https://developers.google.com/workspace/guides/create-credentials.md.txt#choose_the_access_credential_that_is_right_for_you) that are appropriate for your app. This quickstart uses Google Workspace's recommended API client libraries to handle some details of the authentication and authorization flow. ## Objectives + Set up your environment. + Set up the sample. + Run the sample. ## Prerequisites * Java 11 or greater. * [Gradle 7.0 or greater](https://gradle.org/install/). * [A Google Cloud project](https://developers.google.com/workspace/guides/create-project.md.txt). ## Set up your environment To complete this quickstart, set up your environment. ### Enable the API Before using Google APIs, you need to turn them on in a Google Cloud project. You can turn on one or more APIs in a single Google Cloud project. ### Create a service account A service account is a special kind of account used by an application, rather than a person. You can use a service account to access data or perform actions by the robot account, or to access data on behalf of Google Workspace or Cloud Identity users. For more information, see Service accounts overview. SERVICE_ACCOUNT_NAME SERVICE_ACCOUNT_NAME

Google Cloud Console

  1. In the Google Cloud Console, go to Menu menu > IAM & Admin > Service Accounts.

    Go to Service Accounts

    The remaining steps appear in the Google Cloud Console.

  2. Select a Google Cloud project.
  3. Click Create service account.
  4. Enter a service account name to display in the Google Cloud Console.
  5. If you don't want to set access controls now, click Done to finish creating the service account. To set access controls now, click Create and continue and proceed to the next step.
  6. In the Grant this service account access to project section, add the following roles:
    • ROLE_NAME
  7. Optional: Assign roles to your service account to grant access to your Google Cloud project's resources in addition to Google Workspace resources. For more details, refer to Manage access to projects, folders, and organizations.
  8. Click Continue.
  9. Click Done to finish creating the service account.

    Make a note of the email address for the service account.

gcloud CLI

  1. Create the service account:
    gcloud iam service-accounts create SERVICE_ACCOUNT_NAME \
      --display-name="SERVICE_ACCOUNT_NAME"
  2. Grant the necessary roles to the service account:
    gcloud projects add-iam-policy-binding PROJECT_ID \
      --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" \
      --role="ROLE_NAME"

    Replace PROJECT_ID with your Google Cloud project ID.

  3. Optional: Assign roles to your service account to grant access to your Google Cloud project's resources in addition to Google Workspace resources. For more details, refer to Manage access to projects, folders, and organizations.
#### Create credentials for a service account You need to obtain credentials in the form of a public/private key pair. These credentials are used by your code to authorize service account actions within your app.
  1. In the Google Cloud Console, go to Menu menu > IAM & Admin > Service Accounts.

    Go to Service Accounts

    The remaining steps appear in the Google Cloud Console.

  2. Select a Google Cloud project.
  3. Click the email address of the service account that you want to create a key for.
  4. Click the Keys tab.
  5. Click the Add key drop-down menu, then select Create new key.
  6. Select JSON as the Key type and click Create.

    Your new public/private key pair is generated and downloaded to your machine as a service account key file. Save the downloaded JSON file as credentials.json in your working directory. This file is the only copy of this key. After you download the key file, you cannot download it again. For information about how to store your key securely, see Best practices for managing service account keys.

#### Set up domain-wide delegation for a service account Use domain-wide delegation when your application needs to access Google Workspace data on behalf of multiple individual users in your organization (such as sending emails using the Gmail API) without requiring individual user consent. To call APIs on behalf of users in a Google Workspace organization, grant your service account domain-wide delegation of authority in the Google Admin console using a Super Admin account. For more information, see Delegate domain-wide authority to the service account.
  1. In the Google Cloud Console, go to Menu menu > IAM & Admin > Service Accounts.

    Go to Service Accounts

  2. Select a Google Cloud project.
  3. Click the email address of the service account that you want to set up domain-wide delegation for.
  4. Click Show advanced settings.
  5. Under "Domain-wide delegation", find your service account's "Client ID."
  6. Click Copy content_copy to copy the client ID value to your clipboard.
  7. If you have Super Admin access to the relevant Google Workspace account, click View Google Workspace Admin Console, sign in with your super administrator user account, and continue following these steps.

    If you don't have super administrator access to the relevant Google Workspace account, contact a super administrator for the account. Send them your service account's client ID and a list of OAuth Scopes required by your app so they can complete the following steps in the Google Admin console.

    1. In the Google Admin console, go to Menu menu > Security > Access and data control > API controls.

      Go to API controls

    2. Click Manage Domain Wide Delegation.
    3. Click Add new.
    4. In the Client ID field, paste the client ID that you previously copied.
    5. In the OAuth Scopes field, enter a comma-delimited list of the scopes required by your app. This is the same set of scopes you defined when configuring the OAuth consent screen.
    6. Click Authorize.

      Changes can take up to 24 hours but typically happen more quickly. For more information, see Control API access with domain-wide delegation.

### Configure the OAuth consent screen If you're using a new Google Cloud project to complete this quickstart, configure the OAuth consent screen. If you've already completed this step for your Cloud project, skip to the next section.
  1. In the Google API Console, go to Menu menu > Google Auth platform > Branding.

    Go to Branding

  2. If you have already configured the Google Auth platform, you can configure the following OAuth Consent Screen settings in Branding, Audience, and Data Access. If you see a message that says Google Auth platform not configured yet, click Get Started:
    1. Under App Information, in App name, enter a name for the app.
    2. In User support email, choose a support email address where users can contact you if they have questions about their consent.
    3. Click Next.
    4. Under Audience, select Internal.
    5. Click Next.
    6. Under Contact Information, enter an Email address where you can be notified about any changes to your project.
    7. Click Next.
    8. Under Finish, review the Google API Services User Data Policy and if you agree, select I agree to the Google API Services: User Data Policy.
    9. Click Continue.
    10. Click Create.
  3. For now, you can skip adding scopes. In the future, when you create an app for use outside of your Google Workspace organization, you must change the User type to External. Then add the authorization scopes that your app requires. To learn more, see the full Configure OAuth consent guide.
### Authorize credentials for a desktop application To authenticate end users and access user data in your app, you need to create one or more OAuth 2.0 Client IDs. A client ID is used to identify a single app to Google's OAuth servers. If your app runs on multiple platforms, you must create a separate client ID for each platform.
  1. In the Google Cloud Console, go to Menu menu > Google Auth platform > Clients.

    Go to Clients

  2. Click Create Client.
  3. Click Application type > Desktop app.
  4. In the Name field, type a name for the credential. This name is only shown in the Google Cloud Console.
  5. Optional: If your app is an AI agent that takes actions on behalf of users, select Use this client for an AI-powered agent. If your app supports both AI agent workflows and standard user features, create separate OAuth clients for each. You can't change this setting after you create the client.
  6. Click Create.

    The newly created credential appears under "OAuth 2.0 Client IDs."

  7. Save the downloaded JSON file as credentials.json, and move the file to your working directory.
### Configure the Google Chat app Note: To perform read-only API calls with user authentication, such as `GetSpace` or `ListMessages`, you don't need to configure a Google Chat app. You only need to enable the API and create an OAuth client. To perform create, update, and delete Google Chat API calls, you must configure a Google Chat app. For any write requests, Google Chat attributes the Google Chat app in the UI using the following information. 1. In the Google API Console, go to the Chat API **Configuration** page: [Go to Chat API Configuration page](https://console.developers.google.com/apis/api/chat.googleapis.com/hangouts-chat) 1. Under **Application info**, enter the following information: 1. In the **App name** field, enter `Chat API quickstart app`. 1. In the **Avatar URL** field, enter `https://developers.google.com/chat/images/quickstart-app-avatar.png`. 1. In the **Description** field, enter `Quickstart for calling the Chat API`. 1. Under **Interactive features**, click the **Enable interactive features** toggle to the off position to disable interactive features for the Chat app. 1. Click **Save**. ## Prepare the workspace 1. In your working directory, create a new project structure: ```none gradle init --type basic mkdir -p src/main/java src/main/resources ``` 1. In the `src/main/resources/` directory, copy the `credentials.json` file that you previously downloaded. 1. Open the default `build.gradle` file and replace its contents with the following code: ## Set up the sample 1. In the `src/main/java/` directory, create a new Java file with a name that matches the `mainClassName` value in your `build.gradle` file. 1. Include the following code in your new Java file: ## Run the sample 1. Run the sample:
  gradle run
  
  1. The first time you run the sample, it prompts you to authorize access:
    1. If you're not already signed in to your Google Account, sign in when prompted. If you're signed in to multiple accounts, select one account to use for authorization.
    2. Click Accept.

    Your Java application runs and calls the Google Chat API.

    Authorization information is stored in the file system, so the next time you run the sample code, you aren't prompted for authorization.

## Next steps * [Try the Google Workspace APIs in the APIs explorer](https://developers.google.com/workspace/explore.md.txt) --- Source: https://developers.google.com/workspace/chat/api/guides/quickstart/nodejs.md.txt # Node.js quickstart Create a Node.js command-line application that makes requests to the Google Chat API. Quickstarts explain how to set up and run an app that calls a Google Workspace API. This quickstart uses a simplified authentication approach that is appropriate for a testing environment. For a production environment, we recommend learning about [authentication and authorization](https://developers.google.com/workspace/guides/auth-overview.md.txt) before [choosing the access credentials](https://developers.google.com/workspace/guides/create-credentials.md.txt#choose_the_access_credential_that_is_right_for_you) that are appropriate for your app. This quickstart uses Google Workspace's recommended API client libraries to handle some details of the authentication and authorization flow. ## Objectives + Set up your environment. + Install the client library. + Set up the sample. + Run the sample. ## Prerequisites To run this quickstart, you need the following prerequisites: * [Node.js & npm](https://docs.npmjs.com/getting-started/installing-node#1-install-nodejs--npm) installed. * [A Google Cloud project](https://developers.google.com/workspace/guides/create-project.md.txt). ## Set up your environment To complete this quickstart, set up your environment. ### Enable the API Before using Google APIs, you need to turn them on in a Google Cloud project. You can turn on one or more APIs in a single Google Cloud project. ### Create a service account A service account is a special kind of account used by an application, rather than a person. You can use a service account to access data or perform actions by the robot account, or to access data on behalf of Google Workspace or Cloud Identity users. For more information, see Service accounts overview. SERVICE_ACCOUNT_NAME SERVICE_ACCOUNT_NAME

Google Cloud Console

  1. In the Google Cloud Console, go to Menu menu > IAM & Admin > Service Accounts.

    Go to Service Accounts

    The remaining steps appear in the Google Cloud Console.

  2. Select a Google Cloud project.
  3. Click Create service account.
  4. Enter a service account name to display in the Google Cloud Console.
  5. If you don't want to set access controls now, click Done to finish creating the service account. To set access controls now, click Create and continue and proceed to the next step.
  6. In the Grant this service account access to project section, add the following roles:
    • ROLE_NAME
  7. Optional: Assign roles to your service account to grant access to your Google Cloud project's resources in addition to Google Workspace resources. For more details, refer to Manage access to projects, folders, and organizations.
  8. Click Continue.
  9. Click Done to finish creating the service account.

    Make a note of the email address for the service account.

gcloud CLI

  1. Create the service account:
    gcloud iam service-accounts create SERVICE_ACCOUNT_NAME \
      --display-name="SERVICE_ACCOUNT_NAME"
  2. Grant the necessary roles to the service account:
    gcloud projects add-iam-policy-binding PROJECT_ID \
      --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" \
      --role="ROLE_NAME"

    Replace PROJECT_ID with your Google Cloud project ID.

  3. Optional: Assign roles to your service account to grant access to your Google Cloud project's resources in addition to Google Workspace resources. For more details, refer to Manage access to projects, folders, and organizations.
#### Create credentials for a service account You need to obtain credentials in the form of a public/private key pair. These credentials are used by your code to authorize service account actions within your app.
  1. In the Google Cloud Console, go to Menu menu > IAM & Admin > Service Accounts.

    Go to Service Accounts

    The remaining steps appear in the Google Cloud Console.

  2. Select a Google Cloud project.
  3. Click the email address of the service account that you want to create a key for.
  4. Click the Keys tab.
  5. Click the Add key drop-down menu, then select Create new key.
  6. Select JSON as the Key type and click Create.

    Your new public/private key pair is generated and downloaded to your machine as a service account key file. Save the downloaded JSON file as credentials.json in your working directory. This file is the only copy of this key. After you download the key file, you cannot download it again. For information about how to store your key securely, see Best practices for managing service account keys.

#### Set up domain-wide delegation for a service account Use domain-wide delegation when your application needs to access Google Workspace data on behalf of multiple individual users in your organization (such as sending emails using the Gmail API) without requiring individual user consent. To call APIs on behalf of users in a Google Workspace organization, grant your service account domain-wide delegation of authority in the Google Admin console using a Super Admin account. For more information, see Delegate domain-wide authority to the service account.
  1. In the Google Cloud Console, go to Menu menu > IAM & Admin > Service Accounts.

    Go to Service Accounts

  2. Select a Google Cloud project.
  3. Click the email address of the service account that you want to set up domain-wide delegation for.
  4. Click Show advanced settings.
  5. Under "Domain-wide delegation", find your service account's "Client ID."
  6. Click Copy content_copy to copy the client ID value to your clipboard.
  7. If you have Super Admin access to the relevant Google Workspace account, click View Google Workspace Admin Console, sign in with your super administrator user account, and continue following these steps.

    If you don't have super administrator access to the relevant Google Workspace account, contact a super administrator for the account. Send them your service account's client ID and a list of OAuth Scopes required by your app so they can complete the following steps in the Google Admin console.

    1. In the Google Admin console, go to Menu menu > Security > Access and data control > API controls.

      Go to API controls

    2. Click Manage Domain Wide Delegation.
    3. Click Add new.
    4. In the Client ID field, paste the client ID that you previously copied.
    5. In the OAuth Scopes field, enter a comma-delimited list of the scopes required by your app. This is the same set of scopes you defined when configuring the OAuth consent screen.
    6. Click Authorize.

      Changes can take up to 24 hours but typically happen more quickly. For more information, see Control API access with domain-wide delegation.

### Configure the OAuth consent screen If you're using a new Google Cloud project to complete this quickstart, configure the OAuth consent screen. If you've already completed this step for your Cloud project, skip to the next section.
  1. In the Google API Console, go to Menu menu > Google Auth platform > Branding.

    Go to Branding

  2. If you have already configured the Google Auth platform, you can configure the following OAuth Consent Screen settings in Branding, Audience, and Data Access. If you see a message that says Google Auth platform not configured yet, click Get Started:
    1. Under App Information, in App name, enter a name for the app.
    2. In User support email, choose a support email address where users can contact you if they have questions about their consent.
    3. Click Next.
    4. Under Audience, select Internal.
    5. Click Next.
    6. Under Contact Information, enter an Email address where you can be notified about any changes to your project.
    7. Click Next.
    8. Under Finish, review the Google API Services User Data Policy and if you agree, select I agree to the Google API Services: User Data Policy.
    9. Click Continue.
    10. Click Create.
  3. For now, you can skip adding scopes. In the future, when you create an app for use outside of your Google Workspace organization, you must change the User type to External. Then add the authorization scopes that your app requires. To learn more, see the full Configure OAuth consent guide.
### Authorize credentials for a desktop application To authenticate end users and access user data in your app, you need to create one or more OAuth 2.0 Client IDs. A client ID is used to identify a single app to Google's OAuth servers. If your app runs on multiple platforms, you must create a separate client ID for each platform. Caution: This quickstart must be run locally and with access to a browser. It doesn't work if run on a remote terminal such as Cloud Shell or over SSH.
  1. In the Google Cloud Console, go to Menu menu > Google Auth platform > Clients.

    Go to Clients

  2. Click Create Client.
  3. Click Application type > Desktop app.
  4. In the Name field, type a name for the credential. This name is only shown in the Google Cloud Console.
  5. Optional: If your app is an AI agent that takes actions on behalf of users, select Use this client for an AI-powered agent. If your app supports both AI agent workflows and standard user features, create separate OAuth clients for each. You can't change this setting after you create the client.
  6. Click Create.

    The newly created credential appears under "OAuth 2.0 Client IDs."

  7. Save the downloaded JSON file as credentials.json, and move the file to your working directory.
### Configure the Google Chat app Note: To perform read-only API calls with user authentication, such as `GetSpace` or `ListMessages`, you don't need to configure a Google Chat app. You only need to enable the API and create an OAuth client. To perform create, update, and delete Google Chat API calls, you must configure a Google Chat app. For any write requests, Google Chat attributes the Google Chat app in the UI using the following information. 1. In the Google API Console, go to the Chat API **Configuration** page: [Go to Chat API Configuration page](https://console.developers.google.com/apis/api/chat.googleapis.com/hangouts-chat) 1. Under **Application info**, enter the following information: 1. In the **App name** field, enter `Chat API quickstart app`. 1. In the **Avatar URL** field, enter `https://developers.google.com/chat/images/quickstart-app-avatar.png`. 1. In the **Description** field, enter `Quickstart for calling the Chat API`. 1. Under **Interactive features**, click the **Enable interactive features** toggle to the off position to disable interactive features for the Chat app. 1. Click **Save**. ## Install the client library + Install the libraries using npm:
    npm install googleapis@105 @google-cloud/local-auth@2.1.0 --save
    
## Set up the sample 1. In your working directory, create a file named `index.js`. 1. In the file, paste the following code: ## Run the sample 1. In your working directory, run the sample:
    node .
    
  1. The first time you run the sample, it prompts you to authorize access:
    1. If you're not already signed in to your Google Account, sign in when prompted. If you're signed in to multiple accounts, select one account to use for authorization.
    2. Click Accept.

    Your Nodejs application runs and calls the Google Chat API.

    Authorization information is stored in the file system, so the next time you run the sample code, you aren't prompted for authorization.

## Next steps * [Try the Google Workspace APIs in the APIs explorer](https://developers.google.com/workspace/explore.md.txt)