# post\_\_subscriptions\_cancel

`POST /subscriptions/cancel`

*Cancel Subscription*

Cancel the active subscription for the authenticated user's organization. This will immediately cancel the subscription in Stripe and create a cancellation record.

#### Parameters

This endpoint does not accept query parameters or request body. Authentication is required.

#### TypeScript Client Library

```typescript
public cancelSubscription = async (): Promise<CancelSubscriptionResponse> => {
  return this.makeRequest<CancelSubscriptionResponse>('subscriptions/cancel', 'POST', null);
};
```

#### Code Samples

{% tabs %}
{% tab title="Shell" %}

```shell
curl -X POST https://backend.flashback.tech/subscriptions/cancel \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}'
```

{% endtab %}

{% tab title="HTTP" %}

```http
POST https://backend.flashback.tech/subscriptions/cancel HTTP/1.1
Host: localhost:3000
Accept: application/json
Authorization: Bearer {access-token}
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('https://backend.flashback.tech/subscriptions/cancel',
{
  method: 'POST',
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.post 'https://backend.flashback.tech/subscriptions/cancel',
  nil, headers: headers

p JSON.parse(result)
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

r = requests.post('https://backend.flashback.tech/subscriptions/cancel', headers = headers)

print(r.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require 'vendor/autoload.php';

$headers = array(
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

try {
    $response = $client->request('POST','https://backend.flashback.tech/subscriptions/cancel', array(
        'headers' => $headers,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...
```

{% endtab %}

{% tab title="Java" %}

```java
URL obj = new URL("https://backend.flashback.tech/subscriptions/cancel");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    data := bytes.NewBuffer([]byte{})
    req, err := http.NewRequest("POST", "https://backend.flashback.tech/subscriptions/cancel", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}
```

{% endtab %}
{% endtabs %}

> Example responses

> 200 Response

```json
{
  "success": true,
  "message": "Subscription cancelled successfully"
}
```

> 400 Response (No Organization)

```json
{
  "success": false,
  "error_code": "NO_ORGANIZATION",
  "message": "User must belong to an organization"
}
```

> 400 Response (Already Cancelled)

```json
{
  "success": false,
  "error_code": "SUBSCRIPTION_ALREADY_CANCELLED",
  "message": "The subscription is already cancelled"
}
```

> 400 Response (Not Cancellable)

```json
{
  "success": false,
  "error_code": "SUBSCRIPTION_NOT_CANCELLABLE",
  "message": "The subscription cannot be cancelled. Current status: past_due"
}
```

> 400 Response (No Stripe ID)

```json
{
  "success": false,
  "error_code": "NO_STRIPE_SUBSCRIPTION_ID",
  "message": "The subscription does not have a valid Stripe ID"
}
```

> 400 Response (Stripe Not Found)

```json
{
  "success": false,
  "error_code": "STRIPE_SUBSCRIPTION_NOT_FOUND",
  "message": "Could not find the subscription in Stripe"
}
```

> 404 Response (User Not Found)

```json
{
  "success": false,
  "error_code": "USER_NOT_FOUND",
  "message": "User not found"
}
```

> 404 Response (No Active Subscription)

```json
{
  "success": false,
  "error_code": "NO_ACTIVE_SUBSCRIPTION",
  "message": "No active subscription found to cancel"
}
```

> 500 Response (Stripe Cancellation Failed)

```json
{
  "success": false,
  "error_code": "STRIPE_CANCELLATION_FAILED",
  "message": "Error cancelling the subscription in Stripe"
}
```

> 500 Response (Internal Error)

```json
{
  "success": false,
  "error_code": "INTERNAL_ERROR",
  "message": "Error processing subscription cancellation"
}
```

#### Responses <a href="#post__subscriptions_cancel-responses" id="post__subscriptions_cancel-responses"></a>

| Status | Meaning                                                                                             | Description                           | Schema |
| ------ | --------------------------------------------------------------------------------------------------- | ------------------------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)                                             | Subscription cancelled successfully   | Inline |
| 400    | [Bad Request](https://www.rfc-editor.org/rfc/rfc9110.html#name-400-bad-request)                     | Invalid request or subscription state | Inline |
| 404    | [Not Found](https://www.rfc-editor.org/rfc/rfc9110.html#name-404-not-found)                         | User or subscription not found        | Inline |
| 500    | [Internal Server Error](https://www.rfc-editor.org/rfc/rfc9110.html#name-500-internal-server-error) | Server or Stripe error                | Inline |

#### Response Schema <a href="#post__subscriptions_cancel-responseschema" id="post__subscriptions_cancel-responseschema"></a>

Status Code **200**

| Name      | Type    | Required | Restrictions | Description                             |
| --------- | ------- | -------- | ------------ | --------------------------------------- |
| » success | boolean | false    | none         | Indicates if the request was successful |
| » message | string  | false    | none         | Success message                         |

Status Code **400**

| Name          | Type    | Required | Restrictions | Description                       |
| ------------- | ------- | -------- | ------------ | --------------------------------- |
| » success     | boolean | false    | none         | Will be false for error responses |
| » error\_code | string  | false    | none         | Machine-readable error code       |
| » message     | string  | false    | none         | Human-readable error message      |

Status Code **404**

| Name          | Type    | Required | Restrictions | Description                       |
| ------------- | ------- | -------- | ------------ | --------------------------------- |
| » success     | boolean | false    | none         | Will be false for error responses |
| » error\_code | string  | false    | none         | Machine-readable error code       |
| » message     | string  | false    | none         | Human-readable error message      |

Status Code **500**

| Name          | Type    | Required | Restrictions | Description                       |
| ------------- | ------- | -------- | ------------ | --------------------------------- |
| » success     | boolean | false    | none         | Will be false for error responses |
| » error\_code | string  | false    | none         | Machine-readable error code       |
| » message     | string  | false    | none         | Human-readable error message      |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flashback.tech/support-reference/platform-api-reference/subscriptions/post__subscriptions_cancel.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
