iMarioiMario
文档API 参考

指南

API 概览与快速上手认证沙盒与测试密钥API 错误分页幂等请求速率限制API 版本管理Webhook

接口

全部接口工作区人群合成人物调研报告资料库文件自主研究数据连接成员API 密钥Webhook 端点
接口

Webhook 端点

iMario 发送事件的目标端点、测试事件、签名密钥和投递记录。仅限所有者和管理员。

基础地址为 https://api.imario.ai/v1。每次调用所用的密钥都要带有各接口标明的权限范围,密钥的角色也要达到标明的要求(参见认证)。错误的格式见 API 错误。

列出 Webhook 端点

GET /v1/webhook-endpoints

权限范围 webhooks:read · 角色 所有者或管理员

与密钥模式(正式或测试)相同的端点,按时间倒序排列。webhook_endpoint 对象包含:id、livemode(测试密钥创建的端点是测试端点,只接收沙盒事件)、created_at、url、description、events(事件类型,["*"] 表示全部)、enabled、disabled_reason(delivery_failures 表示投递连续 3 天失败后被 iMario 自动关闭,disabled_by_user 表示被手动关闭,也可能为 null)。

参数

名称位置类型必填说明
limit查询参数integer否返回的对象个数(1 到 100)。默认值为 20。
cursor查询参数string否上一页返回的 next_cursor。最多 200 个字符。

示例

curl https://api.imario.ai/v1/webhook-endpoints \
  -H "Authorization: Bearer $IMARIO_API_KEY"

响应

返回一个列表:{"object": "list", "data": [...], "has_more": false, "next_cursor": null}。参见分页。

创建 Webhook 端点

POST /v1/webhook-endpoints

权限范围 webhooks:write · 角色 所有者或管理员

响应中带有 secret(whsec_...),只显示这一次:请妥善保存,用来验证 webhook-signature(遵循 Standard Webhooks 规范)。URL 必须是 https,并且只能解析到公网地址;每次投递时都会重新检查。webhook_endpoint 对象包含:id、livemode(测试密钥创建的端点是测试端点,只接收沙盒事件)、created_at、url、description、events(事件类型,["*"] 表示全部)、enabled、disabled_reason(delivery_failures 表示投递连续 3 天失败后被 iMario 自动关闭,disabled_by_user 表示被手动关闭,也可能为 null)。

请求体

字段类型必填说明
urlstring是一个公开的 https URL。不会跟随重定向。最多 2,048 个字符。
eventsstring[]是要接收的事件类型,["*"] 表示全部类型。最多 20 项。
descriptionstring否最多 200 个字符。

示例

curl https://api.imario.ai/v1/webhook-endpoints \
  -H "Authorization: Bearer $IMARIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/imario/webhooks",
    "events": ["study.completed", "study.failed", "report.completed"],
    "description": "Production receiver"
  }'

获取 Webhook 端点

GET /v1/webhook-endpoints/{endpoint_id}

权限范围 webhooks:read · 角色 所有者或管理员

webhook_endpoint 对象包含:id、livemode(测试密钥创建的端点是测试端点,只接收沙盒事件)、created_at、url、description、events(事件类型,["*"] 表示全部)、enabled、disabled_reason(delivery_failures 表示投递连续 3 天失败后被 iMario 自动关闭,disabled_by_user 表示被手动关闭,也可能为 null)。

示例

curl https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID \
  -H "Authorization: Bearer $IMARIO_API_KEY"

更新 Webhook 端点

PATCH /v1/webhook-endpoints/{endpoint_id}

权限范围 webhooks:write · 角色 所有者或管理员

只传要修改的字段。webhook_endpoint 对象包含:id、livemode(测试密钥创建的端点是测试端点,只接收沙盒事件)、created_at、url、description、events(事件类型,["*"] 表示全部)、enabled、disabled_reason(delivery_failures 表示投递连续 3 天失败后被 iMario 自动关闭,disabled_by_user 表示被手动关闭,也可能为 null)。

请求体

字段类型必填说明
urlstring否最多 2,048 个字符。
eventsstring[]否最多 20 项。
descriptionstring否最多 200 个字符。
enabledboolean否设为 false 时停止投递(并丢弃待投递的事件);设为 true 时重新开启端点。

示例

curl -X PATCH https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID \
  -H "Authorization: Bearer $IMARIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false
  }'

删除 Webhook 端点

DELETE /v1/webhook-endpoints/{endpoint_id}

权限范围 webhooks:write · 角色 所有者或管理员

等待投递到这个端点的事件会被丢弃。返回 {object, id, deleted: true}。

示例

curl -X DELETE https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID \
  -H "Authorization: Bearer $IMARIO_API_KEY"

发送测试事件

POST /v1/webhook-endpoints/{endpoint_id}/test

权限范围 webhooks:write · 角色 所有者或管理员

把一个只发给这个端点的 ping 事件加入投递队列(事件的 data.object 就是这个端点),并返回 webhook_delivery:id、endpoint_id、event_id、event_type、status(pending、delivered、failed)、attempts、last_status_code、last_error、created_at、delivered_at、next_attempt_at。

示例

curl -X POST https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID/test \
  -H "Authorization: Bearer $IMARIO_API_KEY"

轮换签名密钥

POST /v1/webhook-endpoints/{endpoint_id}/rotate-secret

权限范围 webhooks:write · 角色 所有者或管理员

返回新的 secret,只显示这一次。接下来 24 小时内,每次投递都带两个签名(分别用新、旧签名密钥生成),接收方可以从容切换,不会漏掉事件。webhook_endpoint 对象包含:id、livemode(测试密钥创建的端点是测试端点,只接收沙盒事件)、created_at、url、description、events(事件类型,["*"] 表示全部)、enabled、disabled_reason(delivery_failures 表示投递连续 3 天失败后被 iMario 自动关闭,disabled_by_user 表示被手动关闭,也可能为 null)。

示例

curl -X POST https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID/rotate-secret \
  -H "Authorization: Bearer $IMARIO_API_KEY"

列出端点的投递记录

GET /v1/webhook-endpoints/{endpoint_id}/deliveries

权限范围 webhooks:read · 角色 所有者或管理员

按时间倒序排列,保留 30 天。每个 webhook_delivery 包含:id、endpoint_id、event_id(即 webhook-id 请求头)、event_type、status(pending、delivered、failed)、attempts、last_status_code、last_error、created_at、delivered_at、next_attempt_at。投递失败后,会在 1 分钟、5 分钟、30 分钟、2 小时、6 小时和 12 小时后重试。

参数

名称位置类型必填说明
limit查询参数integer否返回的对象个数(1 到 100)。默认值为 20。
cursor查询参数string否上一页返回的 next_cursor。最多 200 个字符。

示例

curl https://api.imario.ai/v1/webhook-endpoints/ENDPOINT_ID/deliveries \
  -H "Authorization: Bearer $IMARIO_API_KEY"

响应

返回一个列表:{"object": "list", "data": [...], "has_more": false, "next_cursor": null}。参见分页。

← API 密钥

本页内容

列出 Webhook 端点创建 Webhook 端点获取 Webhook 端点更新 Webhook 端点删除 Webhook 端点发送测试事件轮换签名密钥列出端点的投递记录