API Reference

USSD API

The Orchestrator supports interactive USSD sessions for offline field-agent operations. Agents dial a shortcode and navigate a menu-driven interface to trigger payment actions without internet access.

POST /api/v1/ussd

Handles an interactive USSD session. The USSD aggregator forwards each keypress from the user's phone to this endpoint, which returns the next menu screen.

Request Body
{
  "sessionId": "session_123",
  "phoneNumber": "233501234567",
  "text": "1",
  "serviceCode": "*203#"
}

Request Fields

FieldTypeDescription
sessionIdstringUnique session identifier from the USSD aggregator
phoneNumberstringCaller's phone number in international format (e.g. 233501234567)
textstringThe user's input so far (aggregator concatenates with previous inputs)
serviceCodestringThe USSD shortcode that was dialed (e.g. *203#)

Response Format

Responses use the standard telco USSD format. Return plain text with the appropriate prefix:

PrefixMeaning
CONContinue — displays the text and waits for user input
ENDEnd — displays the text and terminates the session

USSD Templates

The Orchestrator includes built-in USSD templates that merchants can enable or disable from their settings.

TemplatePurpose
transaction-statusEnter a transaction reference to view amount, status, date, and recipient count
agent-collectionFive-step flow: agent ID → customer phone → amount → confirm → record (bypasses STK push)
commission-balanceEnter agent phone to see pending commission, paid total, and last payout date
transaction-historyView last 5 transactions with status icons; select one for full details

Session Lifecycle

  1. User dials the USSD shortcode (e.g. *347*203#). The aggregator initiates a session.
  2. Aggregator sends initial request to POST /api/v1/ussd with the user's phone and empty text.
  3. Orchestrator resolves the merchant by shortcode and returns the main menu (CON response).
  4. User selects an option. Aggregator sends updated text with the accumulated input.
  5. Orchestrator routes to the appropriate template module based on templateType.
  6. Session continues (CON) or terminates (END) based on the template flow.
  7. Sessions expire after 120 seconds of inactivity.

Use Cases

  • Field agents collecting payments on behalf of merchants in areas with poor internet connectivity
  • Microfinance institutions managing agent networks in rural communities
  • Last-mile logistics confirming delivery and triggering payouts from a basic feature phone