The Xagle Commission API
The Commission API lets an outside system post finished commission amounts into Xagle's commission ledger. Xagle does not apply that system's rules: it registers the sales reps, stores each amount under the caller's own reference, refuses to change money once it has been approved or paid, shows a running estimate per rep exactly as it was posted, and turns approved amounts into real payouts. It is built for a sales front end (appointment setters, influencer programmes) that calculates what a rep has earned and wants Xagle to be the book of record.
All endpoints require authentication: POST /api/v1/login with email + password returns {"token": "..."}; pass it as Authorization: Bearer {token} on every call. Responses follow the standard envelope: {"success": true, "message": "...", "data": ...} on success, {"success": false, "message": "..."} on failure, and {"success": false, "errors": {field: [...]}} with HTTP 422 on validation failure. The Commission add-on must be enabled for the account; otherwise every endpoint answers 404.
Status codes: 200 read or updated, 201 created, 400 the ledger refused the change (for example a status move that is not allowed), 403 the token's user lacks the permission, 404 not found, 409 the record exists already or is locked, 422 validation failure.
Permissions: the token's user needs the Commission module permissions: commission.view to read, commission.create to post entries, reps and summaries, commission.update to move an entry's status, commission.approve to set an entry to approved and commission.pay to create or pay a payout or set an entry to paid. A standard (non-admin) user's token only ever sees and touches the rep linked to that user.
Endpoints
| Operation | Endpoint | Permission |
|---|---|---|
| List sales reps | GET /api/v1/commission/reps | view |
| Find a rep by the caller's own id | GET /api/v1/commission/reps/lookup?external_system=…&external_id=… | view |
| Show a rep | GET /api/v1/commission/reps/{id} | view |
| Create a rep | POST /api/v1/commission/reps | create |
| List ledger entries | GET /api/v1/commission/entries | view |
| Show an entry | GET /api/v1/commission/entries/{id} or GET /api/v1/commission/entries/{external_system}/{external_ref} | view |
| Post (create or update) an entry | PUT /api/v1/commission/entries/{external_system}/{external_ref} | create |
| Post many entries | POST /api/v1/commission/entries/batch | create |
| Move an entry's status | POST /api/v1/commission/entries/{id}/status or POST /api/v1/commission/entries/{external_system}/{external_ref}/status | update (+ approve / pay) |
| List period summaries | GET /api/v1/commission/period-summaries | view |
| Show a rep's period summary | GET /api/v1/commission/period-summaries/{sales_rep_id}/{period} | view |
| Store a rep's period summary | PUT /api/v1/commission/period-summaries/{sales_rep_id}/{period} | create |
| List payouts | GET /api/v1/commission/payouts | view |
| Show a payout | GET /api/v1/commission/payouts/{id} | view |
| Create a payout | POST /api/v1/commission/payouts | pay |
| Mark a payout paid | POST /api/v1/commission/payouts/{id}/pay | pay |
How the ledger treats what you post
Every posted amount becomes one ledger entry for one sales rep, keyed by external_system (a short name for the caller, for example agenthq) and external_ref (the caller's own id for that commission, for example demo-4821 or 2026-03-setter-17-tier). Posting the same key again updates the same entry instead of creating a second one, so a caller may safely re-send a whole month.
An entry has a status: provisional (an estimate that may still change, never payable), new (ready for a person to approve), approved (money is locked), paid (on a payout) or cancelled. Only approved entries are ever included in a payout; provisional entries never appear in payable totals anywhere in Xagle.
Once an entry is approved or paid its money fields (rep, rule, client, invoice, appointment, amount, currency, earned date, period, adjusted entry) are locked. Posting the same figures again is accepted (the note and payload may still be updated); posting different figures answers 409. The correction is a separate adjustment entry: post a new reference with a negative or positive amount and adjusts_external_ref naming the original. Negative amounts are only accepted on adjustments.
Each entry carries a period (YYYY-MM) derived from earned_on unless you send one. Late demos belong to the month the demo happened: send that month as earned_on / period and the entry sits in that month regardless of when it was posted.
Sales reps
Commissions are earned by sales reps, not users. A rep may be an internal user, an external person with no login (an appointment setter) or an affiliate. Register each of your reps once with your own id so later postings can name them by it.
| Field | Required | Meaning |
|---|---|---|
name | yes | Display name. |
rep_type | yes | internal, external or affiliate. |
external_system, external_id | recommended | Your name for your system and your id for this rep. Creating a rep whose pair already exists answers 409 with the existing rep in data, so a create is safe to retry. |
email, phone, notes | no | Contact details. |
user_id, client_id | no | Link the rep to an Xagle user (internal) or client (affiliate). Each user or client can be linked to one rep. |
default_currency_code | no | ISO code used for the rep's entries when a posting does not name one. |
active | no | Defaults to true. |
List filters: search (name, email, affiliate code, external id), rep_type, active, external_system, external_id; add paginated_response=1 for pages with meta.
Posting an entry
PUT /api/v1/commission/entries/{external_system}/{external_ref} with a JSON body:
| Field | Required | Meaning |
|---|---|---|
sales_rep_id or sales_rep_external_id | one of them | The rep earning this amount. sales_rep_external_id is looked up under the external_system in the URL (override with sales_rep_external_system). An unknown rep answers 422; create it first. |
amount | yes | The commission amount. Negative only with adjusts_external_ref / adjusts_entry_id. |
currency_code | no | ISO code. Defaults to the rep's default currency, then the account base currency. |
earned_on | no | Date the commission was earned (YYYY-MM-DD). Defaults to today on create; the month of this date becomes period. |
period | no | YYYY-MM, when the entry should sit in a different month than earned_on. |
status | no | provisional, new (default), approved (token needs commission.approve; send approved_at and approved_by_user_id) or cancelled. On an update the move must be one the ledger allows, for example provisional to new, new to approved or cancelled. |
commission_rule_id or rule_slug | no | The commission rule to file the entry under; rules and their slugs are managed in Commissions > Rules. |
client_id, invoice_id, appointment_id | no | What the commission is for. appointment_id is the Xagle appointment of the demo (see the appointments API below); one rep cannot be paid twice for the same rule and appointment. |
adjusts_external_ref or adjusts_entry_id | for corrections | The entry this one corrects. Required for a negative amount. |
note | no | Free text shown on the ledger (the math, the tier, the reason). |
payload | no | Any JSON object you want stored with the entry (tier, demo count, your own ids). Returned as payload.posting. |
The answer carries outcome: created (HTTP 201), updated or unchanged (HTTP 200). data is the full entry with sales_rep, rule, client, adjusts_entry and payout embedded.
Batch
POST /api/v1/commission/entries/batch with {"external_system": "agenthq", "entries": [ {...}, {...} ]}, up to 500 items. Each item takes the fields above plus external_ref (and may override external_system). Items are processed one by one: a bad item reports its own errors or message and http_status and the rest still land. The call answers 200 with one result per item (index, external_ref, outcome, http_status, entry) and a counts summary.
Status
POST …/status with status and, as applies, approved_at, approved_by_user_id, paid_at, payment_reference. The approver recorded is the user the body names, never the token's user. Allowed moves: provisional to new or cancelled; new to approved, paid or cancelled; approved to paid, cancelled or back to new; paid back to approved or new. Entries mirrored from an invoice or subscription commission answer 409 and must be changed on that invoice.
Reading entries
GET /api/v1/commission/entries filters: sales_rep_id, period, status (comma list), source (api, manual, rule, invoice_item, recurring_item), external_system, external_ref, client_id, appointment_id, updated_since (date-time; everything changed since then, for a pull) and flagged=1 (entries the refund watch marked for review). Add paginated_response=1 for pages.
Period summaries
A period summary is your running estimate of what a rep has earned in a month: the tier they have reached, how many qualified demos so far, the projected total. Xagle stores it as posted and shows it on the rep's ledger labelled Estimate, with your system named as the source. It is display only; the entries are the money.
PUT /api/v1/commission/period-summaries/{sales_rep_id}/{period} (period as YYYY-MM):
| Field | Required | Meaning |
|---|---|---|
external_system | yes | Your system's name. One summary is kept per rep, period and system; posting again replaces it. |
total | no | The estimated total for the period, shown large. |
currency_code | no | ISO code for total. |
figures | no | A JSON object of numbers for machines (for example {"qualified_demos": 7, "tier_rate": 25}). Returned as sent. |
lines | no | Up to 50 display lines for people, each {"label": "...", "value": "..."} or a plain string. Rendered in order. |
label | no | Badge text; defaults to "Estimate". |
as_of | no | When the estimate was calculated; defaults to now. |
note | no | Free text. |
Payouts
A payout bundles one rep's approved, unpaid entries in one currency. Marking it paid writes an expense against the rep's vendor in Xagle and moves every entry to paid with the payment reference, so the books and the ledger agree.
POST /api/v1/commission/payouts with either sales_rep_id (every approved, unpaid entry of that rep; add period to include only entries up to and including that month) or ids (a chosen list of approved entry ids), plus optional note. Send pay_now=1 with the payment fields to create and pay in one call. The answer is the payout (total, entry_count, status, entries). Nothing approved to pay, mixed reps or currencies, or a non-positive net answer 422.
POST /api/v1/commission/payouts/{id}/pay with paid_at, payment_reference, expense_payment_method_id and payment_detail (all optional) marks a draft payout paid; a payout that is not a draft answers 409. GET /api/v1/commission/payouts filters: sales_rep_id, status (draft, paid, cancelled), period.
Reading demo verification from appointments
When demos are booked onto an Xagle appointment calendar, the salesperson records on the appointment whether the demo happened and who attended. The appointments API exposes those facts so your system can apply its own rules:
POST /api/v1/calendar/appointments/createacceptsclient_id,booked_by_sales_rep_id(the setter),external_system,external_refandinternal_notes. A repeatedexternal_refanswers 409 with the existing appointment.GET /api/v1/calendar/appointments?updated_since=YYYY-MM-DD HH:MM:SSreturns every appointment changed since that moment (any status, no date window, oldest change first), so a periodic pull sees new bookings, reschedules, cancellations and verifications. Further filters:outcome(success,unsuccessful,neutral,none),schedule_id,booked_by_sales_rep_id,external_system,external_ref.- Each appointment carries
booked_at(set once, kept through a reschedule),start_datetime(the demo's actual date, which decides the month it counts toward),status,appointment_result(nameand machine-readableoutcome),decision_maker_attended,actual_duration_minutes,salesperson_feedback,verified_byandverified_at.
A month in the life of a setter programme
- Register each setter once:
POST /commission/repswithexternal_system=agenthqand your setter id. Keep the returnedidor look it up later. - Book demos through the appointments API with
booked_by_sales_rep_idand yourexternal_ref. - Pull
GET /calendar/appointments?updated_since=…on a schedule. When a demo showsverified_atwith a successful outcome and a decision-maker present, apply your tier rules. - Post the month as it stands: one
PUT /commission/entries/agenthq/{ref}per qualified demo withstatus=provisional,appointment_id,earned_on= the demo date and anotewith the math, and aPUT /commission/period-summaries/{rep}/{YYYY-MM}with the tier and the projected total. Re-send as the month changes; the same references update in place. - At month end, post the final figures with
status=new(orapprovedif the token may approve). A person reviews and approves in Commissions > Ledger. - Pay:
POST /commission/payoutsfor the rep and period, then…/paywith the payment reference, or let the finance team do it from Commissions > Payouts. - Found a mistake after approval? Post an adjustment entry with
adjusts_external_reffor the difference. Approved money is never rewritten.