Affihub
DocsAPI ReferenceFlows

Flows

Overview

Flows are commission rules that determine how much a partner earns for each referral. They support conditional logic with priority-based evaluation. See Commission Flows for a conceptual overview.

All endpoints require API key authentication.

Create a flow

POST /api/v1/flows

Request body

Field Type Required Description
name string Yes Human-readable name
event string No Trigger event (default: transaction_completed)
action_type string Yes percentage or flat
action_value number Yes Rate (percentage) or amount (cents)
conditions array No Condition objects (AND logic)
priority number No Evaluation order (higher = first, default: 0)
active boolean No Enable/disable (default: true)

Condition object

{
  "field": "txn_amount_cents",
  "op": "gt",
  "value": 50000
}

Operators: eq, neq, gt, lt, contains

Fields: txn_amount_cents, customer_email, partner_slug, provider

Example

curl -X POST "https://api.affihub.com/api/v1/flows" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "High Value Bonus",
    "action_type": "percentage",
    "action_value": 30,
    "priority": 100,
    "conditions": [
      {"field": "txn_amount_cents", "op": "gt", "value": 50000}
    ]
  }'

Response

{
  "id": "flw_abc123",
  "program_id": "prog_xxx",
  "name": "High Value Bonus",
  "event": "transaction_completed",
  "action_type": "percentage",
  "action_value": 30,
  "conditions": [
    {"field": "txn_amount_cents", "op": "gt", "value": 50000}
  ],
  "active": true,
  "priority": 100,
  "created_at": "2026-04-01T12:00:00Z"
}

List flows

GET /api/v1/flows

Returns all flows for your program, ordered by priority (descending).

curl "https://api.affihub.com/api/v1/flows" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

{
  "data": [
    {
      "id": "flw_def456",
      "name": "Agency Pro Flat Fee",
      "action_type": "flat",
      "action_value": 5000,
      "priority": 200,
      "active": true,
      "conditions": [
        {"field": "partner_slug", "op": "eq", "value": "agency-pro"}
      ]
    },
    {
      "id": "flw_abc123",
      "name": "High Value Bonus",
      "action_type": "percentage",
      "action_value": 30,
      "priority": 100,
      "active": true,
      "conditions": [
        {"field": "txn_amount_cents", "op": "gt", "value": 50000}
      ]
    }
  ]
}

Get a flow

GET /api/v1/flows/:id
curl "https://api.affihub.com/api/v1/flows/flw_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY"

Update a flow

PATCH /api/v1/flows/:id

All fields are optional. Only include what you want to change.

curl -X PATCH "https://api.affihub.com/api/v1/flows/flw_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "action_value": 35,
    "active": false
  }'

Updating conditions

To replace all conditions, send the full array:

curl -X PATCH "https://api.affihub.com/api/v1/flows/flw_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "conditions": [
      {"field": "txn_amount_cents", "op": "gt", "value": 100000},
      {"field": "provider", "op": "eq", "value": "stripe"}
    ]
  }'

Delete a flow

DELETE /api/v1/flows/:id

Permanently removes the flow.

curl -X DELETE "https://api.affihub.com/api/v1/flows/flw_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY"

Evaluation order

When a transaction is processed, flows are evaluated as follows:

  1. All active flows for the program are queried, ordered by priority DESC
  2. For each flow, all conditions are evaluated (AND logic)
  3. The first flow where all conditions match is selected
  4. If no flow matches, the system falls back to the partner's commission_pct, then the program's default_commission_pct
💡

Use priority spacing (100, 200, 300) to leave room for inserting rules between existing ones.