LostChurn Docs
API Reference

Errors & Rate Limits

Detailed error response contracts, rate limiting behavior, IP allowlisting, and pagination reference for the LostChurn API v1.

This page provides a detailed reference for API error responses, rate limiting, IP allowlisting, and pagination. For a general overview of the API, see API Overview.

Error Response Format

All API errors return a consistent JSON structure with an error object:

{
  "error": {
    "code": "error_code_string",
    "message": "Human-readable description of the error.",
    "param": "field_name",
    "request_id": "req_abc123def456"
  }
}

Error Object Fields

FieldTypeAlways PresentDescription
codestringYesMachine-readable error code (see table below)
messagestringYesHuman-readable error description
paramstringNoThe request parameter that caused the error (validation errors only)
request_idstringYesUnique request ID for support and debugging

Error Codes Reference

Error CodeHTTP StatusDescription
invalid_request400The request is malformed or missing required fields
invalid_api_key401The API key is invalid, expired, or revoked
insufficient_scope403The API key does not have the required scope for this operation
trial_expired403Your trial has expired. Upgrade to continue using write endpoints
ip_not_allowed403The request IP address is not in your IP allowlist
resource_not_found404The requested resource does not exist
state_conflict409The resource is in a state that does not allow this operation
validation_error422One or more fields failed validation
rate_limit_exceeded429Too many requests. Retry after the specified delay
internal_error500An unexpected error occurred on the server

Error Response Examples

401 Unauthorized

Returned when the API key is missing, invalid, expired, or revoked.

curl https://api.lostchurn.com/v1/payments \
  -H "Authorization: Bearer lc_live_invalid_key"
{
  "error": {
    "code": "invalid_api_key",
    "message": "The API key provided is invalid or has been revoked.",
    "request_id": "req_1a2b3c4d5e6f"
  }
}

Common causes:

  • API key was revoked from Settings > API Keys
  • Key rotation grace period (24 hours) has expired for the old key
  • Typo in the API key string
  • Using a test key (lc_test_*) against production data or vice versa

403 Forbidden

Returned when the API key is valid but lacks permission for the requested operation.

# Using a read-only key to trigger a retry
curl -X POST https://api.lostchurn.com/v1/payments/pay_abc123/retry \
  -H "Authorization: Bearer lc_live_readonly_key"
{
  "error": {
    "code": "insufficient_scope",
    "message": "This API key does not have the 'write' scope required for POST /v1/payments/:id/retry.",
    "request_id": "req_7g8h9i0j1k2l"
  }
}

Common causes:

  • API key was created with limited scopes (e.g., read only)
  • Attempting admin operations with a non-admin key
  • Trial expired -- write endpoints return trial_expired until you upgrade

429 Too Many Requests

Returned when the rate limit is exceeded.

{
  "error": {
    "code": "rate_limit_exceeded",
    "message": "Rate limit exceeded. Retry after 32 seconds.",
    "retry_after": 32
  }
}

The response includes a retry_after field (in seconds) and the following headers:

HeaderExampleDescription
X-RateLimit-Limit100Maximum requests per window
X-RateLimit-Remaining0Requests remaining in the current window
X-RateLimit-Reset1710000032Unix timestamp when the window resets
Retry-After32Seconds until the rate limit resets

Rate Limiting

API requests are rate-limited per merchant (identified by API key). The rate limit window is a sliding 60-second window.

Limits by Plan

PlanRequests per 60 seconds
Recovery Engine20
Revenue Recovery System100
Revenue Command100
Enterprise1,000 (customizable)

Rate Limit Headers

Every API response includes rate limit headers, even successful responses:

HTTP/1.1 200 OK
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 87
X-RateLimit-Reset: 1710000060

Best Practices for Rate Limits

PracticeDetails
Check headersMonitor X-RateLimit-Remaining to avoid hitting limits
Implement backoffOn 429, wait for Retry-After seconds before retrying
Batch where possibleUse list endpoints with filters instead of fetching records individually
Cache responsesCache analytics and configuration data that does not change frequently
Use webhooksFor real-time updates, subscribe to outbound webhooks instead of polling

IP Allowlisting

For additional security, you can restrict API access to specific IP addresses or CIDR ranges. When an IP allowlist is configured, requests from unlisted IPs are rejected with a 403 response.

Configuring IP Allowlisting

  1. Go to Settings > API Keys > IP Allowlist.
  2. Click Add IP Address.
  3. Enter an IPv4 address (e.g., 203.0.113.42) or CIDR range (e.g., 203.0.113.0/24).
  4. Click Save.

Enabling the IP allowlist immediately blocks requests from unlisted IPs. Make sure your server's egress IP addresses are added before enabling this feature. If you lock yourself out, contact support@lostchurn.com.

IP Allowlist Behavior

ScenarioResult
Allowlist empty (default)All IPs allowed
Allowlist has entriesOnly listed IPs/ranges allowed
Request from unlisted IP403 with ip_not_allowed error code
Webhook deliveriesNot affected by allowlist (outbound from LostChurn)

Pagination

All list endpoints return paginated results. LostChurn uses page-based pagination.

Query Parameters

ParameterTypeDefaultRangeDescription
pageinteger11 to 10,000Page number
per_pageinteger201 to 100Results per page

Pagination Response

Every list response includes a pagination object:

{
  "data": [ ... ],
  "pagination": {
    "total": 1423,
    "page": 3,
    "per_page": 20,
    "total_pages": 72
  }
}
FieldTypeDescription
totalintegerTotal number of records matching the query
pageintegerCurrent page number
per_pageintegerNumber of results per page
total_pagesintegerTotal number of pages

Pagination Example

# Fetch page 3 with 50 results per page
curl "https://api.lostchurn.com/v1/payments?page=3&per_page=50&status=pending" \
  -H "Authorization: Bearer lc_live_your_api_key"

Iterating Through All Pages

async function fetchAllPayments(apiKey) {
  let page = 1;
  let allPayments = [];

  while (true) {
    const response = await fetch(
      `https://api.lostchurn.com/v1/payments?page=${page}&per_page=100`,
      { headers: { Authorization: `Bearer ${apiKey}` } }
    );
    const { data, pagination } = await response.json();

    allPayments = allPayments.concat(data);

    if (page >= pagination.total_pages) break;
    page++;
  }

  return allPayments;
}

For large datasets, consider using date range filters (created_after, created_before) to limit the result set rather than iterating through thousands of pages. This is both faster and more efficient on your rate limit budget.

Key Endpoint Quick Reference

For full documentation of each endpoint, see the dedicated API reference pages.

Payments

MethodEndpointScopesReference
GET/v1/paymentsreadPayments API
GET/v1/payments/:idreadPayments API
POST/v1/payments/:id/retrywritePayments API

Customers

MethodEndpointScopesReference
GET/v1/customersreadCustomers API
GET/v1/customers/:idreadCustomers API
DELETE/v1/customers/:idadminCustomers API

Campaigns

MethodEndpointScopesReference
GET/v1/campaignsreadCampaigns API
POST/v1/campaignswriteCampaigns API
PUT/v1/campaigns/:idwriteCampaigns API
DELETE/v1/campaigns/:idwriteCampaigns API

Analytics

MethodEndpointScopesReference
GET/v1/analytics/recoveryread or analyticsAnalytics API
GET/v1/analytics/campaignsread or analyticsAnalytics API

Webhooks

MethodEndpointScopesReference
GET/v1/webhookswebhooksWebhooks API
POST/v1/webhookswebhooksWebhooks API
PUT/v1/webhooks/:idwebhooksWebhooks API
DELETE/v1/webhooks/:idwebhooksWebhooks API

Authentication

MethodEndpointScopesReference
GET/v1/auth/meAnyAuthentication

Authentication Quick Reference

All API requests require a Bearer token in the Authorization header:

curl https://api.lostchurn.com/v1/payments \
  -H "Authorization: Bearer lc_live_your_api_key"

Key Prefixes

PrefixEnvironmentUsage
lc_live_ProductionLive payment data, real retries
lc_test_SandboxTest data, simulated retries
lc_pub_Client-sideRead-only, widget-only access

For complete authentication documentation including key generation, scopes, and rotation, see Authentication.

Next Steps

On this page