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

# Create an Affiliate Link

> Creates a new affiliate link for the specified affiliate. Note: an Affiliate is required to create an Affiliate Link.



## OpenAPI

````yaml POST /links
openapi: 3.0.1
info:
  title: Referly API
  description: API for managing affiliates, referrals, and sales for SaaS businesses
  version: 1.0.0
servers:
  - url: https://www.referly.so/api/v1
security:
  - bearerAuth: []
paths:
  /links:
    post:
      summary: Create a new affiliate link
      description: >-
        Creates a new affiliate link for the specified affiliate. Note: an
        Affiliate is required to create an Affiliate Link.
      requestBody:
        description: Affiliate link details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewAffiliateLink'
        required: true
      responses:
        '200':
          description: Affiliate link created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AffiliateLink'
        '400':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    NewAffiliateLink:
      type: object
      required:
        - link
      properties:
        link:
          type: string
          description: The affiliate link string (letters, numbers, and hyphens only)
        affiliateId:
          type: string
          format: uuid
          description: The affiliate ID (required if affiliateEmail not provided)
        affiliateEmail:
          type: string
          format: email
          description: The affiliate email (required if affiliateId not provided)
    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
        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
        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: Total revenue generated by this link
        fullURLs:
          type: array
          description: Array of full URLs for this affiliate link
          items:
            type: object
            properties:
              baseUrl:
                type: string
                description: The base URL
              fullUrl:
                type: string
                description: The complete affiliate URL with parameters
    Error:
      type: object
      properties:
        error:
          type: integer
          description: Error code
        message:
          type: string
          description: Error message
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````