> ## 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.

# 将促销附加到计划

> 将现有促销附加到订阅计划，适用于一定的收费次数，以便该计划的订阅可以获得该促销

将现有促销附加到计划。之后，该计划上的订阅在[创建](https://docs.y.uno/zh-hans/reference/subscriptions/create-subscription.md)或[更新](https://docs.y.uno/zh-hans/reference/subscriptions/update-subscription.md)时即可获得该促销。附加关系决定折扣覆盖的收费次数（`cycles`）以及暂停对其的影响（`on_pause`）。请参阅[订阅计划促销](https://docs.y.uno/zh-hans/docs/payment-features/subscriptions/promotions.md)。

响应以及计划 `promotions` 列表中的每个条目都会显示附加关系的 `promotion_id`、`name`、`type`、`status`、`cycles`、`on_pause` 和 `attached_at`。

`type` 是促销的兑换方式：`AUTOMATIC`（在该计划上创建订阅时自动应用）或 `CODE`（仅在商户发送其促销码时应用）。

> [!NOTE]
>
> **附加关系不可编辑**
>
> 要更改 `cycles` 或 `on_pause`，请使用[从计划中移除促销](https://docs.y.uno/zh-hans/reference/plans/remove-plan-promotion.md)移除该附加关系，然后重新附加促销。移除附加关系不会改变已经拥有该促销的订阅。

## 错误

| HTTP | `code` | 发生情况 |
| :- | :- | :- |
| `404` | `PROMOTION_NOT_FOUND` | `promotion_id` 未知，或属于其他账户。 |
| `409` | `PROMOTION_ALREADY_ATTACHED` | 该计划已附加此促销。 |
| `422` | `PROMOTION_NOT_APPLICABLE` | 无法附加该促销。`reason` 说明原因，例如 `EXPIRED`，或在您的组织未开启促销时为 `PROMOTIONS_NOT_ENABLED`。 |
| `503` | `PROMOTION_ENGINE_UNAVAILABLE` | 促销引擎没有响应。 |
| `504` | `PROMOTION_ENGINE_TIMEOUT` | 促销引擎未在规定时间内响应。 |

请参阅[订阅促销错误代码](https://docs.y.uno/zh-hans/reference/subscriptions/subscription-promotion-error-codes.md)，了解所有原因。


## OpenAPI

````yaml openapi/zh-hans/plans/attach-plan-promotion.json POST /subscriptions/plans/{plan_id}/promotions
openapi: 3.1.0
info:
  title: plans
  version: 1.0.0
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
  - url: https://api.eu.y.uno/v1
    description: Production (EMEA)
security:
  - sec0: []
    sec1: []
paths:
  /subscriptions/plans/{plan_id}/promotions:
    post:
      summary: 将促销附加到计划
      description: >-
        将现有促销附加到计划，覆盖 `cycles` 次扣款。该计划下的订阅在创建或更新时即可获得该促销。附加关系不可编辑：如需更改 `cycles`
        或 `on_pause`，请移除该附加关系，然后重新附加促销。
      operationId: attach-plan-promotion
      parameters:
        - in: header
          name: X-Account-Code
          required: true
          schema:
            type: string
          description: >-
            您的 [Yuno Dashboard](https://dashboard.y.uno/developers) 中的
            `account_id`（UUID）。必填：缺少该参数时返回 `400 BAD_REQUEST`（"Invalid
            x-account-code header."）。
        - name: plan_id
          in: path
          description: 计划的唯一标识符。
          schema:
            type: string
          required: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - promotion_id
                - cycles
              properties:
                promotion_id:
                  type: string
                  description: 现有促销的 ID（UUID）。
                cycles:
                  type: integer
                  minimum: 1
                  description: 折扣覆盖的扣款次数。至少为 1。
                on_pause:
                  type: string
                  enum:
                    - KEEP
                    - END
                  default: KEEP
                  description: >-
                    促销应用到订阅后，暂停对促销的影响。`KEEP`（默认）会保留其剩余周期，待订阅恢复时继续使用。`END`
                    会结束促销，并将 `end_reason` 设为 `PAUSE`。
            examples:
              Request:
                value:
                  promotion_id: 8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10
                  cycles: 3
      responses:
        '201':
          description: 201。促销已附加到计划。
          content:
            application/json:
              examples:
                Result:
                  value:
                    promotion_id: 8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10
                    name: Welcome 20% x3
                    type: AUTOMATIC
                    status: ENABLED
                    cycles: 3
                    attached_at: '2026-11-02T14:00:00Z'
                    on_pause: KEEP
              schema:
                type: object
                properties:
                  promotion_id:
                    type: string
                  name:
                    type: string
                  type:
                    type: string
                    description: >-
                      促销的兑换模式。`AUTOMATIC` 促销会在该计划下创建订阅时自动应用。`CODE`
                      促销会在商户发送优惠码时应用。
                    enum:
                      - AUTOMATIC
                      - CODE
                  status:
                    type: string
                    description: 创建附加关系时为 `ENABLED`。
                  cycles:
                    type: integer
                  attached_at:
                    type: string
                    format: date-time
                  on_pause:
                    type: string
                    enum:
                      - KEEP
                      - END
                    description: 促销应用到订阅后，暂停对促销的影响。
        '404':
          description: 404。促销不存在，或属于其他账户。
          content:
            application/json:
              examples:
                Result:
                  value:
                    code: PROMOTION_NOT_FOUND
                    messages:
                      - Promotion not found.
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
        '409':
          description: 409。该计划已附加此促销。
          content:
            application/json:
              examples:
                Result:
                  value:
                    code: PROMOTION_ALREADY_ATTACHED
                    messages:
                      - The promotion is already attached to this plan.
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
        '422':
          description: >-
            422。无法附加该促销。`reason` 说明原因，例如 `EXPIRED`，或在组织未开启促销时为
            `PROMOTIONS_NOT_ENABLED`。
          content:
            application/json:
              examples:
                Result:
                  value:
                    code: PROMOTION_NOT_APPLICABLE
                    messages:
                      - The promotion cannot be applied.
                    reason: EXPIRED
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
                  reason:
                    type: string
                    description: 促销无法附加或应用的原因。
components:
  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.