> ## Documentation Index
> Fetch the complete documentation index at: https://cobo.com/payments/llms.txt
> Use this file to discover all available pages before exploring further.

# 发送您的第一个 API 请求

本指南介绍如何使用 Payments API。阅读本指南后，您将能够成功调用一个 API 操作，并接收响应。

## 开始之前

如果您选择使用 Payments API SDK 而不是手动编写 API 请求，则需要先安装相应编程语言的正确版本。例如，如果您想使用 [Python SDK](/payments/cn/developer-tools/quickstart-python)，则需要安装 Python 3.7 或更新版本。

## 设置账户

按照[开发环境前置准备](/payments/cn/guides/preparation)中的说明设置您的 Cobo 账户并创建您的团队。如果团队已经创建，请让您的团队管理员邀请您加入团队。

<Note>本指南的所有示例都使用开发环境。请在开发环境 [https://portal.dev.cobo.com/](https://portal.dev.cobo.com/) 中创建您的团队。</Note>

## 生成 API Key 和 API Secret

生成一对 Ed25519 密钥对作为 API Key 和 API Secret。本指南以 OpenSSL 为例。要了解有关生成密钥对的其他方法，请参阅[生成 API Key 和 API Secret](/payments/cn/developer-tools/cobo-auth#generate-an-api-key-and-an-api-secret)。

1. 在终端窗口中，运行以下 OpenSSL 命令：

```shell theme={null}
# Generate a private key and save it in the `private.key.pem` file.
openssl genpkey -algorithm ed25519 -out private_key.pem

# Extract the public key from the private key and save it in the `public.key.pem` file.
openssl pkey -in private_key.pem -pubout -out public_key.pem
```

私钥保存在 `private.key.pem` 文件中，公钥保存在 `public.key.pem` 文件中。

2. 您可以通过运行以下命令打印密钥：

```shell theme={null}
# Export the private key in hexadecimal format.
openssl pkey -in private_key.pem -text | grep 'priv:' -A 3 | tail -n +2 | tr -d ':\n '

# Export the public key in hexadecimal format.
openssl pkey -pubin -in public_key.pem -text | grep 'pub:' -A 3 | tail -n +2 | tr -d ':\n '
```

## 注册 API Key

在 Cobo Portal 上注册您的 API Key 并配置相关权限。

1. 登录 [Cobo Portal](https://portal.dev.cobo.com/login)（开发环境）。
2. 在左侧导航菜单中，点击 **开发者** > **API Keys**。
3. 点击 **注册 API Key**。
4. 输入 API Key 名称（最多 30 个字符）。
5. 输入您在上一步中生成的公钥。
6. 选择用户角色和钱包范围。用户角色用于确定 API Key 可以进行的操作，钱包范围用于确定 API Key 可以控制的钱包。
7. 将 **Callback Endpoint** 字段留空（无需填写）。
8. 选择**临时**作为**密钥类型**。<Note>如果您已经有静态 IP 地址，您可以将密钥类型设置为**长期**，并在**IP 白名单**中输入您的 IP 地址。</Note>
9. 点击**注册**。
10. 通知您的团队管理员在 Cobo Guard 上批准请求。
    <Note>默认情况下，需要至少一半的管理员批准才能成功注册 API Key。</Note>

只有在 API Key 状态变为**活跃中**后，您才能开始使用它。

## 为您的请求添加身份认证信息

<Note>如果您选择[使用 Payments API SDK](/payments/cn/developer-tools/quickstart-python)，则可以跳过此步骤，因为 SDK 封装了认证机制。</Note>

在发送 API 请求时，您需要在请求头中包含 API Key、随机数和 API 签名，以作为身份认证信息。有关更多信息，请参阅 [Cobo Auth](/payments/cn/developer-tools/cobo-auth)。

```
headers = {
  "Biz-Api-Key": {YOUR_API_KEY}.hex(),
  "Biz-Api-Nonce": {Nonce},
  "Biz-Api-Signature": {YOUR_API_SIGNATURE}.hex(),
}
```

* Biz-Api-Key：API Key。要了解如何生成 API Key，请参阅[生成 API Key 和 API Secret](/payments/cn/developer-tools/cobo-auth#generate-an-api-key-and-an-api-secret)。
* Biz-Api-Nonce：随机数是 Unix 时间戳格式的当前时间，以毫秒为单位。
* Biz-Api-Signature：API 签名。要了解如何计算 API 签名，请参阅[计算 API 签名](/payments/cn/developer-tools/cobo-auth#calculate-the-api-signature)。
