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

# Create a subscription

> Creates a new subscription for a customer on a given plan. A card token is required for paid plans (not needed during trial).



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/subscriptions
openapi: 3.0.0
info:
  title: PlugToPay API
  description: API to make payments easy in multiple gateways.
  version: 1.0.0
servers:
  - url: http://localhost:7701
    description: Test Server
security: []
paths:
  /api/v1/subscriptions:
    post:
      tags:
        - Subscriptions
      summary: Create a subscription
      description: >-
        Creates a new subscription for a customer on a given plan. A card token
        is required for paid plans (not needed during trial).
      operationId: e2be6b4223f2e8dde744ed269167bae3
      parameters:
        - $ref: '#/components/parameters/XClientId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              required:
                - plan_uuid
                - customer_token
              properties:
                plan_uuid:
                  description: UUID of the subscription plan to attach.
                  type: string
                  format: uuid
                  example: plan-uuid-...
                customer_token:
                  description: Token of an existing customer.
                  type: string
                  example: cus_token_abc123
                card_token:
                  description: >-
                    Stored card token to charge on each cycle. Required for paid
                    plans without a trial.
                  type: string
                  example: card_tok_xyz
                  nullable: true
                coupon_code:
                  description: Discount coupon code to apply at creation (max 50 chars).
                  type: string
                  example: PROMO10
                  nullable: true
                billing_day:
                  description: >-
                    Override the plan billing day (1–28). Defaults to plan or
                    creation day.
                  type: integer
                  example: 10
                  nullable: true
                gateway_id:
                  description: Force a specific gateway ID for this subscription's charges.
                  type: integer
                  example: 1
                  nullable: true
                metadata:
                  description: Arbitrary key-value data stored with the subscription.
                  type: object
                  nullable: true
              type: object
      responses:
        '201':
          description: Subscription created
          content:
            application/json:
              schema:
                properties:
                  data:
                    $ref: '#/components/schemas/Subscription'
                type: object
        '401':
          description: Unauthorized — Invalid API Key
        '422':
          description: >-
            Validation error or business rule violation (e.g. duplicate active
            subscription)
      security:
        - ApiKeyAuth: []
components:
  parameters:
    XClientId:
      name: x-client-id
      in: header
      description: Client identifier for the company in the request.
      required: true
      schema:
        type: string
        example: client_abc123
  schemas:
    Subscription:
      properties:
        id:
          type: string
          format: uuid
        status:
          type: string
          enum:
            - active
            - trialing
            - paused
            - past_due
            - canceled
          example: active
        plan:
          oneOf:
            - $ref: '#/components/schemas/SubscriptionPlan'
          nullable: true
        customer:
          type: object
          nullable: true
        card:
          properties:
            last_4_digits:
              type: string
              example: '4242'
            brand:
              type: string
              example: visa
            expire_month:
              type: string
              example: '12'
            expire_year:
              type: string
              example: '2028'
          type: object
          nullable: true
        coupon:
          type: object
          nullable: true
        amount:
          description: Effective billing amount in cents (after discount)
          type: integer
          example: 2990
        original_amount:
          type: integer
          example: 2990
        discount_amount:
          type: integer
          example: 500
          nullable: true
        currency:
          type: string
          example: BRL
        interval:
          type: string
          enum:
            - weekly
            - monthly
            - yearly
          example: monthly
        interval_count:
          type: integer
          example: 1
        billing_day:
          type: integer
          example: 5
          nullable: true
        trial:
          properties:
            period_days:
              type: integer
              example: 7
            start:
              type: string
              format: date-time
              nullable: true
            end:
              type: string
              format: date-time
              nullable: true
          type: object
          nullable: true
        current_period:
          properties:
            start:
              type: string
              format: date-time
              nullable: true
            end:
              type: string
              format: date-time
              nullable: true
          type: object
        next_billing_at:
          type: string
          format: date-time
          nullable: true
        paused_at:
          type: string
          format: date-time
          nullable: true
        paused_until:
          type: string
          format: date-time
          nullable: true
        canceled_at:
          type: string
          format: date-time
          nullable: true
        cancel_at:
          type: string
          format: date-time
          nullable: true
        cancel_at_period_end:
          type: boolean
          example: false
        plan_change_at:
          type: string
          format: date-time
          nullable: true
        new_plan_id:
          type: string
          format: uuid
          nullable: true
        metadata:
          type: array
          items:
            type: object
          nullable: true
        created_at:
          type: string
          format: date-time
          nullable: true
        updated_at:
          type: string
          format: date-time
          nullable: true
      type: object
    SubscriptionPlan:
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
          example: Basic Monthly
        description:
          type: string
          nullable: true
        amount:
          description: Plan price in cents
          type: integer
          example: 2990
        currency:
          type: string
          example: BRL
        interval:
          type: string
          enum:
            - weekly
            - monthly
            - yearly
          example: monthly
        interval_count:
          type: integer
          example: 1
          nullable: true
        trial_period_days:
          type: integer
          example: 7
          nullable: true
        billing_day:
          description: Day of the month to charge (1–28)
          type: integer
          example: 5
          nullable: true
        min_card_months:
          description: >-
            Minimum months the card must be valid at subscription creation; null
            = no restriction
          type: integer
          example: 3
          nullable: true
        is_active:
          type: boolean
          example: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      type: object
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: Company API key. Send in the X-API-Key header.
      name: X-API-Key
      in: header

````