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

# 创建归因链接

> 为指定品牌商品创建推广归因链接

使用该接口为某个品牌商品创建推广归因链接。请求必须包含 `brand_id` 和 `product_id`，也可以传入可选的 `tracking_id`、`destination_url`。

字段说明：

* `tracking_id`：客户侧追踪标识，最多 200 个字符。建议把下游系统里的 tag、campaign、source 等追踪值放在这里；前后空白会被裁剪，不能包含 ASCII 控制字符。创建成功后会在创建响应和列表响应中返回规范化后的值，后续报表也会使用该字段做下游归因。
* `destination_url`：Amazon 落地页 URL，可选。未传入时默认使用商品详情页；它决定用户点击后进入哪个 Amazon 页面，不承担追踪 tag 的作用。

成功时返回 `201` 和 `{ "link": LinkDTO }`。

创建成功后，响应里的 `marketplace` 会返回该链接对应的 Amazon 站点域名，例如 `amazon.com`、`amazon.co.uk`、`amazon.de`。该字段用于判断链接所属站点，不表示合作状态，也不是追踪 tag。

可能的错误：

* `400 invalid_request`：请求体不完整或字段无效。
* `403 forbidden_resource`：当前 Token owner 无权访问该品牌或商品。
* `403 ads_not_connected`：品牌广告连接状态不满足创建要求。
* `404 product_not_found`：商品不存在或不可访问。

相关接口：如需查看已创建的归因链接，请使用 [列出归因链接](/zh/creator/links/list-links)。


## OpenAPI

````yaml POST /api/creator/v1/links
openapi: 3.1.0
info:
  title: OpenLight Public API
  version: 1.0.0
  summary: OpenLight seller and creator public API
  description: |
    Public API for external seller and creator integrations.
    Console/internal APIs remain documented separately in docs/openapi.yaml.
servers:
  - url: https://app.openlight.tech
    description: Production
  - url: http://localhost:8080
    description: Local development
security:
  - bearerAuth: []
tags:
  - name: Creator Brands
  - name: Creator Products
  - name: Creator Links
  - name: Creator Reports
  - name: Seller Brands
  - name: Seller Products
paths:
  /api/creator/v1/links:
    post:
      tags:
        - Creator Links
      summary: Create an attribution link
      description: >
        Creates an attribution link for an approved brand product. The request
        must include `brand_id` and `product_id`. Use optional `tracking_id` as
        your own downstream tracking tag; it is returned by link listing and
        future reports. `destination_url` controls the Amazon landing page and
        defaults to the product detail page. The response includes
        `marketplace`, the Amazon marketplace domain derived from the landing
        page or product.
      operationId: createCreatorLink
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - brand_id
                - product_id
              properties:
                brand_id:
                  type: string
                  description: 品牌 ID。Brand ID.
                product_id:
                  type: string
                  description: 商品 ID。Product ID.
                destination_url:
                  type: string
                  description: >-
                    Amazon 落地页 URL；可选，默认使用商品详情页。Amazon landing page URL;
                    optional, defaults to the product detail page.
                tracking_id:
                  type: string
                  maxLength: 200
                  description: >-
                    客户侧追踪标识；可选，前后空白会被裁剪，不能包含 ASCII
                    控制字符。创建和列表响应会返回规范化后的值，后续报表也会使用该字段做下游归因。Client-side tracking
                    tag; optional, leading/trailing whitespace is trimmed and
                    ASCII control characters are rejected. Create/list responses
                    return the normalized value, intended for downstream
                    reporting.
      responses:
        '201':
          description: Attribution link created
          content:
            application/json:
              schema:
                type: object
                required:
                  - link
                properties:
                  link:
                    $ref: '#/components/schemas/PublicLink'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  schemas:
    PublicLink:
      type: object
      required:
        - id
        - brand_id
        - product_id
        - url
        - destination_url
        - marketplace
        - tracking_id
        - status
        - created_at
      properties:
        id:
          type: string
          description: 归因链接 ID。Attribution link ID.
        brand_id:
          type: string
          description: 品牌 ID。Brand ID.
        product_id:
          type: string
          description: 商品 ID。Product ID.
        url:
          type: string
          description: 可分发的归因链接 URL。Shareable attribution link URL.
        destination_url:
          type: string
          description: >-
            Amazon 落地页 URL，通常为商品详情页或创建链接时传入的目标页。Amazon landing page URL, usually
            the product detail page or the requested destination.
        marketplace:
          type: string
          description: >-
            归因链接对应的 Amazon 站点域名，例如 amazon.com、amazon.co.uk、amazon.de；不是合作状态或追踪
            tag。Amazon marketplace domain for this attribution link, such as
            amazon.com, amazon.co.uk, or amazon.de; not a partnership status or
            tracking tag.
        tracking_id:
          type: string
          description: >-
            创建链接时传入并规范化后的客户侧追踪标识；未传入时为空字符串。Normalized client-side tracking tag
            supplied at creation time; empty string when omitted.
        status:
          type: string
          description: 链接状态；当前固定为 active。Link status; currently always active.
          enum:
            - active
        created_at:
          type: string
          format: date-time
          description: 链接创建时间。Link creation time.
    PublicErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          description: 错误详情。Error detail.
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: 机器可读错误码。Machine-readable error code.
              examples:
                - invalid_api_token
                - forbidden_resource
            message:
              type: string
              description: 面向开发者的错误说明。Developer-facing error message.
  responses:
    BadRequest:
      description: Invalid request or pagination parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicErrorResponse'
          examples:
            invalid_request:
              summary: Invalid request
              value:
                error:
                  code: invalid_request
                  message: invalid_request
            invalid_pagination:
              summary: Invalid pagination
              value:
                error:
                  code: invalid_pagination
                  message: invalid_pagination
    Unauthorized:
      description: Missing or invalid API token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicErrorResponse'
    Forbidden:
      description: Token cannot access the requested role or resource
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicErrorResponse'
          examples:
            forbidden_resource:
              summary: Forbidden resource
              value:
                error:
                  code: forbidden_resource
                  message: forbidden_resource
            ads_not_connected:
              summary: Ads not connected
              value:
                error:
                  code: ads_not_connected
                  message: ads_not_connected
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicErrorResponse'
          examples:
            product_not_found:
              summary: Product not found
              value:
                error:
                  code: product_not_found
                  message: product_not_found
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````