Generate Cancel Flow Link
curl --request POST \
--url https://api.revtain.com/api/cancel-flow/generate \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"customerId": "cus_abc123",
"customerEmail": "customer@example.com",
"subscriptionId": "sub_789",
"amount": 2900,
"currency": "USD",
"returnUrl": "https://app.yourdomain.com/account"
}
'import requests
url = "https://api.revtain.com/api/cancel-flow/generate"
payload = {
"customerId": "cus_abc123",
"customerEmail": "customer@example.com",
"subscriptionId": "sub_789",
"amount": 2900,
"currency": "USD",
"returnUrl": "https://app.yourdomain.com/account"
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customerId: 'cus_abc123',
customerEmail: 'customer@example.com',
subscriptionId: 'sub_789',
amount: 2900,
currency: 'USD',
returnUrl: 'https://app.yourdomain.com/account'
})
};
fetch('https://api.revtain.com/api/cancel-flow/generate', 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://api.revtain.com/api/cancel-flow/generate",
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([
'customerId' => 'cus_abc123',
'customerEmail' => 'customer@example.com',
'subscriptionId' => 'sub_789',
'amount' => 2900,
'currency' => 'USD',
'returnUrl' => 'https://app.yourdomain.com/account'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"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"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.revtain.com/api/cancel-flow/generate"
payload := strings.NewReader("{\n \"customerId\": \"cus_abc123\",\n \"customerEmail\": \"customer@example.com\",\n \"subscriptionId\": \"sub_789\",\n \"amount\": 2900,\n \"currency\": \"USD\",\n \"returnUrl\": \"https://app.yourdomain.com/account\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
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://api.revtain.com/api/cancel-flow/generate")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"cus_abc123\",\n \"customerEmail\": \"customer@example.com\",\n \"subscriptionId\": \"sub_789\",\n \"amount\": 2900,\n \"currency\": \"USD\",\n \"returnUrl\": \"https://app.yourdomain.com/account\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.revtain.com/api/cancel-flow/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customerId\": \"cus_abc123\",\n \"customerEmail\": \"customer@example.com\",\n \"subscriptionId\": \"sub_789\",\n \"amount\": 2900,\n \"currency\": \"USD\",\n \"returnUrl\": \"https://app.yourdomain.com/account\"\n}"
response = http.request(request)
puts response.read_body{
"url": "https://api.revtain.com/api/cancel-flow/abc123xyz...",
"token": "abc123xyz...",
"expiresAt": "2026-05-23T14:30:00.000Z"
}{
"error": "Validation failed.",
"details": {
"paymentMethodToken": [
"Payment method token is required"
],
"amount": [
"Amount must be a positive number"
]
}
}{
"error": "Unauthorized. Missing or invalid API key."
}{
"error": "Cancel flow is not enabled for this account.",
"message": "Contact Revtain to enable the hosted cancel flow for your account."
}Retention
Generate Cancel Flow Link
Generates a secure, time-limited URL for the hosted retention flow. When a customer clicks cancel in your app, send them to this URL — Revtain serves a branded page offering the retention options configured on your account (pause, discount, downgrade).
- URL is valid for 48 hours and can be used once
- When the customer makes a choice, you receive a
churn.flow.{outcome}webhook - Requires the cancel flow to be enabled on your account
POST
/
api
/
cancel-flow
/
generate
Generate Cancel Flow Link
curl --request POST \
--url https://api.revtain.com/api/cancel-flow/generate \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"customerId": "cus_abc123",
"customerEmail": "customer@example.com",
"subscriptionId": "sub_789",
"amount": 2900,
"currency": "USD",
"returnUrl": "https://app.yourdomain.com/account"
}
'import requests
url = "https://api.revtain.com/api/cancel-flow/generate"
payload = {
"customerId": "cus_abc123",
"customerEmail": "customer@example.com",
"subscriptionId": "sub_789",
"amount": 2900,
"currency": "USD",
"returnUrl": "https://app.yourdomain.com/account"
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customerId: 'cus_abc123',
customerEmail: 'customer@example.com',
subscriptionId: 'sub_789',
amount: 2900,
currency: 'USD',
returnUrl: 'https://app.yourdomain.com/account'
})
};
fetch('https://api.revtain.com/api/cancel-flow/generate', 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://api.revtain.com/api/cancel-flow/generate",
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([
'customerId' => 'cus_abc123',
'customerEmail' => 'customer@example.com',
'subscriptionId' => 'sub_789',
'amount' => 2900,
'currency' => 'USD',
'returnUrl' => 'https://app.yourdomain.com/account'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"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"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.revtain.com/api/cancel-flow/generate"
payload := strings.NewReader("{\n \"customerId\": \"cus_abc123\",\n \"customerEmail\": \"customer@example.com\",\n \"subscriptionId\": \"sub_789\",\n \"amount\": 2900,\n \"currency\": \"USD\",\n \"returnUrl\": \"https://app.yourdomain.com/account\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
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://api.revtain.com/api/cancel-flow/generate")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"cus_abc123\",\n \"customerEmail\": \"customer@example.com\",\n \"subscriptionId\": \"sub_789\",\n \"amount\": 2900,\n \"currency\": \"USD\",\n \"returnUrl\": \"https://app.yourdomain.com/account\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.revtain.com/api/cancel-flow/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customerId\": \"cus_abc123\",\n \"customerEmail\": \"customer@example.com\",\n \"subscriptionId\": \"sub_789\",\n \"amount\": 2900,\n \"currency\": \"USD\",\n \"returnUrl\": \"https://app.yourdomain.com/account\"\n}"
response = http.request(request)
puts response.read_body{
"url": "https://api.revtain.com/api/cancel-flow/abc123xyz...",
"token": "abc123xyz...",
"expiresAt": "2026-05-23T14:30:00.000Z"
}{
"error": "Validation failed.",
"details": {
"paymentMethodToken": [
"Payment method token is required"
],
"amount": [
"Amount must be a positive number"
]
}
}{
"error": "Unauthorized. Missing or invalid API key."
}{
"error": "Cancel flow is not enabled for this account.",
"message": "Contact Revtain to enable the hosted cancel flow for your account."
}Authorizations
Your Revtain API key (format: rev_xxx). Provided during onboarding.
Body
application/json
Your internal identifier for the customer.
Example:
"cus_abc123"
The customer's email address.
Example:
"customer@example.com"
Your internal subscription identifier. Echoed back on the churn webhook.
Example:
"sub_789"
The recurring charge in the smallest currency unit. Used to render the retention offer.
Required range:
x >= 0Example:
2900
3-letter ISO 4217 currency code.
Example:
"USD"
Where to send the customer after they complete the flow.
Example:
"https://app.yourdomain.com/account"
Response
Cancel flow link created