Skip to main content
POST
Create a new earning when a referred customer spends money on your platform. This endpoint is typically called when processing a purchase, subscription, or other transaction from a referred customer.

Overview

The Create Earning endpoint allows you to record commissions and earnings for student ambassadors when their referrals make purchases. This is a critical endpoint that:
  • Links earnings to specific referrals
  • Tracks commission amounts and currency
  • Records earning type and description
  • Enables payout processing
  • Supports idempotent requests to prevent duplicates
Use this endpoint to:
  • Record commissions from customer purchases
  • Track subscription-based earnings
  • Create recurring earnings
  • Process one-time payments
  • Enable automated payout systems

Authentication

This endpoint requires authentication using a Bearer token in the Authorization header:

Request Body

string
required
Required. The ID of the referral that generated this earning. This links the earning back to the original signup and ambassador.Example: ref_123abcNote: The referral must exist in your system and typically should have a status of converted.
number
required
Required. Amount in cents. For example, to represent 10.00,send1000.Torepresent10.00, send `1000`. To represent 5.50, send 550.Example: 1000 (represents $10.00)Important: Always specify amounts in the smallest currency unit (cents for USD).
string
default:"USD"
Currency code in ISO 4217 format. Defaults to “USD” if not specified.Examples: USD, EUR, GBP, CADNote: Ensure the currency matches your program’s payout currency.
string
Type of earning. Use this to categorize different earning types for reporting and analytics.Examples:
  • purchase - One-time purchase commission
  • subscription - Subscription-based commission
  • recurring - Recurring payment commission
  • bonus - Bonus or special promotion
Example: purchase
string
Human-readable description of the earning. This helps ambassadors understand what the earning is for.Example: Commission from customer purchase - Order #12345
object
Optional additional metadata about the earning. Use this to store custom information like order IDs, transaction IDs, commission rates, or other relevant data.Example:
string
Optional unique key for idempotent requests. If you send the same idempotency_key within a short time window, the API will return the same earning instead of creating a duplicate. This is essential for retry logic and webhook processing.Example: earn_20240115_order12345Best Practice: Use a combination of order/transaction ID and timestamp to ensure uniqueness.

Request Example

Response

On success, the API returns the created earning object:
string
required
Unique identifier for the newly created earning.
string
required
The referral ID that was provided in the request.
number
required
Amount in cents.
string
required
Currency code.
string
Type of earning (if provided).
string
Description of the earning (if provided).
string
required
Initial status of the earning, typically pending.
string
required
ISO 8601 timestamp of when the earning was created.

Response Example

Error Responses

object
Bad Request - Invalid request data
Common causes:
  • Missing required fields (referral_id, amount)
  • Invalid amount (must be a positive number)
  • Invalid referral_id (referral doesn’t exist)
  • Invalid currency code
object
Unauthorized - Invalid or missing API key

Use Cases

Processing Purchase Webhooks

When a referred customer makes a purchase, create an earning:

Creating Subscription Earnings

Process recurring subscription commissions:

Idempotent Earning Creation

Use idempotency keys to prevent duplicate earnings:

Best Practices

  1. Always use idempotency keys - Critical for webhook processing and retry logic
  2. Validate referral status - Ensure referral is converted before creating earnings
  3. Store amounts in cents - Always convert dollar amounts to cents (multiply by 100)
  4. Include metadata - Store order IDs, transaction IDs, and commission rates for tracking
  5. Use descriptive types - Categorize earnings for better reporting
  6. Handle errors gracefully - Check for 400 errors and provide user-friendly messages
  7. Link to external systems - Store reference IDs in metadata for payment processing

Amount Conversion

Remember to convert dollar amounts to cents:

Workflow

The typical earning creation workflow:
  1. Referred customer makes a purchase → Earning created (this endpoint)
  2. Earning status is pending → Ready for processing
  3. Earning status changes to processing → Payout initiated
  4. Earning status changes to paid → Commission paid to ambassador

Rate Limits

This endpoint is subject to rate limiting. Check response headers for rate limit information.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
referral_id
string
required

The referral ID that this earning is associated with

amount
number
required

Amount in cents (e.g., 1000 = $10.00)

currency
string
default:USD

Currency code (ISO 4217)

type
string

Type of earning (e.g., "purchase", "subscription", "recurring")

description
string

Description of the earning

metadata
object

Additional metadata about the earning

idempotency_key
string

A unique key for idempotent requests

Response

Earning created successfully