Cancel a subscription at period end
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel \
--header 'X-API-Key: <api-key>'import requests
url = "https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel"
headers = {"X-API-Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'X-API-Key': '<api-key>'}};
fetch('https://merchant-api-prod.anyway.sh/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://merchant-api-prod.anyway.sh/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_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"data": {
"amountCents": 123,
"billingInterval": "DAY",
"cancelAtPeriodEnd": true,
"canceledAt": "<string>",
"createdAt": "<string>",
"currency": "<string>",
"currentPeriodEnd": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"endedAt": "<string>",
"id": "<string>",
"initialOrderId": "<string>",
"latestOrderId": "<string>",
"productId": "<string>",
"productName": "<string>",
"status": "<string>",
"subscriptionId": "<string>",
"updatedAt": "<string>"
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}Merchant API endpoints
Cancel a subscription
Schedule an active subscription to cancel at the end of its current billing period.
POST
/
v1
/
subscriptions
/
{id}
/
cancel
Cancel a subscription at period end
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel \
--header 'X-API-Key: <api-key>'import requests
url = "https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel"
headers = {"X-API-Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'X-API-Key': '<api-key>'}};
fetch('https://merchant-api-prod.anyway.sh/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://merchant-api-prod.anyway.sh/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_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/subscriptions/{id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"data": {
"amountCents": 123,
"billingInterval": "DAY",
"cancelAtPeriodEnd": true,
"canceledAt": "<string>",
"createdAt": "<string>",
"currency": "<string>",
"currentPeriodEnd": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"endedAt": "<string>",
"id": "<string>",
"initialOrderId": "<string>",
"latestOrderId": "<string>",
"productId": "<string>",
"productName": "<string>",
"status": "<string>",
"subscriptionId": "<string>",
"updatedAt": "<string>"
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}Authenticate with an API key that belongs to the target organization and has Full access or the
sales:subscriptions:write permission.
- Cancels at the end of the current billing period. The buyer keeps access until
currentPeriodEnd, andcancelAtPeriodEndbecomestrue. - Anyway emails the buyer the cancellation confirmation and sends the usual subscription Webhook. You do not need to send anything.
- Safe to retry: calling it again on a subscription already set to cancel returns
200with the same body. - The response is the same subscription object as Get a subscription record.
| Status | Code | Meaning |
|---|---|---|
403 | INSUFFICIENT_SCOPE | The key lacks sales:subscriptions:write. |
404 | Unknown subscription ID, or it belongs to another organization. | |
409 | SUBSCRIPTION_NOT_CANCELABLE | The subscription is not active (pending, paused, canceled, expired or ended). |
500 | INTERNAL_ERROR | Something failed on our side. The cancel may have taken effect; retrying is safe. |
502 | PROVIDER_ERROR | The payment provider call failed. The cancel may not have taken effect; retrying is safe. |