✅ 1. Callback URL Setup
Know that:
You must provide a callback URL that will be called when a USSD session hits your shortcode. Your server must respond with a JSON response to guide the USSD flow.
✅ 2. Request Parameters
The following GET parameters will be sent to their URL:
Parameter | Description | Example |
---|---|---|
session_id | Unique ID for the USSD session | 123456789 |
session_msisdn | User's phone number (MSISDN) | 2348000000000 |
session_msg | The latest user input (menu response) | 1 |
session_operation | Request operation type: begin or continue | begin or continue |
session_from | USSD shortcode | example *123# or #123*45# |
session_type | Usually 1 , expect user reply | 1 |
session_mno | Mobile network operator | MTN , AIRTEL , 9MOBILE, GLO |
✅ 3. Expected JSON Response
Your callback URL must return a JSON response like this:
{
"session_operation": "continue",
"session_type": 1,
"session_id": "123456789",
"session_msg": "Welcome to MyService\n1. Airtime\n2. Data"
}
Field | Description |
---|---|
session_operation | continue (expecting more input) or end (exit) |
session_type | Usually 1 for continue, 4 for end |
session_id | Same session ID received |
session_msg | Text shown to the user |
✅ 4. Sample Flow
User Dials: *123#
Provider Sends to Client:
Client Responds with:
{
"session_operation": "continue",
"session_type": 1,
"session_id": "123456",
"session_msg": "Welcome to My Service\n1. Airtime\n2. Data"
}
User Enters: 1
-
Provider Sends to Client:
-
✅ 5. Final Response to End Session
-
{
"session_operation": "end",
"session_type": 4,
"session_id": "123456",
"session_msg": "Thank you for using MyService."
}
✅ 6. Important NotesUse only GET requests. Always return valid JSON with proper headers. Timeout limit: 5–10 seconds. URL must be HTTPS.
✅ 7. Sample PHP Response Code
-
header('Content-Type: application/json');
echo json_encode([
'session_operation' => 'continue',
'session_type' => 1,
'session_id' => $_GET['session_id'],
'session_msg' => "Welcome to MyService\n1. Airtime\n2. Data"
]);
SAMPLE: Create ussd.php in your root and save this