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

# 接口调用

> 通过 HTTP 调用已保存的 Function，传递参数并读取返回结果。

调用前，需要一个已保存的 Function、有效的 [Access Key](/zh/guides/openapi/authentication) 和可用的 OpenAPI 单位。可以先按[创建 Function](/zh/guides/functions/create)建立 `demo.usdc_amount`，在控制台用 `1500000` 测试并确认返回 `1.5`。

## 请求格式

```text theme={null}
POST https://openapi.chaintable.com/v1/function/{function_id}
```

| 部分                 | 内容                                   |
| ------------------ | ------------------------------------ |
| `function_id`      | 完整 Function ID，例如 `demo.usdc_amount` |
| `AccessKey` 请求头    | 所属账户的 Access Key                     |
| `Content-Type` 请求头 | `application/json`                   |
| `parameters`       | 按函数参数顺序排列的 JSON 数组；无参数时传 `[]`        |

```bash theme={null}
curl -X POST 'https://openapi.chaintable.com/v1/function/demo.usdc_amount' \
  -H "AccessKey: $CHAINTABLE_ACCESS_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"parameters": [1500000]}'
```

`parameters` 是位置参数列表，不是按参数名组织的对象。若 Function 定义为 `_(address, block_id)`，则依次传入地址和区块 ID。

## 读取结果

响应包含 `code`、`message` 和 `data`。上述请求成功时，HTTP 状态为 `200`，`code` 为 `success`，`data` 是函数本身的返回值：

```json theme={null}
{
  "code": "success",
  "message": "ok",
  "data": 1.5
}
```

在 Python 应用环境中安装 `requests`，然后检查 HTTP 状态和响应中的 `code`：

```python theme={null}
import os
import requests

response = requests.post(
    'https://openapi.chaintable.com/v1/function/demo.usdc_amount',
    headers={'AccessKey': os.environ['CHAINTABLE_ACCESS_KEY']},
    json={'parameters': [1500000]},
    timeout=10,
)
body = response.json()
if not response.ok or body['code'] != 'success':
    raise RuntimeError(f"{body['code']}: {body['message']}")
print(body['data'])
```

运行后输出 `1.5`。

## 调用其他 Function

替换路径中的完整 Function ID，并按定义调整 `parameters`。

完成[查询地址 ETH 余额](/zh/quickstart/use/query-wallet-eth-balance)后，可以从应用调用已保存的 `demo.wallet_eth_value`：

```bash theme={null}
curl -X POST 'https://openapi.chaintable.com/v1/function/demo.wallet_eth_value' \
  -H "AccessKey: $CHAINTABLE_ACCESS_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"parameters": ["0xd8da6bf26964af9d7eed9e03e53415d37aa96045"]}'
```

成功时，`data` 包含地址、ETH 余额、区块 ID、ETH 价格及美元价值。
