我们将于 2024 年 7 月 31 日逐步淘汰 Google Business Messages。点击
此处了解详情。
OpenAPI
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
OpenAPI 是
REST API 描述规范使用
OpenAPI 规范 2.0,
您可以为 Business Messages 和 Business 创建 OpenAPI 文档
通信 API 来描述其结构。
这样一来,您将能够:
- 使用您的首选语言创建客户端库
- 创建服务器桩
- 使用 API 管理工具
OpenAPI 文档的基本结构
OpenAPI 文档介绍了 REST 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 文档
如需访问 OpenAPI 文档,您必须从 Google Cloud 获取 API 密钥
包含 Business Messages 和 Business Communications 的平台 (GCP) 项目
已启用 API。
请按照以下部分操作
- 创建 GCP 项目
- 创建 API 密钥
- 启用 Business Messages API 和 Business Communications API
完成上述步骤后,您就可以访问 OpenAPI 文档了。
创建 GCP 项目
如果您已有 GCP 项目,可以使用它来创建 API 密钥。
如需创建新的 GCP 项目,请执行以下操作:
- 转到管理资源
页面
- 在页面顶部的选择组织下拉列表中,
选择要为其创建项目的组织。
如果您是免费试用用户,请跳过此步骤。
- 点击创建项目。
- 在新建项目窗口中,输入项目名称,然后选择
结算账号(如果适用)。项目名称只能包含字母、数字、单个
引号、连字符、空格或感叹号,并且长度必须介于 4 到 30 个字符之间。
在位置部分,输入新项目的父级组织或文件夹。
点击创建。
创建 API 密钥
前往
“凭据”页面
GCP 控制台中
点击创建凭据,然后选择 API 密钥。
您新建的密钥将显示在已创建的 API 密钥对话框中。
复制密钥并妥善保管。如需详细了解 API 密钥,请参阅
API 密钥文档。
启用 Business Communications API 和 Business Messages API
如需在 GCP 项目中启用这些 API,请执行以下操作:
- 转到 API 和服务页面。
- 在选择项目下拉列表中,
项目启动 API。
- 点击启用 API 和服务。
- 在搜索 API 和服务字段中,输入 Business Messages。
- 选择 Business Messages API。
- 点击启用。
- 点击启用 API 和服务。
- 在搜索 API 和服务字段中,输入 Business Communications。
- 选择 Business Communications API。
- 点击启用。
现在,您的 API 密钥有权访问
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 密钥。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):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."]]