Delete an Invoice Schedule

Deletes a recurring invoice schedule. This operation requires merchant authentication.

Use this API endpoint to stop future charges for a scheduled invoice (an invoice configured to run on a recurring schedule) in a merchant's account.

This operation performs a soft delete: it keeps the schedule's record in the database but prevents the merchant and customers from accessing it. It requires merchant authentication.

Delete a schedule

  1. Install Python 3 to run the example without additional packages.
  2. Copy your merchant API key (a credential scoped to one merchant account) from Stax Pay > Apps > API Keys. Keep the key private; the example prompts for it without displaying it.
  3. Call Retrieve All Scheduled Invoices with the same merchant key and copy the target schedule's id from the response's data array. For example, 320c909f-7808-465f-b519-5d906bf615f8 shows the ID format; use the ID of the schedule you intend to delete. The id path parameter is a required string and has no documented default.
  4. Save the following code as delete_schedule.py, then run python3 delete_schedule.py. Enter your key and schedule ID, verify the target, and type DELETE to stop its future charges.

The example uses the documented production URL, sends no request body, and does not retry automatically. Confirm the target carefully: this request changes the merchant's schedule.

import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.parse import quote
from urllib.request import Request, urlopen


def main():
    api_key = getpass.getpass("Merchant API key: ").strip()
    # Copy the schedule's id from GET /invoice/schedule, not its customer_id.
    schedule_id = input("Schedule ID to delete: ").strip()
    if not api_key or not schedule_id:
        sys.exit("No request sent: both the API key and schedule ID are required.")

    if input(f"Type DELETE to delete schedule {schedule_id}: ") != "DELETE":
        print("Cancelled. No request sent.")
        return

    request = Request(
        "https://apiprod.fattlabs.com/invoice/schedule/"
        + quote(schedule_id, safe=""),
        headers={
            "Authorization": f"Bearer {api_key}",
            "Accept": "application/json",
        },
        method="DELETE",
    )
    try:
        # A timeout limits waiting; it does not prove the server rejected deletion.
        with urlopen(request, timeout=30) as response:
            status = response.status
            body = response.read().decode("utf-8")
    except HTTPError as error:
        sys.exit(f"HTTP {error.code}: {error.read().decode('utf-8', errors='replace')}")
    except (URLError, TimeoutError, OSError) as error:
        sys.exit(f"Request failed: {error}. Verify the schedule state before retrying.")

    try:
        schedule = json.loads(body)
    except ValueError:
        sys.exit(f"HTTP {status}: response was not JSON. Verify the schedule state.")

    if status != 200 or not isinstance(schedule, dict):
        sys.exit(f"Unexpected response (HTTP {status}): {body}")
    if (not schedule.get("deleted_at")
            or schedule.get("next_run_at", "missing") is not None
            or schedule.get("future_occurrences") != []):
        sys.exit("Deletion not confirmed. Inspect the returned schedule: " + body)

    print("Deletion confirmed: future charges stopped.")
    print(json.dumps({key: schedule.get(key) for key in (
        "id", "deleted_at", "next_run_at", "future_occurrences", "active"
    )}, indent=2))


if __name__ == "__main__":
    main()

Verify deletion

After a successful deletion, the API returns HTTP 200 with the updated schedule:

  • deleted_at contains the time of deletion.
  • next_run_at is null.
  • future_occurrences is an empty array ([]).
  • active retains its previous value; deletion does not change the schedule's active state.

A non-null deleted_at value marks the schedule as deleted, so the merchant and customers can no longer access it and it stops generating future charges.

For the documented example response, the script prints the following fields. Your schedule ID, deletion time, and previous active value will differ:

Deletion confirmed: future charges stopped.
{
  "id": "320c909f-7808-465f-b519-5d906bf615f8",
  "deleted_at": "2025-07-02 19:03:38",
  "next_run_at": null,
  "future_occurrences": [],
  "active": true
}

Troubleshoot a failed request

  • If the API returns an HTTP error, inspect the status and response body printed by the script. Confirm that you used the target merchant's key and copied the schedule's id, not its customer_id.
  • If the connection fails or times out, verify the schedule state before retrying; a lost response does not prove that deletion failed.
  • If the response is empty, is not JSON, or lacks the expected deletion fields, treat deletion as unconfirmed and inspect the schedule state before sending another request.
Path Params
string
required
Response

Language
Credentials
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json