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

# Cancel Subscription By Account

> Cancel a subscription or bill associated with a linked merchant account



## OpenAPI

````yaml POST /subscriptions/cancel
openapi: 3.1.0
info:
  title: Knot API
  description: An API to interact with the Knot merchant connectivity platform.
  version: 1.0.0
servers:
  - url: https://development.knotapi.com
    description: Development server
security:
  - basicAuth: []
paths:
  /subscriptions/cancel:
    post:
      description: Cancel a subscription or bill associated with a linked merchant account
      operationId: subscription_cancel_by_account
      requestBody:
        description: >-
          The input parameters required for cancelling a subscription or bill on
          a merchant account.
        content:
          application/json:
            schema:
              type: object
              properties:
                external_user_id:
                  type: string
                  description: Your unique identifier for the user.
                  example: abc
                merchant_id:
                  type: integer
                  description: >-
                    The unique ID of the merchant whose linked account the
                    subscription is cancelled on.
                  example: 18
                simulate:
                  type: string
                  description: >-
                    Simulate a failed cancellation or an error response in the
                    development environment.
                  example: failed
                  oneOf:
                    - const: failed
                      title: failed
                      description: >-
                        The cancellation attempt fails and triggers the
                        `CANCELLATION_FAILED` webhook. Requires exactly one
                        cancellable subscription on the merchant account;
                        otherwise the matching
                        `CANCELLABLE_SUBSCRIPTION_NOT_FOUND` or
                        `MULTIPLE_CANCELLABLE_SUBSCRIPTIONS_FOUND` error is
                        returned instead.
                    - const: no_cancellable_subscriptions
                      title: no_cancellable_subscriptions
                      description: >-
                        The request fails with a
                        `CANCELLABLE_SUBSCRIPTION_NOT_FOUND` error, as if the
                        merchant account had no cancellable subscriptions.
                    - const: multiple_subscriptions
                      title: multiple_subscriptions
                      description: >-
                        The request fails with a
                        `MULTIPLE_CANCELLABLE_SUBSCRIPTIONS_FOUND` error listing
                        the cancellable subscriptions on the merchant account.
              required:
                - external_user_id
                - merchant_id
            examples:
              Success:
                summary: Success
                value:
                  external_user_id: abc
                  merchant_id: 18
              Failure:
                summary: Simulate failure
                value:
                  external_user_id: abc
                  merchant_id: 18
                  simulate: failed
              NoCancellableSubscriptions:
                summary: Simulate no cancellable subscriptions
                value:
                  external_user_id: abc
                  merchant_id: 18
                  simulate: no_cancellable_subscriptions
              MultipleCancellableSubscriptions:
                summary: Simulate multiple cancellable subscriptions
                value:
                  external_user_id: abc
                  merchant_id: 18
                  simulate: multiple_subscriptions
      responses:
        '202':
          description: Cancellation request accepted.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Success
        '400':
          description: Bad request.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Error'
                  - type: object
                    properties:
                      data:
                        type: object
                        description: >-
                          Additional context returned with the
                          `MULTIPLE_CANCELLABLE_SUBSCRIPTIONS_FOUND` error.
                        properties:
                          subscriptions:
                            type: array
                            description: >-
                              The cancellable subscriptions found on the
                              merchant account. Cancel one of them with [Cancel
                              Subscription By
                              ID](/api-reference/products/subscriptions/cancel).
                            items:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: Unique identifier for the subscription.
                                  example: 13da3c28-a068-4642-9ce2-b730cfda5f5f
                                name:
                                  type: string
                                  description: >-
                                    Human-readable subscription name as
                                    displayed by the merchant.
                                  example: Hulu (With Ads)
                                description:
                                  type:
                                    - string
                                    - 'null'
                                  description: Description of the subscription plan.
                                  example: >-
                                    Stream thousands of shows and movies, with
                                    ads.
                                price:
                                  anyOf:
                                    - $ref: '#/components/schemas/SubscriptionPrice'
                                    - type: 'null'
              examples:
                ExternalUserIdRequired:
                  summary: external_user_id is required
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The external_user_id field is required.
                MerchantIdRequired:
                  summary: merchant_id is required
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The merchant_id field is required.
                MerchantIdInvalid:
                  summary: merchant_id is invalid
                  value:
                    error_type: INVALID_REQUEST
                    error_code: INVALID_FIELD
                    error_message: The selected merchant_id is invalid.
                UserNotFound:
                  summary: User not found
                  value:
                    error_type: USER_ERROR
                    error_code: USER_NOT_FOUND
                    error_message: The user was not found. Please check the ID provided.
                MerchantAccountNotFound:
                  summary: Merchant account not found
                  value:
                    error_type: MERCHANT_ACCOUNT_ERROR
                    error_code: MERCHANT_ACCOUNT_NOT_FOUND
                    error_message: >-
                      The merchant account was not found. Please check the
                      merchant_id provided.
                CancellableSubscriptionNotFound:
                  summary: No cancellable subscriptions found
                  value:
                    error_type: SUBSCRIPTION_ERROR
                    error_code: CANCELLABLE_SUBSCRIPTION_NOT_FOUND
                    error_message: There are no cancellable subscriptions found.
                MultipleCancellableSubscriptionsFound:
                  summary: Multiple cancellable subscriptions found
                  value:
                    error_type: SUBSCRIPTION_ERROR
                    error_code: MULTIPLE_CANCELLABLE_SUBSCRIPTIONS_FOUND
                    error_message: There are multiple cancellable subscriptions found.
                    data:
                      subscriptions:
                        - id: 13da3c28-a068-4642-9ce2-b730cfda5f5f
                          name: Hulu (With Ads)
                          description: Stream thousands of shows and movies, with ads.
                          price:
                            total: '9.99'
                            currency: USD
                        - id: 7a2e9f14-b532-48d1-ae73-c9f2d8e61b4a
                          name: HBO Max Add-on
                          description: Add HBO Max to your Hulu plan, ad-free.
                          price:
                            total: '16.99'
                            currency: USD
                MerchantUnavailable:
                  summary: Merchant unavailable
                  value:
                    error_type: MERCHANT_ERROR
                    error_code: MERCHANT_UNAVAILABLE
                    error_message: >-
                      The merchant is unavailable. Please check the merchant_id
                      provided.
                MerchantAccountDisconnected:
                  summary: Merchant account disconnected
                  value:
                    error_type: MERCHANT_ACCOUNT_ERROR
                    error_code: MERCHANT_ACCOUNT_DISCONNECTED
                    error_message: >-
                      The merchant account is disconnected. Please check the
                      merchant_id provided.
                OngoingOperation:
                  summary: Ongoing operation
                  value:
                    error_type: MERCHANT_ACCOUNT_ERROR
                    error_code: ONGOING_OPERATION
                    error_message: An existing operation is in progress.
        '401':
          description: Unauthorized request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                AuthFailed:
                  summary: Auth failed
                  value:
                    error_type: INVALID_INPUT
                    error_code: INVALID_API_KEYS
                    error_message: Invalid client_id or secret provided.
        '403':
          description: Forbidden request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                NoAccess:
                  summary: No access
                  value:
                    error_type: INVALID_REQUEST
                    error_code: NO_ACCESS
                    error_message: Please contact Knot for access to this endpoint.
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                InternalServerError:
                  summary: Unexpected server error
                  value:
                    message: Server Error
components:
  schemas:
    Error:
      type: object
      properties:
        error_type:
          type: string
          description: Type of error.
          enum:
            - INVALID_INPUT
            - INVALID_REQUEST
            - USER_ERROR
            - SESSION_ERROR
            - MERCHANT_ACCOUNT_ERROR
            - MERCHANT_ERROR
            - SUBSCRIPTION_ERROR
            - TRANSACTION_ERROR
            - CART_ERROR
          example: INVALID_REQUEST
        error_code:
          type: string
          description: Error code.
          enum:
            - INVALID_API_KEYS
            - INVALID_FIELD
            - INVALID_JWE
            - INVALID_CURSOR_FORMAT
            - USER_NOT_FOUND
            - MERCHANT_ACCOUNT_NOT_FOUND
            - MERCHANT_ACCOUNT_DISCONNECTED
            - SESSION_NOT_FOUND
            - EXTEND_NOT_SUPPORTED
            - MERCHANT_UNAVAILABLE
            - NO_ACCESS
            - TRANSACTION_NOT_FOUND
            - NO_TRANSACTIONS
            - SUBSCRIPTION_NOT_FOUND
            - CANCELLABLE_SUBSCRIPTION_NOT_FOUND
            - MULTIPLE_CANCELLABLE_SUBSCRIPTIONS_FOUND
            - ONGOING_OPERATION
            - CART_NOT_FOUND
            - FULFILLMENT_NOT_FOUND
          example: INVALID_FIELD
        error_message:
          type: string
          description: Detailed error message.
          example: The limit may not be greater than 10.
    SubscriptionPrice:
      type: object
      properties:
        total:
          type: string
          description: Total price of the subscription.
          example: '11.99'
        currency:
          type: string
          description: Currency of the price. ISO 4217 format.
          example: USD
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: >-
        Basic authentication header of the form `Basic <encoded-value>`, where
        `<encoded-value>` is the base64-encoded string `username:password`. Use
        your `client_id` as the `username` and your `secret` as the `password`
        value.

````