USSD
Dial codes such as *100# from phones, the dashboard and the API, and the SIP contract for softphone authors.
USSD codes (*100# for a balance, top-ups, carrier menus) work on every line, in both directions, including menus of several steps. One session runs per line at a time, as the network allows one.
From a phone
Dial the code on a phone registered to the line, or from your PBX over a trunk. No call is placed: the carrier's answer comes back as a SIP MESSAGE from the code. Reply to that message to answer a menu, or send cancel to end the session.
From the dashboard
Open the line's USSD panel, send a code and answer the menus it shows. Network-initiated USSD (messages the carrier sends by itself) shows there too, and goes to your webhooks as simtrunk.ussd.network.
From the API
curl https://api.simtrunk.com/v1/lines/LINE_ID/ussd \ -H "Authorization: Bearer $SIMTRUNK_API_KEY" \ -H "Content-Type: application/json" \ -d '{"text": "*100#"}'Answer an open menu with {"text": "1", "reply": true}, and end it with POST /v1/lines/{id}/ussd/cancel. The key needs the ussd:write scope.
Requires the scope ussd:write.
apiKeyAuthorizationBearer <token>An API key, or an access token for one, through the API gateway.
id*stringapplication/json- body
text*stringA code such as *100#, or a reply in a session.
reply?booleantext answers the open session's menu.
OK
application/json- response
text*stringThe network's answer.
done*booleanThe session ended; false: it waits for a reply.
curl -X POST 'https://api.simtrunk.com/v1/lines/string/ussd' \ -H 'Content-Type: application/json' \ -d '{ "text": "string"}'{ "text": "string", "done": true}The SIP contract, for softphone authors
A phone registered to a line (or the PBX on a trunk) sends USSD through simtrunk as SIP MESSAGE:
- To:
sip:<code>@<your SIP domain>, with the#escaped as%23(RFC 3261), for examplesip:*100%[email protected]. A raw#is read too. - Content-Type:
text/plain, orapplication/vnd.3gpp.ussd+xml(the ussd-data document of 3GPP TS 24.390). Another type is refused with 415; unreadable XML with 400. - Start a session with the code: any text body, or an XML request whose
ussd-stringis the code. Reply with the text, or an XMLUnstructuredSS-Response. Cancel withcancel(orexit,quit), or an XMLUnstructuredSS-Release. - simtrunk answers
202 Accepted, then sends a MESSAGE From the escaped code (<sip:*100%23@…>), in the format the session started in: - XML:UnstructuredSS-Requestwhile the session is open;UnstructuredSS-Notify,UnstructuredSS-Releaseor anerror-codewhen it ended. - Text: the session is open while the text ends with(Reply to answer, or "cancel".)on its own lines. - Dialling the code (an INVITE) places no call: it is refused with
603 USSD sent, and the answer comes as a text MESSAGE as above.
Webhooks
| Topic | When |
|---|---|
simtrunk.ussd.sent | A code was sent |
simtrunk.ussd.answered | The network answered |
simtrunk.ussd.failed | The code failed |
simtrunk.ussd.network | USSD from the network |
How is this guide?
Last updated on