开发者
使用 API Key

介绍

您可以通过任何语言发送 HTTP 请求,与我们的 GraphQL API / REST API 进行交互。在使用之前,您需要在 Dashboard (opens in a new tab) 中创建一个 API Key。

创建 API Key

Dashboard (opens in a new tab) 中,点击右侧下拉菜单的 Settings,然后点击 左侧边栏 Developer , 即可看到开发者选项。

Developer Panel

找到 API Key 区域,点击 Generate New Token 按钮即可生成一个 API Key。

Generate API Key

点击 View 按钮即可查看 API Key。

View API Key

点击 Copy 按钮即可复制 API Key。

Copy API Key

使用 API Key

验证

Zeabur API 可以选择使用 API Key 进行身份验证。保证您已经生成了有效的 API Key。

所有 API 请求都应在 Authorization HTTP 头部中包含您的 API Key ,如下所示:

Authorization: Bearer ZEABUR_API_KEY

发出 REST API 请求

您可以使用任何 HTTP 客户端库或者在您的应用中来发出请求。下面是示例:

您可以将以下命令粘贴到终端中以运行您的第一个 REST API 请求。确保将 $ZEABUR_API_KEY 替换为您的 API Key:

curl https://gateway.zeabur.com/api/v1/users/me \
  -H "Authorization: Bearer $ZEABUR_API_KEY" \
  -H "Content-Type: application/json" \

此处查询当前用户的信息。您应该收到类似于以下内容的响应。

{
    "_id": "64ffffffffffffffffff",
    "name": "Zeabur Zebra",
    "email": "zebra@zeabur.com",
    "username": "zeabra",
    "language": "en-US",
    "githubID": 5000000,
    "avatarUrl": "https://avatars.githubusercontent.com/u/5000000?v=4",
    "createdAt": "2023-08-31T08:14:08.873Z",
    "bannedAt": null,
    "bannedReason": null,
    "emailPreference": {
        "buildFailed": true,
        "deploymentCrashed": true
    },
    "agreedAt": "2023-08-31T08:14:17.028Z",
    "referralCode": "zeabra",
    "discordID": "7000000000000000000",
    "customerID": "cus_xxxxxxxxxxxxxx"
}

现在您已经成功地使用 API Key 进行了身份验证,您可以使用 API Key 来访问其他 REST API 了。

GrapQL API 的访问方式与上述相同,只是请求方式不同。您可以在 GraphQL Playground (opens in a new tab) 中尝试 GraphQL API。