Google Business Messages 功能將於 2024 年 7 月 31 日終止服務。請按
這裡瞭解詳情。
OpenAPI
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
OpenAPI 是
說明 REST API 的規格使用
OpenAPI 規範 2.0,
您可以為 Business Messages 和 Business 建立 OpenAPI 文件
用於說明其結構的通訊 API
如此一來,您就能:
- 使用您偏好的語言建立用戶端程式庫
- 建立伺服器虛設常式
- 使用 API 管理工具
OpenAPI 文件的基本結構
OpenAPI 文件說明 REST API 的介面。本文件定義
API 的名稱和說明、API 中的個別端點 (路徑)
API、呼叫端的驗證方式等等。
請點選下方按鈕,查看基本結構的範例。
JSON
{
"swagger": "2.0",
"host": "businessmessages.googleapis.com",
"info": {
"title": "Business Messages API",
"description": "",
"version": "v1"
},
"paths": {
"/v1/conversations/{conversationsId}/messages": {
"post": {
"description": "Sends a message from an agent to a user.",
"parameters": [
{
"description": "Part of `parent`. Required. The conversation that contains the message. Resolves to \"conversations/{conversationId}\".",
"type": "string",
"in": "path",
"required": true,
"name": "conversationsId"
},
{
"description": "Optional. A flag to send the specified fallback text instead of other message content.",
"name": "forceFallback",
"type": "boolean",
"in": "query"
},
{
"name": "message",
"schema": {
"$ref": "#/definitions/BusinessMessagesMessage"
},
"in": "body",
"description": "Required. The content of a message."
}
],
"tags": [
"businessmessages"
],
"operationId": "CreateMessage",
"responses": {
"default": {
"schema": {
"$ref": "#/definitions/BusinessMessagesMessage"
},
"description": "Successful operation"
}
}
}
}
}
}
如要進一步瞭解 OpenAPI 文件的結構,請參閱
Swagger 網站。
如何存取 OpenAPI 文件
您必須具備 Google Cloud 的 API 金鑰,才能存取 OpenAPI 文件
具有 Business Messages 和 Business Communications 的平台 (GCP) 專案
API 已啟用。
請按照下方各節操作,
- 建立 GCP 專案
- 建立 API 金鑰
- 啟用 Business Messages API 和 Business Communications API
完成這些步驟後,您就可以存取 OpenAPI 文件。
建立 GCP 專案
如果您已經有 GCP 專案,可以用該專案建立 API 金鑰。
如要建立新的 GCP 專案,請按照下列步驟操作:
- 前往「管理資源」頁面。
管理頁面
- 在頁面頂端的「選取機構」下拉式清單中,
選取要建立專案的機構。
如果您是免費試用的使用者,請略過這個步驟。
- 按一下 [建立專案]。
- 在「New Project」視窗中輸入專案名稱,然後選取
帳單帳戶。專案名稱只能由英文字母、數字和單個英文字母組成
引號、連字號、空格或驚嘆號,長度必須介於 4 至 30 個字元之間。
在「位置」部分,輸入新專案的上層機構或資料夾。
按一下「建立」。
建立 API 金鑰
前往
「憑證」頁面
GCP 控制台開始
按一下 [建立憑證],然後選取 [API 金鑰]。
「API key created」(建立的 API 金鑰) 對話方塊會顯示您新建立的金鑰。
請複製您的金鑰並妥善保管。如要進一步瞭解 API 金鑰,請參閱
API 金鑰說明文件。
啟用 Business Communications API 和 Business Messages API
如要在 GCP 專案中啟用這些 API,請按照下列步驟操作:
- 前往 API 和 GCP 控制台中的「服務」頁面。
- 在「選取專案」下拉式清單中,選取
以及您要啟用 API 的 API 專案
- 點選「啟用 API 和服務」。
- 在「搜尋 API 和服務」欄位中輸入 Business Messages。
- 選取「Business Messages API」。
- 按一下「啟用」。
- 點選「啟用 API 和服務」。
- 在「搜尋 API 和服務」欄位中輸入 Business Communications。
- 選取「Business Communications API」。
- 按一下「啟用」。
現在您的 API 金鑰有權存取以下項目的 OpenAPI 文件:
Business Messages 和 Business Communications API。
存取 OpenAPI 文件
執行下列指令,存取 Business Messages API 的 OpenAPI 文件:
curl "https://businessmessages.googleapis.com/$discovery/swagger2?version=v1&key=API_KEY"
執行下列指令,存取 Business Communications API 的 OpenAPI 文件:
curl "https://businesscommunications.googleapis.com/$discovery/swagger2?version=v1&key=API_KEY"
然後將 API_KEY 替換成您的 API 金鑰。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eOpenAPI specification enables creation of descriptive documents for Business Messages and Business Communications APIs, facilitating client library and server stub development and API management tool usage.\u003c/p\u003e\n"],["\u003cp\u003eOpenAPI documents outline the structure of a REST API, including its name, endpoints, authentication methods, and other details.\u003c/p\u003e\n"],["\u003cp\u003eAccessing OpenAPI documents requires an API key from a Google Cloud Platform (GCP) project with the Business Messages and Business Communications APIs enabled.\u003c/p\u003e\n"],["\u003cp\u003eUsers need to create a GCP project, generate an API key, and enable both Business Messages and Business Communications APIs within the project for document access.\u003c/p\u003e\n"],["\u003cp\u003eOpenAPI documents for both APIs can be retrieved using specific curl commands with the user's API key.\u003c/p\u003e\n"]]],[],null,["# OpenAPI\n\n[OpenAPI](https://swagger.io/docs/specification/about/) is a\nspecification for describing REST APIs. Using\n[OpenAPI specification 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md),\nyou can create OpenAPI documents for the Business Messages and Business\nCommunications APIs to describe their structure.\n\nThis allows you to do the following:\n\n- Create client libraries in your preferred language\n- Create server stubs\n- Use API management tools\n\nBasic structure of an OpenAPI document\n--------------------------------------\n\nAn OpenAPI document describes the surface of a REST API. The document defines\nthe name and description of the API, the individual endpoints (paths) in the\nAPI, how the callers are authenticated, and more.\n\nClick below to see an example of this basic structure. \n\n#### JSON\n\n```mysql\n {\n \"swagger\": \"2.0\",\n \"host\": \"businessmessages.googleapis.com\",\n \"info\": {\n \"title\": \"Business Messages API\",\n \"description\": \"\",\n \"version\": \"v1\"\n },\n \"paths\": {\n \"/v1/conversations/{conversationsId}/messages\": {\n \"post\": {\n \"description\": \"Sends a message from an agent to a user.\",\n \"parameters\": [\n {\n \"description\": \"Part of `parent`. Required. The conversation that contains the message. Resolves to \\\"conversations/{conversationId}\\\".\",\n \"type\": \"string\",\n \"in\": \"path\",\n \"required\": true,\n \"name\": \"conversationsId\"\n },\n {\n \"description\": \"Optional. A flag to send the specified fallback text instead of other message content.\",\n \"name\": \"forceFallback\",\n \"type\": \"boolean\",\n \"in\": \"query\"\n },\n {\n \"name\": \"message\",\n \"schema\": {\n \"$ref\": \"#/definitions/BusinessMessagesMessage\"\n },\n \"in\": \"body\",\n \"description\": \"Required. The content of a message.\"\n }\n ],\n \"tags\": [\n \"businessmessages\"\n ],\n \"operationId\": \"CreateMessage\",\n \"responses\": {\n \"default\": {\n \"schema\": {\n \"$ref\": \"#/definitions/BusinessMessagesMessage\"\n },\n \"description\": \"Successful operation\"\n }\n }\n }\n }\n }\n }\n \n```\n\nTo learn more about the structure of an OpenAPI document, see the\n[Swagger website](https://swagger.io/docs/specification/2-0/basic-structure/).\n\nHow to access the OpenAPI documents\n-----------------------------------\n\nTo access the OpenAPI documents, you must have an API key from a Google Cloud\nPlatform (GCP) project with the Business Messages and Business Communications\nAPIs enabled.\n\nFollow the sections below to\n\n- create a GCP project\n- create an API key\n- enable the Business Messages API and Business Communications API\n\nWith these steps completed, you can [access the OpenAPI documents](#access_the_openapi_documents).\n\n### Create a GCP project\n\nIf you already have a GCP project, you can use it to [create an API key](#create_an_api_key).\n\nTo create a new GCP project, do the following:\n\n1. Navigate to the [Manage resources](https://console.cloud.google.com/cloud-resource-manager) page in the GCP console.\n2. In the **Select organization** drop-down list at the top of the page, select the organization that you want to create the project for. If you are a free-trial user, skip this step.\n3. Click **Create Project**.\n4. In the **New Project** window, enter a project name and select a billing account as applicable. A project name can contain only letters, numbers, single quotes, hyphens, spaces, or exclamation points, and must be between 4 and 30 characters.\n5. For **Location**, enter the parent organization or folder for the new project.\n\n6. Click **Create**.\n\n### Create an API key\n\n1. Navigate to the\n [Credentials page](https://console.cloud.google.com/apis/credentials)\n in the GCP console.\n\n2. Click **Create credentials** , then select **API key**.\n\n The **API key created** dialog box displays your newly created key.\n Copy your key and keep it secure. To learn more about API keys, see the\n [API key documentation](https://cloud.google.com/api-keys/docs).\n\n### Enable the Business Communications API and Business Messages API\n\nTo enable these APIs in your GCP project, do the following:\n\n1. Go to the [APIs \\& Services](https://console.cloud.google.com/apis) page in the GCP console.\n2. In the **Select project** drop-down list, select the project you want to enable the APIs for.\n3. Click **Enable APIs and Services**.\n4. In the **Search for APIs and Services** field, enter **Business Messages**.\n5. Select **Business Messages API**.\n6. Click **Enable**.\n7. Click **Enable APIs and Services**.\n8. In the **Search for APIs and Services** field, enter **Business Communications**.\n9. Select **Business Communications API**.\n10. Click **Enable**.\n\nNow your API key has permissions to access the OpenAPI documents for the\nBusiness Messages and Business Communications APIs.\n\n### Access the OpenAPI documents\n\nRun this command to access the OpenAPI document for the Business Messages API: \n\n```scdoc\ncurl \"https://businessmessages.googleapis.com/$discovery/swagger2?version=v1&key=API_KEY\"\n```\n\n\u003cbr /\u003e\n\nRun this command to access the OpenAPI document for the Business Communications API: \n\n```scdoc\ncurl \"https://businesscommunications.googleapis.com/$discovery/swagger2?version=v1&key=API_KEY\"\n```\n\n\u003cbr /\u003e\n\nReplace the \u003cvar translate=\"no\"\u003eAPI_KEY\u003c/var\u003e with your API key."]]