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

# Cancel a Subscription

> Cancels a subscription so it never renews again. A subscription with paid time left stays `active` until `ends_at`, the end of the period the customer paid for, and reads `canceled` after it. One with no paid period left (never paid, past due, or first paid while renewals were off for your account) ends now; if the customer hasn't paid yet, their open checkout charges nothing. A renewal waiting to be charged is voided; one already being charged finishes, and if it is paid the customer keeps that period. Canceling a paused subscription ends the pause. Canceling again changes nothing and keeps the first `ends_at`. Sends the `subscription.canceled` webhook: always for a subscription whose first payment began renewals, otherwise only if you turned that event on.

```bash Curl theme={null}
curl -X POST "https://api-sandbox.paywithsoap.com/api/v1/subscriptions/sub_7Hn2Kq9Wx4Lm8Pz3Rt6Vb1Ys5JdCfEaG/cancel" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reason": "customer asked to cancel"}'
```

```json Error (not found) theme={null}
{
  "error": "Subscription not found.",
  "hint": "Please verify the subscription id is correct. \n subscription_id: sub_7Hn2Kq9Wx4Lm8Pz3Rt6Vb1Ys5JdCfEaG"
}
```


## OpenAPI

````yaml POST /api/v1/subscriptions/{id}/cancel
openapi: 3.1.0
info:
  title: Soap API
  description: >-
    API documentation for Soap - AI-native payments infrastructure for complex,
    compliance-heavy payment flows
  license:
    name: MIT
  version: 1.4.0
servers:
  - url: https://api-sandbox.paywithsoap.com
security:
  - bearerAuth: []
paths:
  /api/v1/subscriptions/{id}/cancel:
    post:
      tags:
        - Subscriptions
      summary: Cancel a subscription
      description: >-
        Cancels a subscription so it never renews again. A subscription with
        paid time left stays `active` until `ends_at`, the end of the period the
        customer paid for, and reads `canceled` after it. One with no paid
        period left (never paid, past due, or first paid while renewals were off
        for your account) ends now; if the customer hasn't paid yet, their open
        checkout charges nothing. A renewal waiting to be charged is voided; one
        already being charged finishes, and if it is paid the customer keeps
        that period. Canceling a paused subscription ends the pause. Canceling
        again changes nothing and keeps the first `ends_at`. Sends the
        `subscription.canceled` webhook: always for a subscription whose first
        payment began renewals, otherwise only if you turned that event on.
      parameters:
        - name: id
          in: path
          required: true
          description: Public id of the subscription to cancel.
          schema:
            type: string
            example: sub_7Hn2Kq9Wx4Lm8Pz3Rt6Vb1Ys5JdCfEaG
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                reason:
                  type: string
                  minLength: 1
                  maxLength: 500
                  description: >-
                    Why the subscription is canceled. Recorded and sent as
                    `reason` on the `subscription.canceled` webhook.
                  example: customer asked to cancel
              additionalProperties: false
      responses:
        '200':
          description: >-
            The subscription, with `canceled_at` and `ends_at` set and
            `next_billing_at` null.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Subscription'
        '400':
          description: >-
            The request body is not a JSON object: malformed JSON, or a JSON
            array, string or number. An empty body is accepted. The response
            never echoes the body.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  hint:
                    type: string
                  code:
                    type: string
                    enum:
                      - invalid_json
                    description: >-
                      Stable machine-readable code. Branch on this, not on
                      `error`.
              example:
                error: Invalid JSON body.
                hint: >-
                  The request body must be a JSON object. Ensure Content-Type is
                  application/json and the payload is valid JSON.
                code: invalid_json
        '401':
          description: >-
            Missing, unknown or inactive API key. The key is checked before the
            request body is read, so a request without a valid key never gets a
            400 or 422. The response never echoes the request.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  hint:
                    type: string
                  code:
                    type: string
                    enum:
                      - invalid_api_key
                    description: >-
                      Stable machine-readable code. Branch on this, not on
                      `error`.
              example:
                error: API key not found.
                hint: >-
                  Send an active API key in the Authorization header as a Bearer
                  token.
                code: invalid_api_key
        '422':
          description: >-
            No subscription with this id belongs to your business, or the body
            has a field other than `reason`, or `reason` is empty or over 500
            characters.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Subscription not found.
                  hint:
                    type: string
      security:
        - bearerAuth: []
components:
  schemas:
    Subscription:
      type: object
      description: A subscription as the merchant API returns it.
      properties:
        id:
          type: string
          example: sub_7Hn2Kq9Wx4Lm8Pz3Rt6Vb1Ys5JdCfEaG
        customer_id:
          type: string
          example: cus_3Lm8Pz3Rt6Vb1Ys5JdCfE7Hn2Kq9WxaG
        status:
          type: string
          enum:
            - incomplete
            - active
            - past_due
            - paused
            - canceled
          description: >-
            Derived from the billing dates each time you read it. `incomplete`
            until the first payment succeeds. `active` while billing runs, when
            the first payment went through while renewals were off for your
            account, and for a subscription canceled for the end of its paid
            period, until `ends_at`. `past_due` after a renewal failed, or while
            a declined renewal waits for its retry. `paused` while the merchant
            has paused billing: nothing renews until it is resumed. `canceled`
            once a canceled subscription's `ends_at` has passed.
        interval:
          type: string
          enum:
            - day
            - week
            - month
            - year
        interval_count:
          type: integer
          example: 1
        line_items:
          type: array
          items:
            type: object
            properties:
              product_id:
                type: string
              sku:
                type:
                  - string
                  - 'null'
              product_name:
                type: string
              product_url:
                type:
                  - string
                  - 'null'
              quantity:
                type: integer
              price_cents:
                type: integer
              total_amount_cents:
                type: integer
        line_items_total_amount_cents:
          type: integer
          example: 4200
        current_period_end:
          type:
            - string
            - 'null'
          format: date-time
          description: End of the period the customer has paid for.
        next_billing_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When the next renewal is charged; while a declined renewal waits for
            its retry, when that retry is charged. Null while paused, canceled,
            or after a renewal failed.
        canceled_at:
          type:
            - string
            - 'null'
          format: date-time
        ends_at:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When a canceled subscription stops being active. Null unless
            canceled.
        paused_at:
          type:
            - string
            - 'null'
          format: date-time
          description: When the merchant paused billing. Null unless paused.
        created_at:
          type: string
          format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token authentication using your API key (key_...). Used for every
        endpoint except POST /api/v1/device_pings.

````

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