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

# Subscription Link

> This API can be used to generate subscription links programmatically. Subscription links are basically standalone webpages where your customer can make a subscription payment.

<Info>
  **These APIs generate subscription links.** For proper integration, refer to [Create Subscription](/developer-resources/endpoints/subscriptions/create-subscription). To learn more about the link, refer to the [Payment Links](/products/payment-links/payment-links) page in the Products section.
</Info>


## OpenAPI

````yaml POST /subscription/link/merchant/generate-link
openapi: 3.0.1
info:
  title: xPay API Store
  description: ''
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.xpaycheckout.com
security:
  - basicAuth: []
paths:
  /subscription/link/merchant/generate-link:
    post:
      description: >-
        This API can be used to generate subscription links programmatically.
        Subscription links are basically standalone webpages where your customer
        can make a subscription payment.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        description: Generate Subscription Link
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/subscription-link'
        required: true
      responses:
        '200':
          description: Generate Subscription Link
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/subscription-link-response'
        '400':
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        maxLength: 255
        pattern: ^[a-zA-Z0-9\-_:\.]+$
      description: >-
        A unique key for making the request idempotent. Must match pattern:
        `^[a-zA-Z0-9\-_:\.]+$`. See [Idempotent
        Requests](/developer-resources/idempotency) for more details.
      example: KG5LxwFBepaKHyUD
  schemas:
    subscription-link:
      required:
        - amount
        - currency
        - customerDetails
        - expiryDate
        - interval
        - intervalCount
        - cycleCount
      type: object
      properties:
        amount:
          description: >-
            The amount in lowest count unit. e.g.: For USD 1, amount is 100
            representing 100 cents (The minimum amount should be greater than 1
            USD)
          type: integer
          format: int64
          example: 100
        currency:
          type: string
          description: >-
            Three letter abbreviation of the currency. Refer [supported
            currencies](/get-started/currencies-supported)
          example: USD
        receiptId:
          type: string
          description: Your identifier of the order
          example: order123
        customerDetails:
          $ref: '#/components/schemas/BillingDetails'
        description:
          description: The description of the order, if any
          type: string
          example: Order for 2 items
        expiryDate:
          description: >-
            Timestamp in epoch milliseconds, indicating the expiration time of
            the link
          type: integer
          format: int64
          example: 32526868154000
        callbackUrl:
          description: >-
            The URL we will callback to with the subscriptionId once it
            finishes.
          type: string
          example: https://example.com/callback
        cancelUrl:
          description: >-
            The URL to redirect the customer to when they cancel the
            subscription. If not provided, the callbackUrl will be used as
            fallback.
          type: string
          example: https://example.com/cancel
        interval:
          type: string
          description: The interval group between subscriptions.
          enum:
            - DAY
            - WEEK
            - MONTH
            - YEAR
          example: MONTH
        intervalCount:
          type: integer
          description: >-
            The number of intervals between subscription billings. For example,
            `interval = MONTH` and `intervalCount = 3` bills every 3 months.
          format: int64
          example: 2
        cycleCount:
          type: integer
          description: >-
            The number of billing cycles for which the subscription will renew
            before ending. The first cycle is included in this count.
          format: int64
          example: 2
        upfrontAmount:
          $ref: '#/components/schemas/UpfrontAmount'
        trialPeriodCount:
          type: integer
          format: int64
          description: >-
            The number of trial periods before the first billing cycle. Must be
            greater than or equal to 0 if provided.


            **Validation Rules:**

            - If `trialPeriodCount` is provided, `trialPeriodInterval` must also
            be provided

            - `trialPeriodCount` is not compatible with `upfrontAmount` - both
            cannot be provided simultaneously
          minimum: 0
          example: 7
        trialPeriodInterval:
          type: string
          description: |-
            The interval for the trial period.

            **Validation Rules:**
            - Required when `trialPeriodCount` is provided
          enum:
            - DAY
            - WEEK
            - MONTH
            - YEAR
          example: DAY
        multiUseLimit:
          type: integer
          format: int64
          description: >-
            The maximum number of times this subscription link can be used. If
            null, the link can be used only once. Must be greater than 0 if
            provided.
          minimum: 1
          example: 5
        productPage:
          $ref: '#/components/schemas/ProductPage'
          description: Product Page - showcases more about the product in the payment links
        phoneNumberRequired:
          type: boolean
          description: >-
            Flag to indicate whether phone number is required from the customer
            during checkout. By default, this is false.
          example: false
    subscription-link-response:
      type: object
      properties:
        shortUrl:
          type: string
          description: >-
            The shortened URL generated by the xPay API. This link can be shared
            with customers for completing payments.
          example: https://api.xpaycheckout.com/subscription/link/pcTrro7D
        disclaimer:
          type: string
          description: >-
            A message highlighting unsupported currency and payment method
            pairs. You may use this information to communicate these limitations
            to your users and set expectations.
          example: GBP is not supported on Klarna. The payment will default to USD.
    Error:
      required:
        - errorCode
        - errorDescription
      type: object
      properties:
        errorCode:
          type: string
          example: bad_request
        errorDescription:
          type: string
          example: Failed to read request
    BillingDetails:
      type: object
      description: Billing details for the customer.
      required:
        - name
        - email
        - contactNumber
      properties:
        name:
          type: string
          description: Customer's name
          example: John Doe
        email:
          type: string
          description: Customer's email address
          example: john.doe@example.com
        contactNumber:
          type: string
          description: >-
            Customer's contact number ([E.164
            format](https://en.wikipedia.org/wiki/E.164)), including the country
            code (e.g., +1 for US, +44 for UK, +91 for India).
          example: '+919123456789'
        customerAddress:
          $ref: '#/components/schemas/CustomerAddress'
    UpfrontAmount:
      type: integer
      format: int64
      description: >-
        An optional amount that merchants can set to be charged to the customer
        at the time the subscription is activated. This amount replaces the
        first billing cycle charge — the regular subscription amount is not
        added on top of it. Regular billing resumes from the next cycle.


        The amount is in the lowest count unit. e.g.: For USD 1, amount is 100
        representing 100 cents (minimum amount should be greater than 1 USD).


        **Validation Rules:**

        - Not compatible with `trialPeriodCount` and `trialPeriodInterval` —
        cannot be provided simultaneously
      minimum: 1
      example: 200
    ProductPage:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: Product name. Must be between 2 and 100 characters long.
          minLength: 2
          maxLength: 100
          example: Premium Subscription
        description:
          type: string
          description: Product description. Must be less than 500 characters long.
          maxLength: 500
          example: Access to premium features and content
    CustomerAddress:
      type: object
      properties:
        addressLine1:
          type: string
          description: Line 1 of the customer's address
          example: 123 Main St
        addressLine2:
          type: string
          description: Line 2 of the customer's address
          example: Apt 1
        city:
          type: string
          description: City of the customer's address
          example: New York
        state:
          type: string
          description: State of the customer's address
          example: NY
        country:
          type: string
          description: >-
            Two-letter country code ([ISO 3166-1
            alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
          example: US
        postalCode:
          type: string
          description: Postal code
          example: '2424'
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic

````