Subscriptions
Cancel Subscription
Cancel a subscription
POST
/
v1
/
subscriptions
/
{id}
/
cancel
Cancel a subscription
curl --request POST \
--url https://billing.example.com/v1/subscriptions/{id}/cancel \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"cancel_at_period_end": true,
"immediately": true,
"feedback": "<string>",
"revoke_consent": true
}
'import requests
url = "https://billing.example.com/v1/subscriptions/{id}/cancel"
payload = {
"cancel_at_period_end": True,
"immediately": True,
"feedback": "<string>",
"revoke_consent": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
cancel_at_period_end: true,
immediately: true,
feedback: '<string>',
revoke_consent: true
})
};
fetch('https://billing.example.com/v1/subscriptions/{id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/subscriptions/{id}/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cancel_at_period_end' => true,
'immediately' => true,
'feedback' => '<string>',
'revoke_consent' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/subscriptions/{id}/cancel"
payload := strings.NewReader("{\n \"cancel_at_period_end\": true,\n \"immediately\": true,\n \"feedback\": \"<string>\",\n \"revoke_consent\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://billing.example.com/v1/subscriptions/{id}/cancel")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"cancel_at_period_end\": true,\n \"immediately\": true,\n \"feedback\": \"<string>\",\n \"revoke_consent\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/subscriptions/{id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cancel_at_period_end\": true,\n \"immediately\": true,\n \"feedback\": \"<string>\",\n \"revoke_consent\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "<string>",
"cancel_at_period_end": true,
"cancelled_at": "2023-11-07T05:31:56Z",
"current_period_end": "2023-11-07T05:31:56Z",
"cancellation_reason": "<string>",
"message": "<string>"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The subscription ID |
Request Body
| Parameter | Type | Description |
|---|---|---|
cancel_at_period_end | boolean | Cancel at end of period (default: true) |
immediately | boolean | Cancel immediately |
reason | string | Cancellation reason |
Example Request
curl -X POST https://api.recurso.dev/v1/subscriptions/sub_xyz/cancel \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"cancel_at_period_end": true,
"reason": "switching_to_competitor"
}'
Response
{
"id": "sub_xyz789",
"object": "subscription",
"status": "active",
"cancel_at_period_end": true,
"cancelled_at": "2024-01-15T10:30:00Z",
"cancellation_reason": "switching_to_competitor",
"current_period_end": "2024-02-15T00:00:00Z"
}
When
cancel_at_period_end is true, the subscription remains active until current_period_end.Errors
| Status | Code | When | Fix |
|---|---|---|---|
| 400 | validation_failed | id is not a valid UUID, or the request body is malformed JSON. | Pass the subscription’s UUID and a valid JSON body (an empty {} is fine). |
| 401 | unauthorized | API key missing or invalid (invalid_api_key), or a live/test mode mismatch (key_mode_mismatch). | Send Authorization: Bearer <api_key> with a key for the right mode. |
| 404 | not_found | The subscription does not exist in your tenant. | Verify the ID with GET /v1/subscriptions/{id}. |
| 500 | internal_error | Cancellation failed mid-flight. | Retry — canceling an already-canceled subscription is a safe no-op. |
Authorizations
Tenant API key obtained from POST /auth/register or POST /v1/developer/keys.
Path Parameters
Body
application/json
Available options:
too_expensive, not_using, switching_competitor, missing_features, technical_issues, customer_service, temporary_pause, other Defaults to true when immediately is false.
Also revoke the recurring-payment consent (RBI compliance).
⌘I
Cancel a subscription
curl --request POST \
--url https://billing.example.com/v1/subscriptions/{id}/cancel \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"cancel_at_period_end": true,
"immediately": true,
"feedback": "<string>",
"revoke_consent": true
}
'import requests
url = "https://billing.example.com/v1/subscriptions/{id}/cancel"
payload = {
"cancel_at_period_end": True,
"immediately": True,
"feedback": "<string>",
"revoke_consent": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
cancel_at_period_end: true,
immediately: true,
feedback: '<string>',
revoke_consent: true
})
};
fetch('https://billing.example.com/v1/subscriptions/{id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/subscriptions/{id}/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cancel_at_period_end' => true,
'immediately' => true,
'feedback' => '<string>',
'revoke_consent' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/subscriptions/{id}/cancel"
payload := strings.NewReader("{\n \"cancel_at_period_end\": true,\n \"immediately\": true,\n \"feedback\": \"<string>\",\n \"revoke_consent\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://billing.example.com/v1/subscriptions/{id}/cancel")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"cancel_at_period_end\": true,\n \"immediately\": true,\n \"feedback\": \"<string>\",\n \"revoke_consent\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/subscriptions/{id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cancel_at_period_end\": true,\n \"immediately\": true,\n \"feedback\": \"<string>\",\n \"revoke_consent\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "<string>",
"cancel_at_period_end": true,
"cancelled_at": "2023-11-07T05:31:56Z",
"current_period_end": "2023-11-07T05:31:56Z",
"cancellation_reason": "<string>",
"message": "<string>"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}