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

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# 创建 Webhook

> 创建处于活跃状态的 webhook，并订阅您选择的事件

创建处于 `ACTIVE` 状态的 webhook，使其立即开始接收通知。请发送目标地址 `url`、在账户内唯一的 `name`，以及至少一个 [触发器](https://docs.y.uno/zh-hans/reference/webhooks.md#triggers)。响应包含 `id`，您可使用它来 [检索](https://docs.y.uno/zh-hans/reference/webhooks/retrieve-webhook.md)、[更新](https://docs.y.uno/zh-hans/reference/webhooks/update-webhook.md) 和 [删除](https://docs.y.uno/zh-hans/reference/webhooks/delete-webhook.md) 该 webhook。

为保护 Yuno 调用您 endpoint 的方式，请在同一请求体中添加任一 [投递认证](https://docs.y.uno/zh-hans/reference/webhooks.md#delivery-authentication) 方式的字段。这些字段均为可选，并且可以组合使用。您配置的密钥会以掩码形式返回，其余字段返回 `null`。

> [!NOTE]
>
> 如需设置 `oauth2_scope`，请使用 [更新 Webhook](https://docs.y.uno/zh-hans/reference/webhooks/update-webhook.md)。

一个账户可以有多个指向同一 `url` 的 webhook，只要它们监听不同的事件即可。如果账户中已有同一 `name` 的 webhook，或已有同一 `url` 且监听至少一个相同事件的 webhook，则创建会以 `409 WEBHOOK_ALREADY_EXISTS` 被驳回。


## OpenAPI

````yaml openapi/zh-hans/webhooks/manage-webhooks.json POST /webhooks
openapi: 3.1.0
info:
  title: webhooks-manage-webhooks
  version: 1.0.0
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
security:
  - sec0: []
    sec1: []
paths:
  /webhooks:
    post:
      summary: 创建 Webhook
      description: 创建一个处于启用状态的 webhook，订阅您所选择的事件。它至少需要一个触发器，并且会立即开始接收通知。
      operationId: create-webhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WebhookCreateInput'
            example:
              account_id: 493e9374-510a-4201-9e09-de669d75f256
              name: Production payments listener
              url: https://api.acme.com/yuno/webhooks
              api_key: my-webhook-key
              secret: my-webhook-secret
              hmac_client_secret: my-hmac-secret
              enrollment_triggers:
                - ENROLL
                - UNENROLL
              payment_triggers:
                - AUTHORIZE
                - CAPTURE
                - REFUND
              subscription_triggers:
                - CREATE
                - CLOSE_TO_RENEWAL
              renewal_days: 5
      responses:
        '201':
          description: 您创建的 webhook。您配置的密钥信息会以掩码形式返回，您未提供的则返回 null。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Webhook'
              example:
                id: '12345'
                account_id: 493e9374-510a-4201-9e09-de669d75f256
                name: Production payments listener
                state: ACTIVE
                url: https://api.acme.com/yuno/webhooks
                api_key: '***'
                secret: '***'
                hmac_client_secret: '***'
                oauth2_authentication_url: null
                oauth2_client_secret: null
                oauth2_client_id: null
                oauth2_grant_type: null
                oauth2_scope: null
                oauth2_authorization_name: null
                oauth2_include_client_id: false
                enrollment_triggers:
                  - ENROLL
                  - UNENROLL
                payment_triggers:
                  - AUTHORIZE
                  - CAPTURE
                  - REFUND
                report_triggers: []
                subscription_triggers:
                  - CREATE
                  - CLOSE_TO_RENEWAL
                onboarding_triggers: []
                renewal_days: 5
                created_at: '2026-07-09T13:05:36.482913Z'
                updated_at: '2026-07-09T13:05:36.482913Z'
        '400':
          $ref: '#/components/responses/InvalidCreateRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          $ref: '#/components/responses/WebhookConflict'
        '502':
          $ref: '#/components/responses/UpstreamError'
components:
  schemas:
    WebhookCreateInput:
      type: object
      required:
        - account_id
        - name
        - url
      properties:
        account_id:
          type: string
          format: uuid
          description: webhook 所属账户的唯一标识符。
          example: 493e9374-510a-4201-9e09-de669d75f256
        name:
          type: string
          description: 您为 webhook 起的名称。在账户内必须唯一。
          example: Production payments listener
        url:
          type: string
          description: Yuno 发送通知的目标 endpoint。必须是解析到公共、可路由地址的 `http` 或 `https` URL。
          example: https://api.acme.com/yuno/webhooks
        api_key:
          type: string
          description: 每次投递时，作为 `x-api-key` 标头发送到您的 endpoint。
          example: my-webhook-key
        secret:
          type: string
          description: 每次投递时，作为 `x-secret` 标头发送到您的 endpoint。
          example: my-webhook-secret
        hmac_client_secret:
          type: string
          description: Yuno 用于对 payload 签名的密钥。签名通过 `x-hmac-signature` 标头传递。
          example: my-hmac-secret
        oauth2_authentication_url:
          type: string
          description: >-
            您的令牌 endpoint。必须使用 HTTPS。请将
            `oauth2_authentication_url`、`oauth2_client_id`、`oauth2_client_secret`
            和 `oauth2_grant_type` 一起发送。
          example: https://api.acme.com/oauth/token
        oauth2_client_id:
          type: string
          description: >-
            Yuno 用于身份验证的客户端标识符。请将
            `oauth2_authentication_url`、`oauth2_client_id`、`oauth2_client_secret`
            和 `oauth2_grant_type` 一起发送。
          example: acme_client_id
        oauth2_client_secret:
          type: string
          description: >-
            Yuno 用于身份验证的客户端密钥。请将
            `oauth2_authentication_url`、`oauth2_client_id`、`oauth2_client_secret`
            和 `oauth2_grant_type` 一起发送。
          example: acme_client_secret
        oauth2_grant_type:
          type: string
          description: >-
            Yuno 请求令牌时使用的授权类型。请将
            `oauth2_authentication_url`、`oauth2_client_id`、`oauth2_client_secret`
            和 `oauth2_grant_type` 一起发送。
          example: client_credentials
        oauth2_authorization_name:
          type: string
          description: Yuno 发送令牌所使用的标头。默认为 `Authorization`。
          example: Authorization
        oauth2_include_client_id:
          type: boolean
          description: 同时在令牌请求中，将客户端标识符作为标头发送。
          example: false
        enrollment_triggers:
          type: array
          description: webhook 订阅的注册事件。
          items:
            type: string
            enum:
              - ENROLL
              - UNENROLL
          example:
            - ENROLL
            - UNENROLL
        payment_triggers:
          type: array
          description: webhook 订阅的支付事件。
          items:
            type: string
            enum:
              - AUTHORIZE
              - CANCEL
              - CAPTURE
              - CHARGEBACK
              - PRECHARGEBACK
              - PURCHASE
              - REFUND
              - SPLIT_UPDATE
              - VERIFY
          example:
            - AUTHORIZE
            - CAPTURE
            - REFUND
        report_triggers:
          type: array
          description: webhook 订阅的报告事件。
          items:
            type: string
            enum:
              - CREATE
              - UPDATE
          example:
            - UPDATE
        subscription_triggers:
          type: array
          description: webhook 订阅的订阅事件。
          items:
            type: string
            enum:
              - ACTIVE
              - CANCEL
              - CLOSE_TO_RENEWAL
              - COMPLETE
              - CREATE
              - CREATION_FAILED
              - PAUSE
              - PLAN_CHANGE_CANCELED
              - PLAN_CHANGE_SCHEDULED
              - PLAN_CHANGED
              - PROMOTION_APPLIED
              - RESUME
          example:
            - CREATE
            - CLOSE_TO_RENEWAL
        onboarding_triggers:
          type: array
          description: webhook 订阅的 onboarding 事件。
          items:
            type: string
            enum:
              - BLOCKED
              - CANCELLED
              - CREATED
              - DECLINED
              - ERROR
              - EXPIRED
              - INACTIVE
              - PENDING
              - SUCCEEDED
              - TRANSFERRED
              - UNBLOCKED
          example:
            - CREATED
            - SUCCEEDED
        renewal_days:
          type: integer
          description: >-
            Yuno 在续订前多少天发送 `CLOSE_TO_RENEWAL` 通知。必须为 1 或更大，并且仅当
            `subscription_triggers` 包含 `CLOSE_TO_RENEWAL` 时有效。
          example: 5
    Webhook:
      type: object
      properties:
        id:
          type: string
          description: webhook 的唯一标识符。
          example: '12345'
        account_id:
          type: string
          format: uuid
          description: webhook 所属账户的唯一标识符。
          example: 493e9374-510a-4201-9e09-de669d75f256
        name:
          type: string
          description: 您为 webhook 起的名称。
          example: Production payments listener
        state:
          type: string
          description: '`ACTIVE` 的 webhook 会接收通知，`INACTIVE` 的不会。webhook 创建时为 `ACTIVE`。'
          enum:
            - ACTIVE
            - INACTIVE
          example: ACTIVE
        url:
          type: string
          description: Yuno 发送通知的目标 endpoint。
          example: https://api.acme.com/yuno/webhooks
        api_key:
          type:
            - string
            - 'null'
          description: 以 `***` 掩码显示；如果您尚未配置，则为 `null`。
          example: '***'
        secret:
          type:
            - string
            - 'null'
          description: 以 `***` 掩码显示；如果您尚未配置，则为 `null`。
          example: '***'
        hmac_client_secret:
          type:
            - string
            - 'null'
          description: 以 `***` 掩码显示；如果您尚未配置，则为 `null`。
          example: '***'
        oauth2_authentication_url:
          type:
            - string
            - 'null'
          description: 您的令牌 endpoint。
          example: https://api.acme.com/oauth/token
        oauth2_client_secret:
          type:
            - string
            - 'null'
          description: 以 `***` 掩码显示；如果您尚未配置，则为 `null`。
          example: '***'
        oauth2_client_id:
          type:
            - string
            - 'null'
          description: Yuno 用于身份验证的客户端标识符。
          example: acme_client_id
        oauth2_grant_type:
          type:
            - string
            - 'null'
          description: Yuno 请求令牌时使用的授权类型。
          example: client_credentials
        oauth2_scope:
          type:
            - string
            - 'null'
          description: 请求令牌时使用的范围。
          example: webhooks:write
        oauth2_authorization_name:
          type:
            - string
            - 'null'
          description: Yuno 发送令牌所使用的标头。
          example: Authorization
        oauth2_include_client_id:
          type: boolean
          description: Yuno 是否同时在令牌请求中将客户端标识符作为标头发送。
          example: true
        enrollment_triggers:
          type:
            - array
            - 'null'
          description: webhook 订阅的注册事件。
          items:
            type: string
          example:
            - ENROLL
            - UNENROLL
        payment_triggers:
          type:
            - array
            - 'null'
          description: webhook 订阅的支付事件。
          items:
            type: string
          example:
            - AUTHORIZE
            - CAPTURE
            - REFUND
        report_triggers:
          type:
            - array
            - 'null'
          description: webhook 订阅的报告事件。
          items:
            type: string
          example:
            - UPDATE
        subscription_triggers:
          type:
            - array
            - 'null'
          description: webhook 订阅的订阅事件。
          items:
            type: string
          example:
            - CREATE
            - CLOSE_TO_RENEWAL
        onboarding_triggers:
          type:
            - array
            - 'null'
          description: webhook 订阅的 onboarding 事件。
          items:
            type: string
          example:
            - CREATED
            - SUCCEEDED
        renewal_days:
          type:
            - integer
            - 'null'
          description: Yuno 在续订前多少天发送 `CLOSE_TO_RENEWAL` 通知。
          example: 5
        created_at:
          type: string
          description: webhook 的创建日期和时间，采用 ISO 8601。
          example: '2026-07-09T13:05:36.482913Z'
          format: date-time
        updated_at:
          type: string
          description: webhook 的最近更新日期和时间，采用 ISO 8601。在您首次更新 webhook 之前，它与 `created_at` 相同。
          example: '2026-07-11T16:20:44.918330Z'
          format: date-time
    WebhookWriteRequestError:
      type: object
      properties:
        code:
          type: string
          description: 机器可读的错误代码。
          enum:
            - WEBHOOK_INVALID_REQUEST
            - INVALID_ACCOUNT_ID
            - WEBHOOK_INVALID_TRIGGER
            - WEBHOOK_INVALID_OAUTH2
            - WEBHOOK_INVALID_RENEWAL_DAYS
            - WEBHOOK_URL_UNSAFE
        messages:
          type: array
          description: 错误的可读描述。
          items:
            type: string
    WebhookAuthError:
      type: object
      properties:
        code:
          type: string
          description: 机器可读的错误代码。
          enum:
            - NOT_AUTHENTICATED
            - INVALID_CREDENTIALS
        messages:
          type: array
          description: 错误的可读描述。
          items:
            type: string
    WebhookConflictError:
      type: object
      properties:
        code:
          type: string
          description: 机器可读的错误代码。
          enum:
            - WEBHOOK_ALREADY_EXISTS
        messages:
          type: array
          description: 错误的可读描述。
          items:
            type: string
    WebhookUpstreamError:
      type: object
      properties:
        code:
          type: string
          description: 机器可读的错误代码。
          enum:
            - WEBHOOK_UPSTREAM_ERROR
        messages:
          type: array
          description: 错误的可读描述。
          items:
            type: string
  responses:
    InvalidCreateRequest:
      description: 请求无效。`code` 会告诉您违反了哪条规则。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WebhookWriteRequestError'
          examples:
            Missing required field:
              value:
                code: WEBHOOK_INVALID_REQUEST
                messages:
                  - account_id, name and url are required.
            No triggers:
              value:
                code: WEBHOOK_INVALID_REQUEST
                messages:
                  - at least one trigger is required.
            Invalid trigger:
              value:
                code: WEBHOOK_INVALID_TRIGGER
                messages:
                  - One or more webhook triggers are invalid.
            Incomplete OAuth2:
              value:
                code: WEBHOOK_INVALID_OAUTH2
                messages:
                  - OAuth2 configuration is incomplete or inconsistent.
            Invalid renewal_days:
              value:
                code: WEBHOOK_INVALID_RENEWAL_DAYS
                messages:
                  - >-
                    renewal_days is only valid when subscription_triggers
                    contains CLOSE_TO_RENEWAL
            Invalid account_id:
              value:
                code: INVALID_ACCOUNT_ID
                messages:
                  - Account id is invalid
            Unsafe url:
              value:
                code: WEBHOOK_URL_UNSAFE
                messages:
                  - >-
                    The webhook url is not allowed; it must resolve to a public,
                    routable address.
    Unauthorized:
      description: 您的 API 凭证缺失或无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WebhookAuthError'
          examples:
            Not authenticated:
              value:
                code: NOT_AUTHENTICATED
                messages:
                  - Not authenticated
            Invalid credentials:
              value:
                code: INVALID_CREDENTIALS
                messages:
                  - Invalid Credentials
    WebhookConflict:
      description: 账户中已经有同名的 webhook，或者已经有 URL 相同且监听其中某个相同事件的 webhook。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WebhookConflictError'
          examples:
            Already exists:
              value:
                code: WEBHOOK_ALREADY_EXISTS
                messages:
                  - >-
                    A webhook with the same name, or url and trigger(s), already
                    exists for this account.
    UpstreamError:
      description: webhook 服务暂时不可用。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WebhookUpstreamError'
          examples:
            Service unavailable:
              value:
                code: WEBHOOK_UPSTREAM_ERROR
                messages:
                  - The webhook service is temporarily unavailable.
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      name: public-api-key
      x-default: <Your public-api-key>
    sec1:
      type: apiKey
      in: header
      name: private-secret-key
      x-default: <Your private-secret-key>

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.