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

# 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




## OpenAPI

````yaml /api-reference/openapi.yaml post /api/cancel-flow/generate
openapi: 3.0.3
info:
  title: Revtain API
  description: >
    Recover failed payments. No checkout changes. Works with your existing
    payment stack.


    ## Choose Your Path


    **Using Chargebee, Recurly, Stripe Billing, Braintree, Zuora, or Shopify
    (ReCharge)?**

    Use a Connector — paste one webhook URL, no code, 5 minutes.


    **Custom billing system or want full API control?**

    Use the Recovery Engine directly. The quickstart gets you to a working
    recovery call in 60 seconds.


    ## Authentication


    Pass your API key via the `X-API-KEY` header on all requests:


    ```

    X-API-KEY: rev_dTviCg52T8gLPCjrrW4KA0NKf_f5pQgk

    ```


    Keep this secret. Your API key can trigger charges. Never expose it in
    client-side code, public repos, or logs.


    ## Base URL


    ```

    https://api.revtain.com

    ```


    Same URL for testing and production. Test mode is controlled by your gateway
    type — onboard with a test gateway (e.g., Stripe `sk_test_...`) for sandbox,
    live key for production.
  version: 1.0.0
  contact:
    email: support@revtain.com
servers:
  - url: https://api.revtain.com
    description: Production & Sandbox (test mode controlled by gateway key)
security:
  - ApiKeyAuth: []
tags:
  - name: Recovery Engine
    description: Trigger and track payment recovery attempts
  - name: Predictive Risk Engine
    description: Pre-screen payments before they fail
  - name: Retention
    description: Hosted cancel flow to reduce voluntary churn
  - name: Health
    description: Service health check
paths:
  /api/cancel-flow/generate:
    post:
      tags:
        - Retention
      summary: Generate Cancel Flow Link
      description: >
        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
      operationId: generateCancelFlowLink
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateCancelFlowRequest'
            example:
              customerId: cus_abc123
              customerEmail: customer@example.com
              subscriptionId: sub_789
              amount: 2900
              currency: USD
              returnUrl: https://app.yourdomain.com/account
      responses:
        '201':
          description: Cancel flow link created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateCancelFlowResponse'
              example:
                url: https://api.revtain.com/api/cancel-flow/abc123xyz...
                token: abc123xyz...
                expiresAt: '2026-05-23T14:30:00.000Z'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedError'
        '403':
          description: Cancel flow is not enabled for this account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeatureNotEnabledError'
components:
  schemas:
    GenerateCancelFlowRequest:
      type: object
      required:
        - customerId
      properties:
        customerId:
          type: string
          description: Your internal identifier for the customer.
          example: cus_abc123
        customerEmail:
          type: string
          format: email
          description: The customer's email address.
          example: customer@example.com
        subscriptionId:
          type: string
          description: >-
            Your internal subscription identifier. Echoed back on the churn
            webhook.
          example: sub_789
        amount:
          type: integer
          minimum: 0
          description: >-
            The recurring charge in the smallest currency unit. Used to render
            the retention offer.
          example: 2900
        currency:
          type: string
          description: 3-letter ISO 4217 currency code.
          example: USD
        returnUrl:
          type: string
          format: uri
          description: Where to send the customer after they complete the flow.
          example: https://app.yourdomain.com/account
    GenerateCancelFlowResponse:
      type: object
      properties:
        url:
          type: string
          format: uri
          description: The hosted retention page URL to send the customer to.
          example: https://api.revtain.com/api/cancel-flow/abc123xyz...
        token:
          type: string
          example: abc123xyz...
        expiresAt:
          type: string
          format: date-time
          description: The URL is valid for 48 hours and can be used once.
          example: '2026-05-23T14:30:00.000Z'
    ValidationError:
      type: object
      properties:
        error:
          type: string
          example: Validation failed.
        details:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
          example:
            paymentMethodToken:
              - Payment method token is required
            amount:
              - Amount must be a positive number
    UnauthorizedError:
      type: object
      properties:
        error:
          type: string
          example: Unauthorized. Missing or invalid API key.
    FeatureNotEnabledError:
      type: object
      properties:
        error:
          type: string
          example: Cancel flow is not enabled for this account.
        message:
          type: string
          example: Contact Revtain to enable the hosted cancel flow for your account.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
      description: 'Your Revtain API key (format: `rev_xxx`). Provided during onboarding.'

````