Webhook配置

API使用webhook配置资源将事件发送到您的webhook接收器。
组织可以具有默认webook配置,该配置由该组织内的所有未指定其自己的webhook配置的密钥使用。
属性
名称 | 类型 | 描述 |
---|---|---|
id | webhook配置ID | 资源标识符。 |
resource | 字符串,总是webhook_config | 资源类型说明符。 |
organisation | 组织ID | 资源所属的组织。 |
url | 串 | 发送事件时要定位的网址。 |
secret | 串 | 用于验证事件签名的共享密钥。 |
state | 串 | 其中之一: new , valid , invalid , deactivated 。 |
date_created | 约会时间 | 资源创建时。 |
秘密
创建webhook配置后,将生成一个秘密,用于签署API发送的事件。强烈建议您使用此秘密实现webhook接收器以验证传入事件的签名。有关签名验证过程的更多详细信息,请参阅webhook配置文档 。
状态
-
new
刚刚创建或最近更新,但尚未测试。 -
valid
已通过验证并可以使用。组织必须至少具有一个处于此状态的webhook配置才能使用。 -
invalid
验证测试失败。必须更新或重新测试。 -
deactivated
已由所属组织关闭。
创建POST /configs/webhook
此操作将创建webhook_config.test
任务以验证端点详细信息。如果尚未设置webhook接收器,则此测试可能会失败并将配置设置为invalid
状态。但是,始终可以使用测试操作重新测试配置。
参数
名称 | 类型 | 描述 |
---|---|---|
url | 需要 | 您的webhook接收器的URL。 |
使用cURL
curl https://ricloud-api.reincubate.com/configs/webhook \ -X POST \ -H 'Authorization: Token <your key_token>' \ -H 'Content-Type: application/json' \ -d '{ "url": "https://www.mywebhook.com/webhooks/" }'
使用ricloud-py
import ricloud webhook_config = ricloud.WebhookConfig.create(url='https://www.mywebhook.com/webhooks/')
检索GET /configs/webhook/{webhook_config ID}
使用cURL
curl https://ricloud-api.reincubate.com/configs/webhook/<webhook_config ID> \ -H 'Authorization: Token <your key_token>'
使用ricloud-py
import ricloud webhook_config = ricloud.WebhookConfig.retrieve(<webhook_config ID>)
列出GET /configs/webhook
处于deactivated
状态的Webhook配置默认隐藏,只能通过显式过滤列出。
参数
名称 | 类型 | 描述 |
---|---|---|
state | 串 | 按状态过滤webhook配置。 |
date_created | 日期时间过滤器 | 按资源创建日期过滤。 |
更新POST /configs/webhook/{webhook_config ID}
此操作将在后台创建webhook_confg.test
任务,以验证对配置所做的任何更改。
在您基本上停用配置的情况下,只能将state
属性更改为deactivated
。
参数
名称 | 类型 | 描述 |
---|---|---|
url | 串 | 更新URL。 |
state | 串 | 仅限new 或deactivated 。 |
使用cURL
curl https://ricloud-api.reincubate.com/configs/webhook/<webhook_config ID> \ -X POST \ -H 'Authorization: Token <your key_token>' \ -H 'Content-Type: application/json' \ -d '{ "url": "https://www.myupdatedwebhook.com/webhooks/", }'
使用ricloud-py
import ricloud webhook_config = ricloud.WebhookConfig.update_with_id( <webhook_config ID>, url='https://www.myupdatedwebhook.com/webhooks/' ) # OR webhook_config = ricloud.WebhookConfig.retrieve(<webhook_config ID>) webhook_config.update(url='https://www.myupdatedwebhook.com/webhooks/')
测试POST /configs/webhook/{webhook_config ID}/test
此操作将创建webhook_config.test
任务,该任务使用指定的配置发送测试事件。测试结果将相应地更新webook配置的state
属性。
使用cURL
curl https://ricloud-api.reincubate.com/configs/webhook/<webhook_config ID>/test \ -H 'Authorization: Token <your key_token>'
使用ricloud-py
import ricloud test_task = ricloud.WebhookConfig.test_with_id(<webhook_config ID>) # OR webhook_config = ricloud.WebhookConfig.retrieve(<webhook_config ID>) test_task = webhook_config.test()