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

# Change a trial

> Extend, shorten or end a subscription's trial.

Moves a trialing subscription's end, or ends the trial now. [Free trials](https://docs.integrateledger.com/pricing/trials.md) explains both kinds.

* `trialEndsAt` sets the new end; `days` counts from now (14 on day 10 of a 14-day trial gives 14 more). The new end must be after now (`422 invalid_trial_end`). No credits are added: the trial's grant lasts until the new end.
* `end: "now"` on a card trial bills the first period at once and grants it; send an `Idempotency-Key`. On a no-card trial it goes back to the plan before the trial at once.
* A subscription that isn't trialing answers `409 subscription_not_trialing`.

Needs the **Billing** permission at Write.


## OpenAPI

````yaml openapi.json POST /v1/customers/subscriptions/{subscriptionId}/trial
openapi: 3.1.0
info:
  title: Ledger API
  version: 0.1.0
servers:
  - url: https://api.integrateledger.com
    description: Hosted Ledger API
security: []
paths:
  /v1/customers/subscriptions/{subscriptionId}/trial:
    post:
      tags:
        - Customers
      summary: Extend, shorten or end a trial
      description: >-
        End the trial with { end: "now" } and an Idempotency-Key: a card trial
        bills its first period at once.
      operationId: changeSubscriptionTrial
      parameters:
        - schema:
            type: integer
            exclusiveMinimum: 0
            maximum: 2147483647
            description: The subscription's `id` from List customer subscriptions.
          required: true
          description: The subscription's `id` from List customer subscriptions.
          name: subscriptionId
          in: path
        - schema:
            type: string
            minLength: 1
            maxLength: 255
            description: Your ID for the customer, such as your user ID.
          required: true
          description: Your ID for the customer, such as your user ID.
          name: customerId
          in: query
        - schema:
            type: string
            minLength: 1
            maxLength: 255
            description: 'Required with `end: now` on a card trial, which charges.'
          required: false
          description: 'Required with `end: now` on a card trial, which charges.'
          name: idempotency-key
          in: header
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TrialChange'
      responses:
        '200':
          description: The trial's state after the change
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrialChangeResult'
        '400':
          description: >-
            Invalid request, or `end: now` on a card trial without an
            Idempotency-Key (idempotency_key_required)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '401':
          description: Missing or invalid Ledger API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '403':
          $ref: '#/components/responses/InsufficientPermissions'
        '404':
          description: No such subscription for this customer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '409':
          description: The subscription isn't trialing (subscription_not_trialing)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '422':
          description: The new end isn't after now (invalid_trial_end)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
        '429':
          $ref: '#/components/responses/RateLimited'
        '502':
          description: >-
            No Stripe connection (stripe_not_configured) or Stripe unavailable
            (stripe_request_failed)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerError'
      security:
        - ApiKey: []
      x-codeSamples:
        - lang: python
          label: Python SDK
          source: >-
            import os

            from integrateledger import ledger


            client = ledger(api_key=os.environ["LEDGER_API_KEY"])

            client.change_subscription_trial(customer_id="user_123",
            subscription_id=42, days=14)
        - lang: bash
          label: cURL
          source: >-
            curl --request POST
            'https://api.integrateledger.com/v1/customers/subscriptions/42/trial?customerId=user_123'
            \
              -H "Authorization: Bearer $LEDGER_API_KEY" \
              -H 'Content-Type: application/json' \
              --data '{"days":14}'
        - lang: typescript
          label: TypeScript SDK
          source: >-
            import ledger from "integrateledger";


            const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? ""
            });

            await client.changeSubscriptionTrial({ subscriptionId: 42,
            customerId: "user_123", body: { days: 14 } });
components:
  schemas:
    TrialChange:
      anyOf:
        - $ref: '#/components/schemas/TrialNewEnd'
        - $ref: '#/components/schemas/TrialDaysFromNow'
        - $ref: '#/components/schemas/TrialEndNow'
    TrialChangeResult:
      type: object
      properties:
        subscriptionId:
          type: integer
        status:
          type: string
          enum:
            - trialing
            - active
            - canceled
            - past_due
        trialEndsAt:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - subscriptionId
        - status
        - trialEndsAt
    CustomerError:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
        issues:
          type: array
          items:
            type: object
            properties:
              path:
                type: string
              message:
                type: string
            required:
              - path
              - message
          description: >-
            With `invalid_request`: each field that failed validation and why.
            `path` is empty for the body itself, such as an unknown field.
      required:
        - error
    TrialNewEnd:
      type: object
      properties:
        trialEndsAt:
          type: string
          format: date-time
          description: The trial's new end. Must be after now.
      required:
        - trialEndsAt
      additionalProperties: false
    TrialDaysFromNow:
      type: object
      properties:
        days:
          type: integer
          minimum: 1
          maximum: 365
          description: >-
            Days from now (the customer's now, on a test clock) until the trial
            ends: 14 on day 10 of a 14-day trial gives 14 more.
      required:
        - days
      additionalProperties: false
    TrialEndNow:
      type: object
      properties:
        end:
          type: string
          enum:
            - now
          description: >-
            End the trial now: a card trial bills its first period at once (send
            an Idempotency-Key); a no-card trial goes back to the plan before
            it.
      required:
        - end
      additionalProperties: false
    InsufficientPermissionsError:
      type: object
      properties:
        error:
          type: string
          example: insufficient_permissions
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
        requiredScope:
          type: string
          example: customers:read
      required:
        - error
        - requiredScope
    PayloadTooLargeError:
      type: object
      properties:
        error:
          type: string
          example: payload_too_large
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
      required:
        - error
    RateLimitError:
      type: object
      properties:
        error:
          type: string
          example: rate_limited
        message:
          type: string
          description: >-
            What went wrong and what to do about it, for a person or an agent to
            read. Every Ledger error has one. The wording can change: branch on
            `error`, not on this text.
          example: >-
            No customer "user_123" exists in this environment. Create it with
            POST /v1/customers, or check that the API key is for the right
            environment.
      required:
        - error
  responses:
    InsufficientPermissions:
      description: >-
        The API key works but lacks the permission this endpoint needs, named in
        requiredScope. See the API keys guide.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/InsufficientPermissionsError'
    PayloadTooLarge:
      description: 'The request body is over the limit: 1 MiB, or 5 MiB for a webhook.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PayloadTooLargeError'
    RateLimited:
      description: >-
        Too many requests. Wait Retry-After seconds, then retry. See the rate
        limits guide.
      headers:
        Retry-After:
          description: Seconds until a request is allowed again
          schema:
            type: integer
        RateLimit-Limit:
          description: 'The burst: requests allowed at once'
          schema:
            type: integer
        RateLimit-Remaining:
          description: Requests left right now
          schema:
            type: integer
        RateLimit-Reset:
          description: Seconds until the full burst is back
          schema:
            type: integer
        RateLimit-Policy:
          description: >-
            The sustained rate per second and the burst, such as
            200;w=1;burst=1000
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitError'
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.