Retrieve All Scheduled Invoices

Finds and lists all scheduled invoices under a merchant's account.

Retrieve scheduled invoices for your merchant account with GET /invoice/schedule in your API integration.

This reference is for developers. The example below only reads schedules; it does not create invoices or change billing schedules. You do not need a customer ID or schedule ID to list schedules.

Retrieve your scheduled invoices

  1. Install Python 3 to run the example without third-party packages.
  2. Select your sandbox (a test environment) from the merchant switcher in the upper-right corner of Stax Pay, then copy your merchant API key from Stax Pay > Apps > API Keys. An API key is a credential that authorizes requests for your selected merchant account; keep it private.
  3. Save the code below as list_schedules.py and run python3 list_schedules.py. Enter your API key at the hidden prompt. The example explicitly sorts by creation time, newest first, and retrieves the first page without optional filters.
import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode
from urllib.request import Request, urlopen

api_key = getpass.getpass("Merchant API key: ").strip()
if not api_key:
    sys.exit("Enter a merchant API key.")

query = urlencode({"sort": "created_at", "order": "DESC"})
request = Request(
    f"https://apiprod.fattlabs.com/invoice/schedule?{query}",
    headers={
        "Authorization": f"Bearer {api_key}",
        "Accept": "application/json",
    },
    method="GET",
)

try:
    with urlopen(request, timeout=30) as response:
        status = response.status
        body = response.read().decode("utf-8", errors="replace")
except HTTPError as error:
    detail = error.read().decode("utf-8", errors="replace")
    guidance = {
        400: "Check the query parameter names and values.",
        401: "Check your merchant API key and selected account.",
        500: "A server error occurred; retry the read request later.",
    }.get(error.code, "Review the response details.")
    sys.exit(f"HTTP {error.code}: {guidance}\n{detail}")
except (URLError, TimeoutError, OSError) as error:
    sys.exit(f"Request failed: {error}. Check your connection and retry.")

if status != 200:
    sys.exit(f"Unexpected HTTP {status}.\n{body}")

try:
    result = json.loads(body)
except json.JSONDecodeError:
    sys.exit("HTTP 200 returned a non-JSON response.")

if not isinstance(result, dict) or not isinstance(result.get("data"), list):
    sys.exit("Unexpected response: expected an object with a data array.")

schedules = result["data"]
if any(not isinstance(item, dict) or not isinstance(item.get("id"), str)
       for item in schedules):
    sys.exit("Unexpected response: a schedule is missing a string ID.")

print("HTTP 200: Scheduled invoices retrieved.")
if not schedules:
    print("No scheduled invoices on this page.")
else:
    for schedule in schedules:
        # Use the returned ID for later operations; no Dashboard ID is required.
        print(f"Schedule ID: {schedule['id']}")

if result.get("next_page_url"):
    print("More results are available; request the next page.")
else:
    print("No more pages.")

With the schedule shown in the endpoint's response example, the output is:

HTTP 200: Scheduled invoices retrieved.
Schedule ID: 320c909f-7808-465f-b519-5d906bf615f8
No more pages.

Your schedule IDs and page count will differ. An empty page prints No scheduled invoices on this page. A successful request returns HTTP 200 and a JSON object whose data array contains the schedules on that page.


Key Features

  • Returns all scheduled invoices associated with a merchant account.
  • Provides default sorting by created_at in descending order (newest first).
  • Enables filtering and ordering based on various parameters.
  • Supports pagination for handling large datasets.

Optional: Sort, filter, paginate, or manage schedules

Default Sorting: Results are sorted by created_at in descending order.

Custom Sorting: Use query parameters to sort by other fields, such as next_run_at or status.

Filtering: Include parameters like status (e.g., active, paused, deleted) or customer-specific identifiers to refine the results.



Optional: Choose a sort field

Sort ParameterDescriptionExample Query
last_run_atSorts by the most recent time the schedule was run.?sort=last_run_at&order=DESC (latest first)
next_run_atSorts by the next scheduled run time.?sort=next_run_at&order=ASC (earliest first)
countSorts numerically by the total number of runs.?sort=count&order=DESC (highest first)
created_atSorts by the creation time of the schedule.?sort=created_at&order=ASC (oldest first)
updated_atSorts by the last time the schedule was updated.?sort=updated_at&order=DESC (most recent first)

Additional Notes

  • Use the order parameter to define the sorting direction:
    • DESC: Descending order (e.g., newest, latest, highest).
    • ASC: Ascending order (e.g., oldest, earliest, lowest).

Response Structure

CodeResponseReason
200SuccessReturns a paginated list of scheduled invoices.
400Bad RequestInvalid query parameters or missing required fields.
401UnauthorizedAuthentication failed.
500Internal Server ErrorUnexpected server error.

Important Considerations

  • Schedule Management: Use this endpoint to monitor and manage active, paused, or deleted schedules.
  • Deleted Schedules: Scheduled invoices marked as deleted will not generate new invoices.
  • Pagination Best Practices: For large datasets, implement pagination to ensure optimal performance and usability.
  • Audit Trail: Scheduled invoices include timestamps and metadata for tracking purposes. Use this information to reconcile or audit scheduled billing activities.
Query Params
string

Used to filter results by customer

string
enum
Allowed:
string
enum
Allowed:
Responses

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