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
- 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
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.Required. Amount in cents. For example, to represent 5.50, send
550.Example: 1000 (represents $10.00)Important: Always specify amounts in the smallest currency unit (cents for 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.Type of earning. Use this to categorize different earning types for reporting and analytics.Examples:
purchase- One-time purchase commissionsubscription- Subscription-based commissionrecurring- Recurring payment commissionbonus- Bonus or special promotion
purchaseHuman-readable description of the earning. This helps ambassadors understand what the earning is for.Example:
Commission from customer purchase - Order #12345Optional additional metadata about the earning. Use this to store custom information like order IDs, transaction IDs, commission rates, or other relevant data.Example:
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:Unique identifier for the newly created earning.
The referral ID that was provided in the request.
Amount in cents.
Currency code.
Type of earning (if provided).
Description of the earning (if provided).
Initial status of the earning, typically
pending.ISO 8601 timestamp of when the earning was created.
Response Example
Error Responses
Bad Request - Invalid request dataCommon causes:
- Missing required fields (referral_id, amount)
- Invalid amount (must be a positive number)
- Invalid referral_id (referral doesn’t exist)
- Invalid currency code
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
- Always use idempotency keys - Critical for webhook processing and retry logic
- Validate referral status - Ensure referral is
convertedbefore creating earnings - Store amounts in cents - Always convert dollar amounts to cents (multiply by 100)
- Include metadata - Store order IDs, transaction IDs, and commission rates for tracking
- Use descriptive types - Categorize earnings for better reporting
- Handle errors gracefully - Check for 400 errors and provide user-friendly messages
- 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:- Referred customer makes a purchase → Earning created (this endpoint)
- Earning status is
pending→ Ready for processing - Earning status changes to
processing→ Payout initiated - 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
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
The referral ID that this earning is associated with
Amount in cents (e.g., 1000 = $10.00)
Currency code (ISO 4217)
Type of earning (e.g., "purchase", "subscription", "recurring")
Description of the earning
Additional metadata about the earning
A unique key for idempotent requests
Response
Earning created successfully