simtrunkDocs

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

Terminal
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.

Send USSD

POST
/v1/lines/{id}/ussd

Requires the scope ussd:write.

Authorization

apiKey
headerAuthorizationBearer <token>

An API key, or an access token for one, through the API gateway.

Path Parameters

id*string

Request Body

application/json
  1. body
text*string

A code such as *100#, or a reply in a session.

reply?boolean

text answers the open session's menu.

Response Body

OK

application/json
  1. response
text*string

The network's answer.

done*boolean

The 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 example sip:*100%[email protected]. A raw # is read too.
  • Content-Type: text/plain, or application/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-string is the code. Reply with the text, or an XML UnstructuredSS-Response. Cancel with cancel (or exit, quit), or an XML UnstructuredSS-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-Request while the session is open; UnstructuredSS-Notify, UnstructuredSS-Release or an error-code when 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

TopicWhen
simtrunk.ussd.sentA code was sent
simtrunk.ussd.answeredThe network answered
simtrunk.ussd.failedThe code failed
simtrunk.ussd.networkUSSD from the network

How is this guide?

Last updated on

On this page