Skip to main content

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

OperationEndpointPermission
List sales repsGET /api/v1/commission/repsview
Find a rep by the caller's own idGET /api/v1/commission/reps/lookup?external_system=…&external_id=…view
Show a repGET /api/v1/commission/reps/{id}view
Create a repPOST /api/v1/commission/repscreate
List ledger entriesGET /api/v1/commission/entriesview
Show an entryGET /api/v1/commission/entries/{id} or GET /api/v1/commission/entries/{external_system}/{external_ref}view
Post (create or update) an entryPUT /api/v1/commission/entries/{external_system}/{external_ref}create
Post many entriesPOST /api/v1/commission/entries/batchcreate
Move an entry's statusPOST /api/v1/commission/entries/{id}/status or POST /api/v1/commission/entries/{external_system}/{external_ref}/statusupdate (+ approve / pay)
List period summariesGET /api/v1/commission/period-summariesview
Show a rep's period summaryGET /api/v1/commission/period-summaries/{sales_rep_id}/{period}view
Store a rep's period summaryPUT /api/v1/commission/period-summaries/{sales_rep_id}/{period}create
List payoutsGET /api/v1/commission/payoutsview
Show a payoutGET /api/v1/commission/payouts/{id}view
Create a payoutPOST /api/v1/commission/payoutspay
Mark a payout paidPOST /api/v1/commission/payouts/{id}/paypay

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.

FieldRequiredMeaning
nameyesDisplay name.
rep_typeyesinternal, external or affiliate.
external_system, external_idrecommendedYour 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, notesnoContact details.
user_id, client_idnoLink the rep to an Xagle user (internal) or client (affiliate). Each user or client can be linked to one rep.
default_currency_codenoISO code used for the rep's entries when a posting does not name one.
activenoDefaults to true.

Posting an entry

PUT /api/v1/commission/entries/{external_system}/{external_ref} with a JSON body:

FieldRequiredMeaning
sales_rep_id or sales_rep_external_idone of themThe 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.
amountyesThe commission amount. Negative only with adjusts_external_ref / adjusts_entry_id.
currency_codenoISO code. Defaults to the rep's default currency, then the account base currency.
earned_onnoDate the commission was earned (YYYY-MM-DD). Defaults to today on create; the month of this date becomes period.
periodnoYYYY-MM, when the entry should sit in a different month than earned_on.
statusnoprovisional, 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_slugnoThe commission rule to file the entry under; rules and their slugs are managed in Commissions > Rules.
client_id, invoice_id, appointment_idnoWhat 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_idfor correctionsThe entry this one corrects. Required for a negative amount.
notenoFree text shown on the ledger (the math, the tier, the reason).
payloadnoAny 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):

FieldRequiredMeaning
external_systemyesYour system's name. One summary is kept per rep, period and system; posting again replaces it.
totalnoThe estimated total for the period, shown large.
currency_codenoISO code for total.
figuresnoA JSON object of numbers for machines (for example {"qualified_demos": 7, "tier_rate": 25}). Returned as sent.
linesnoUp to 50 display lines for people, each {"label": "...", "value": "..."} or a plain string. Rendered in order.
labelnoBadge text; defaults to "Estimate".
as_ofnoWhen the estimate was calculated; defaults to now.
notenoFree 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/create accepts client_id, booked_by_sales_rep_id (the setter), external_system, external_ref and internal_notes. A repeated external_ref answers 409 with the existing appointment.
  • GET /api/v1/calendar/appointments?updated_since=YYYY-MM-DD HH:MM:SS returns 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 (name and machine-readable outcome), decision_maker_attended, actual_duration_minutes, salesperson_feedback, verified_by and verified_at.

A month in the life of a setter programme

  1. Register each setter once: POST /commission/reps with external_system=agenthq and your setter id. Keep the returned id or look it up later.
  2. Book demos through the appointments API with booked_by_sales_rep_id and your external_ref.
  3. Pull GET /calendar/appointments?updated_since=… on a schedule. When a demo shows verified_at with a successful outcome and a decision-maker present, apply your tier rules.
  4. Post the month as it stands: one PUT /commission/entries/agenthq/{ref} per qualified demo with status=provisional, appointment_id, earned_on = the demo date and a note with the math, and a PUT /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.
  5. At month end, post the final figures with status=new (or approved if the token may approve). A person reviews and approves in Commissions > Ledger.
  6. Pay: POST /commission/payouts for the rep and period, then …/pay with the payment reference, or let the finance team do it from Commissions > Payouts.
  7. Found a mistake after approval? Post an adjustment entry with adjusts_external_ref for the difference. Approved money is never rewritten.