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

# Create an Affiliate Link

> Creates an additional referral link for an existing affiliate. An affiliate can own any number of links, which is useful for running separate campaigns under one affiliate.

Identify the affiliate with either `affiliateId` or `affiliateEmail` — a link cannot exist without an affiliate. The `link` slug may contain only letters, numbers and hyphens, and must be unique within the program.

Fires the `affiliate.updated` webhook for the link's owner.



## OpenAPI

````yaml POST /links
openapi: 3.0.1
info:
  title: Referly API
  description: >-
    REST API for managing affiliates, referrals, sales, affiliate links, coupons
    and promotional codes in your Referly affiliate program.


    Every request must send `Authorization: Bearer <YOUR_API_KEY>`. The token is
    scoped to a single affiliate program, so no program ID is ever required in
    the request — every read and write is automatically limited to that program.


    Requests are rate limited per token, per endpoint and per method.
  version: 1.0.0
servers:
  - url: https://www.referly.so/api/v1
security:
  - bearerAuth: []
paths:
  /links:
    post:
      summary: Create an affiliate link
      description: >-
        Creates an additional referral link for an existing affiliate. An
        affiliate can own any number of links, which is useful for running
        separate campaigns under one affiliate.


        Identify the affiliate with either `affiliateId` or `affiliateEmail` — a
        link cannot exist without an affiliate. The `link` slug may contain only
        letters, numbers and hyphens, and must be unique within the program.


        Fires the `affiliate.updated` webhook for the link's owner.
      requestBody:
        description: The affiliate link to create
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewAffiliateLink'
        required: true
      responses:
        '200':
          description: >-
            The created affiliate link, with counters at zero and its full URLs
            already generated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AffiliateLink'
        '400':
          description: >-
            `link` was missing, neither `affiliateId` nor `affiliateEmail` was
            supplied, the affiliate was not found in this program, the slug
            contains characters other than letters, numbers and hyphens, or the
            slug is already used in this program.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/ProgramNotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          description: The affiliate link could not be created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    NewAffiliateLink:
      type: object
      required:
        - link
      properties:
        link:
          type: string
          description: >-
            The slug for the new link. Letters, numbers and hyphens only, and
            unique within the program.
          example: summer-campaign
        affiliateId:
          type: string
          format: uuid
          description: >-
            The affiliate who will own this link. Required unless
            `affiliateEmail` is supplied.
        affiliateEmail:
          type: string
          format: email
          description: >-
            Email of the affiliate who will own this link. Required unless
            `affiliateId` is supplied.
    AffiliateLink:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: The affiliate link ID
        link:
          type: string
          description: The affiliate link string
        createdAt:
          type: string
          format: date-time
          description: Timestamp when the affiliate link was created
        updatedAt:
          type: string
          format: date-time
          description: Timestamp when the affiliate link was last updated
        affiliate:
          type: object
          properties:
            id:
              type: string
              format: uuid
              description: The affiliate ID
            name:
              type: string
              description: Full name of the affiliate
            email:
              type: string
              format: email
              description: Email of the affiliate
          nullable: true
          description: The affiliate who owns this link. `null` if the link has no owner.
        program:
          type: object
          properties:
            id:
              type: string
              format: uuid
              description: The program ID
            name:
              type: string
              description: Name of the affiliate program
            currency:
              type: string
              description: Currency used by the program
          nullable: true
          description: The program this link belongs to. `null` if the link has no program.
        clicks:
          type: integer
          description: Number of clicks on this affiliate link
        referrals:
          type: integer
          description: Number of referrals generated by this link
        sales:
          type: integer
          description: Number of sales generated by this link
        totalRevenue:
          type: number
          format: float
          description: Sum of `totalEarned` across every sale attributed to this link
        fullURLs:
          type: array
          description: >-
            One entry per base URL configured on your program, with the
            affiliate's tracking parameter and any program URL parameters
            already applied. Share these directly.
          items:
            type: object
            properties:
              baseUrl:
                type: string
                description: The base URL
              fullUrl:
                type: string
                description: The complete affiliate URL with parameters
      description: >-
        An affiliate link as returned by the affiliate link endpoints. The
        counters and `fullURLs` are computed per request and are not stored on
        the link itself.
    Error:
      type: object
      properties:
        error:
          type: string
          description: Human readable description of what went wrong
  responses:
    Unauthorized:
      description: >-
        The `Authorization` header is missing, is not a `Bearer` header, or the
        token is not valid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: API access is not enabled for this account.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ProgramNotFound:
      description: The affiliate program this token belongs to no longer exists.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: Too many requests for this token on this endpoint. Please slow down.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````