--- title: "从 GraphQL Playground 连接到 Cato API" slug: "connecting-to-the-cato-api-from-the-graphql-playground" updated: 2026-07-30T03:23:28Z published: 2026-07-30T03:23:28Z canonical: "knowledge.catonetworks.com/connecting-to-the-cato-api-from-the-graphql-playground" --- > ## Documentation Index > Fetch the complete documentation index at: https://knowledge.catonetworks.com/llms.txt > Use this file to discover all available pages before exploring further. # 从 GraphQL Playground 连接到 Cato API 本文解释了如何使用 GraphQL Playground 运行一些示例查询并测试与 Cato Networks API 端点的连接。 ## GraphQL Playground 概述 GraphQL Playground 允许您运行直接发送到 Cato API 服务器的 API 查询。 第三方 API 查询软件,如 Altair 或 Postman,为运行 API 调用提供强大的功能。 但是,如果 API 查询存在连接问题,您可以使用 Playground 帮助识别问题的原因。 ### Prerequisites 要从 GraphQL Playground 运行 Cato API 查询,您必须拥有账户 API 密钥 (**资源 > API 密钥**)。 有关 API 密钥的更多信息,请参阅[为 Cato API 生成 API 密钥](/v1/docs/generating-api-keys-for-the-cato-api)。 您需要在示例查询中输入您的账户 Cato 管理应用程序 (CMA) ID。 您可以在[账户信息页面](/v1/docs/viewing-the-account-info)找到 CMA ID。 API 端点的 URL 特定于托管 Cato 管理应用程序 (CMA) 实例的位置。 可以有一个 值附加到您的 CMA 账户和 API 端点的 URL。 - 如果没有前缀(例如 `cc.catonetworks.com`),则使用以下 URL:`https://api.catonetworks.com/api/v1/graphql2` - 如果有前缀(例如 `cc.us1.catonetworks.com`),则应使用以下 URL:`https://api.us1.catonetworks.com/api/v1/graphql2` ## 通过示例 Cato API 查询测试连接性 您可以运行示例 API 查询来测试与 Cato API 服务器的连接。 当正确配置 `accountID` 参数和 API 密钥时,示例 API 查询返回账户数据并在 GraphQL Playground 中显示结果。 如果查询未返回您的账户结果,则可能是连接到 API 服务器有问题或服务器已停止。 以下示例 API 查询可以帮助您测试与 Cato API 服务器的连接: - [accountMetrics](https://support.catonetworks.com/hc/article_attachments/360013398157) - [accountSnapshot](https://support.catonetworks.com/hc/article_attachments/360013489978) ## 在 GraphQL Playground 中运行示例 API 查询 使用互联网浏览器打开 Cato API 的 GraphQL Playground。 使用您的 API 密钥配置 Playground 的 HTTP 头。 将示例查询粘贴到左侧窗格并输入您的账户 ID。 然后,您可以运行查询并在 Playground 中查看结果。 1. 从本文下载一个示例 API 查询并在诸如 Notepad 的文本编辑器中打开文件。 2. 从互联网浏览器转到 Cato API 的 GraphQL Playground。 3. 在左侧窗格的底部,点击 **HTTP 头**。 4. 以此格式输入您的 API 密钥: `{ "x-api-key" :"<api key>" }`。 下方截图显示了使用 API 密钥和**AaBbCcDdEeFf0123456789ABCDEF1234**配置的 HTTP 头: ![graphql1.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/24809308787229.png?sv=2026-02-06&spr=https&st=2026-11-19T06%3A43%3A47Z&se=2026-11-19T07%3A43%3A47Z&sr=b&sp=r&sig=T%2FPP9XYlJi5pJRE6QmbJChNUiRXVTVFSKMcXCNlepc0%3D) 5. 将一个示例查询复制并粘贴到 Playground 的左侧窗格。 6. 在查询顶部的 `accountID` 参数中输入您的账户 ID。 下方截图显示配置 `accountID` 参数的值为 2626: ![graphql2.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/24809288265885.png?sv=2026-02-06&spr=https&st=2026-11-19T06%3A43%3A47Z&se=2026-11-19T07%3A43%3A47Z&sr=b&sp=r&sig=%2BJw0hayju%2BzKovkjsFKO3G06z8puRITN1jiLR13k%2BfE%3D) 7. 点击播放按钮。 8. 右侧窗格显示了 API 查询的结果。 下方截图展示了为账户 ID 2626 提供的 accountMetrics 示例查询结果: ![graphql3.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/24809302891165.png?sv=2026-02-06&spr=https&st=2026-11-19T06%3A43%3A47Z&se=2026-11-19T07%3A43%3A47Z&sr=b&sp=r&sig=%2FlvBl8cVF8uBAbNirOld3kU2VDQUWZ%2BunXcAkuDl4qc%3D)