Skip to main content

权限授予 Webhook 事件

每当客户的权限授予状态发生变化时,这些事件将触发,例如生成许可证密钥、分配 Discord 角色、提供下载链接或撤销访问。订阅这些事件以保持您的应用程序与每个客户的可访问性同步。 所有四个事件共享相同的 EntitlementGrantResponse 负载,如下模式所述。

事件触发器

entitlement_grant.created

授予行刚刚插入。从此时起,即使状态发生变化,授予始终具有稳定的 id。使用此事件记录履行正在进行中。 对于自动履行的 License Key,该行会直接插入,并填充 status: "Delivered"delivered_at,因此单个 created 事件之后不会再有其他状态变更,除非该 grant 随后被撤销。 对于手动履行的 License Key(包含 fulfillment_mode: manual 的 entitlement),该行到达时会包含 status: "Pending",但不包含 license_key 对象——此时还没有 License Key。此事件表示有一个 License Key 正在等待履行;请通过 POST /grants/{grant_id}/license-key 提供 License Key,随后系统会触发 entitlement_grant.delivered。请参阅手动履行 对于其他所有集成,该行到达时会包含 status: "Pending"。交付完成后会触发 deliveredfailed 事件:
  • 基于 OAuth 的集成(Discord、GitHub、Notion)会包含一个 oauth_url,客户必须访问该链接以完成授权同意。在客户完成授权之前,grant 会保持为 Pending
  • 平台直连集成(Telegram、Framer、Digital Files)只会在平台调用执行期间短暂处于 Pending,随后转换为 Delivered

entitlement_grant.delivered

grant 已从 Pending 转换为 Delivered。客户现在可以获得 entitlement 所描述的访问权限。使用此事件在自己的系统中解锁依赖功能,例如配置工作区、发送自定义欢迎邮件,或将 “fulfilled” 标记设为已完成。 payload 的 delivered_at 字段记录了交付完成的时间。对于创建时即处于 Delivered 的 grant,您会连续收到 createddelivered 事件。

entitlement_grant.failed

交付尝试失败且出现不可重试的错误。error_codeerror_message 字段解释了失败原因。常见原因包括撤销 OAuth 令牌、被拒绝的平台权限或缺少的目标(例如,已删除的 Discord 公会)。
entitlement_grant.failed 视为可操作的。顾客付款但未获得访问。向支持团队报告失败或在解决根本问题后触发重授权。

entitlement_grant.revoked

访问在平台层面被撤销:Discord 角色被移除,GitHub 协作者被移除,许可证密钥被禁用,不再提供文件下载网址。 revocation_reason 字段记录触发。

负载变体

data 字段始终是一个 EntitlementGrantResponse 对象。payload 包含一个 integration_type 字段(例如 license_keydigital_filesdiscord),因此您可以直接识别 grant 类型。三种集成类型还会附加额外的嵌套对象:
  • integration_typelicense_key 且已签发 License Key 时,会包含 license_key。其中包含生成的 License Key、到期时间和激活使用情况。对于仍处于 Pending 的手动履行 grant,在您履行该 grant 之前,此对象为 null
  • integration_typedigital_files 时,会包含 digital_product_delivery。其中包含预签名下载 URL、可选的 instructions 以及可选的 external_url
  • integration_typefeature_flag 时,会包含 feature。其中包含 grant 所授予能力的 feature_typefeature_id
对于其他所有集成类型(Discord、GitHub、Telegram、Figma、Framer、Notion),这些嵌套字段均为 null;相关配置记录在 entitlement 本身中,而不是 grant 中。

示例负载

许可证密钥已交付 (entitlement_grant.delivered)

许可证密钥等待手动获取 (entitlement_grant.created)

当客户购买的产品包含使用 fulfillment_mode: manual 的 License Key entitlement 时触发。此时 grant 为 Pending,尚无 license_key 对象——商户必须提供 License Key。

数字文件已交付 (entitlement_grant.delivered)

Discord 角色已创建并挂起 (entitlement_grant.created)

订阅取消时撤销授权 (entitlement_grant.revoked)

交付失败 (entitlement_grant.failed)


集成提示

  • 在解锁依赖功能之前,等待 entitlement_grant.delivered payment.succeeded 事件表示款项已结算,但不表示客户已经获得 GitHub 仓库或 Discord 角色。delivered 事件才是履行完成的事实来源。
  • revocation_reason 映射到留存流程。 subscription_on_hold 撤销通常表示客户的银行卡扣款失败,下一次续期时会重新授予访问权限。manualsubscription_cancelled 撤销则是有意执行的。请在客户沟通中区别对待。
  • 使用 grant 的 id 作为幂等键。 单个 grant 最多会发出一个 created 事件、一个终止事件(deliveredfailed),以及一个 revoked 事件。Webhook 系统的重新交付可能会重复事件;请根据 grant 的 idtype 进行去重。
  • 读取 integration_type 以识别 grant 类型。 payload 会直接携带 integration_type(例如 license_keydigital_filesdiscord)。相应的 grant 完成交付后,license_keydigital_product_delivery 嵌套对象会被填充;手动履行的 License Key grant 在您履行之前,会保持为 Pending,并带有 integration_type: "license_key" 以及一个为 nulllicense_key
  • 对于基于 OAuth 的 grant,向客户展示 oauth_url Discord、GitHub 或 Notion 订阅者流程中的 entitlement_grant.created 事件包含 oauth_urloauth_expires_at。请将其通过电子邮件发送给客户,或在您的应用中显示,以解除交付阻塞。

Detailed view of a single entitlement grant: who it's for, its lifecycle state, and any integration-specific delivery payload.

brand_id
string
必填

Brand id this grant belongs to.

business_id
string
必填

Identifier of the business that owns the grant.

created_at
string<date-time>
必填

Timestamp when the grant was created.

customer_id
string
必填

Identifier of the customer the grant was issued to.

entitlement_id
string
必填

Identifier of the entitlement this grant was issued from.

id
string
必填

Unique identifier of the grant.

integration_type
enum<string>
必填

The integration type of the grant's entitlement (e.g. license_key).

可用选项:
discord,
telegram,
github,
figma,
framer,
notion,
digital_files,
license_key,
feature_flag
metadata
Metadata · object
必填

Arbitrary key-value metadata recorded on the grant.

status
enum<string>
必填

Lifecycle status of the grant.

可用选项:
Pending,
Delivered,
Failed,
Revoked
updated_at
string<date-time>
必填

Timestamp when the grant was last modified.

delivered_at
string<date-time> | null

Timestamp when the grant transitioned to delivered, when applicable.

digital_product_delivery
null | Digital Product Delivery · object

Digital-product-delivery payload, present when the entitlement integration is digital_files.

error_code
string | null

Machine-readable code reported when delivery failed, when applicable.

error_message
string | null

Human-readable message reported when delivery failed, when applicable.

feature
null | object

Typed feature payload, present only when the entitlement integration is feature_flag; null for every other integration type.

license_key
null | object

License-key delivery payload, present when the entitlement integration is license_key.

oauth_expires_at
string<date-time> | null

Timestamp when oauth_url stops being valid, when applicable.

oauth_url
string | null

Customer-facing OAuth URL for OAuth-style integrations. Populated during the customer-portal accept flow; null until the customer completes that step, and on grants for non-OAuth integrations.

payment_id
string | null

Identifier of the payment that triggered this grant, when applicable.

revocation_reason
string | null

Reason recorded when the grant was revoked, when applicable.

revoked_at
string<date-time> | null

Timestamp when the grant transitioned to revoked, when applicable.

subscription_id
string | null

Identifier of the subscription that triggered this grant, when applicable.

最后修改于 2026年8月21日