---
title: "Cancels a subscription now or at the end of its period."
---

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

Path: Sherpo merchant API › subscription

`POST /v1/stores/{store}/subscriptions/{subscription}/cancel`

## Authentication

- `bearer`, http, header `Authorization`, scopes: `subscription:write`

## Path parameters

- `store` (`cancelSubscription.path.store`; string, required) — The store's id.
- `subscription` (`cancelSubscription.path.subscription`; string, required)
  - minLength 1

## Header parameters

- `Idempotency-Key` (`cancelSubscription.header.Idempotency-Key`; string, optional) — Repeats within 24 hours answer the first result; the same key with other arguments is a conflict.
  - minLength 1; maxLength 255; pattern `^[\x21-\x7E]+$`

## Request body

_Required._

- `when` (`cancelSubscription.when`; string, required)
  - one of `"now"`, `"period_end"`
- `reason` (`cancelSubscription.reason`; any of, optional) — Why, in your own words; one of the codes the store writes itself as a reason (`refund`, `dispute`, `upgraded`, `account_erased`, `Ended by the seller.` and the like) is refused.
  - any of: `string`, `null`

## Example request

```json
{
  "when": "now",
  "reason": "string"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.sherpo.io/merchant/v1/stores/<store>/subscriptions/<subscription>/cancel' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "when": "now",
  "reason": "string"
}
'
```

### TypeScript

```typescript
const url = 'https://api.sherpo.io/merchant/v1/stores/<store>/subscriptions/<subscription>/cancel';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({when: 'now', reason: 'string'})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.sherpo.io/merchant/v1/stores/<store>/subscriptions/<subscription>/cancel"

payload = {
    "when": "now",
    "reason": "string"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Cancels a subscription now or at the end of its period.

#### Example

```json
{
  "display_status": "string",
  "next_event": {
    "kind": "string",
    "at": "string"
  },
  "actions": {
    "cancel": {
      "period_end": true,
      "now": true
    },
    "resume": true
  },
  "period_end": "string",
  "customer": {
    "id": "string",
    "name": "string",
    "email": "string",
    "phone": "string",
    "erased": true
  },
  "product": {
    "id": "string",
    "slug": "string",
    "path": "string",
    "url": "string",
    "title": "string",
    "category": "string",
    "deleted": true
  },
  "plan": {
    "created_at": "string",
    "id": "string",
    "price_id": "string",
    "amount": 0,
    "currency": "string",
    "exponent": 0,
    "period": {
      "unit": "string",
      "multiplier": 0
    },
    "autorenew": true
  },
  "periods": {
    "items": [
      {
        "id": "string",
        "subscription_id": "string",
        "starts_at": "string",
        "ends_at": "string",
        "status": "string",
        "lead_in": true,
        "settlement_id": "string",
        "grant_id": "string",
        "currency": "string",
        "exponent": 0,
        "amount": 0,
        "order": {
          "id": "string",
          "number": 0
        }
      }
    ],
    "total": 0
  },
  "scheduled_change": {
    "plan": {
      "created_at": "string",
      "id": "string",
      "price_id": "string",
      "amount": 0,
      "currency": "string",
      "exponent": 0,
      "period": {
        "unit": "string",
        "multiplier": 0
      },
      "autorenew": true
    },
    "effective_at": "string"
  },
  "id": "string",
  "customer_id": "string",
  "product_id": "string",
  "plan_id": "string",
  "processor": "string",
  "external_ref": "string",
  "account_ref": "string",
  "status": "string",
  "cancel_at_period_end": true,
  "instrument_ref": "string",
  "cancel_reason": "string",
  "created_at": "string",
  "ended_at": "string"
}
```

- `display_status` (`cancelSubscription.response.200.display_status`; string, required) — Its status as people read it: `cancelling` while it bills and is set to stop.
- `next_event` (`cancelSubscription.response.200.next_event`; any of, required) — What happens at the end of its latest paid period, as of the answer; null when nothing is ahead.
  - any of: `object`, `null`
- `actions` (`cancelSubscription.response.200.actions`; object, required) — The moves the store offers on it as of the answer; a write still decides again.
  - `cancel` (`cancelSubscription.response.200.actions.cancel`; object, required)
    - `period_end` (`cancelSubscription.response.200.actions.cancel.period_end`; boolean, required) — Stopping at the period's end: it bills, is not set to stop, and its period has not ended or is not known yet.
    - `now` (`cancelSubscription.response.200.actions.cancel.now`; boolean, required) — Ending it now, revoking what it paid for.
  - `resume` (`cancelSubscription.response.200.actions.resume`; boolean, required) — Taking a stop back: it still bills and is set to stop.
- `period_end` (`cancelSubscription.response.200.period_end`; any of, required) — When its period ends, as a cancel reads it; null for none, or once a period was refunded and none is paid.
  - any of: `string`, `null`
- `customer` (`cancelSubscription.response.200.customer`; any of, required)
  - any of: `object`, `null`
- `product` (`cancelSubscription.response.200.product`; any of, required)
  - any of: `object`, `null`
- `plan` (`cancelSubscription.response.200.plan`; any of, required)
  - any of: `object`, `null`
- `periods` (`cancelSubscription.response.200.periods`; object, required)
  - `items` (`cancelSubscription.response.200.periods.items`; array<object>, required)
    - `id` (`cancelSubscription.response.200.periods.items.id`; string, required)
    - `subscription_id` (`cancelSubscription.response.200.periods.items.subscription_id`; string, required)
    - `starts_at` (`cancelSubscription.response.200.periods.items.starts_at`; any of, required)
      - any of: `string`, `null`
    - `ends_at` (`cancelSubscription.response.200.periods.items.ends_at`; any of, required)
      - any of: `string`, `null`
    - `status` (`cancelSubscription.response.200.periods.items.status`; string, required)
    - `lead_in` (`cancelSubscription.response.200.periods.items.lead_in`; boolean, required) — A first period the customer's own grant covered, charged nothing; the plan's first charge pays the next.
    - `settlement_id` (`cancelSubscription.response.200.periods.items.settlement_id`; any of, required)
      - any of: `string`, `null`
    - `grant_id` (`cancelSubscription.response.200.periods.items.grant_id`; any of, required)
      - any of: `string`, `null`
    - `currency` (`cancelSubscription.response.200.periods.items.currency`; any of, required)
      - any of: `string`, `null`
    - `exponent` (`cancelSubscription.response.200.periods.items.exponent`; any of, required)
      - any of: `number`, `null`
    - `amount` (`cancelSubscription.response.200.periods.items.amount`; any of, required)
      - any of: `number`, `null`
    - `order` (`cancelSubscription.response.200.periods.items.order`; any of, required)
      - any of: `object`, `null`
  - `total` (`cancelSubscription.response.200.periods.total`; number, required)
- `scheduled_change` (`cancelSubscription.response.200.scheduled_change`; any of, required) — The plan it renews on from `effective_at`, the end of its paid run, as the customer scheduled; null for none.
  - any of: `object`, `null`
- `id` (`cancelSubscription.response.200.id`; string, required)
- `customer_id` (`cancelSubscription.response.200.customer_id`; string, required)
- `product_id` (`cancelSubscription.response.200.product_id`; string, required)
- `plan_id` (`cancelSubscription.response.200.plan_id`; string, required)
- `processor` (`cancelSubscription.response.200.processor`; any of, required)
  - any of: `string`, `null`
- `external_ref` (`cancelSubscription.response.200.external_ref`; any of, required)
  - any of: `string`, `null`
- `account_ref` (`cancelSubscription.response.200.account_ref`; any of, required)
  - any of: `string`, `null`
- `status` (`cancelSubscription.response.200.status`; string, required)
- `cancel_at_period_end` (`cancelSubscription.response.200.cancel_at_period_end`; boolean, required)
- `instrument_ref` (`cancelSubscription.response.200.instrument_ref`; any of, required)
  - any of: `string`, `null`
- `cancel_reason` (`cancelSubscription.response.200.cancel_reason`; any of, required)
  - any of: `string`, `null`
- `created_at` (`cancelSubscription.response.200.created_at`; any of, required)
  - any of: `string`, `null`
- `ended_at` (`cancelSubscription.response.200.ended_at`; any of, required)
  - any of: `string`, `null`

### default

A problem; see https://api.sherpo.io/merchant/docs/errors.

#### Example

```json
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "string",
  "context": {},
  "reached_core": true,
  "core_answer": "string"
}
```

- `type` (`cancelSubscription.response.default.type`; string, required)
  - format `uri`
- `title` (`cancelSubscription.response.default.title`; string, required)
- `status` (`cancelSubscription.response.default.status`; integer, required)
- `detail` (`cancelSubscription.response.default.detail`; string, required)
- `code` (`cancelSubscription.response.default.code`; string, optional)
- `context` (`cancelSubscription.response.default.context`; object, optional)
- `reached_core` (`cancelSubscription.response.default.reached_core`; boolean, optional)
- `core_answer` (`cancelSubscription.response.default.core_answer`; string, optional)


Source: https://docs.sherpo.io/merchant-api/reference/cancel-subscription/index.md
