App API
Control the app from a script or another program: every method, what it takes and what it answers.
Uplink has an API: every part of the app, from your conversations to its screens, as methods you can call from a script or another program. It's off until you turn it on, and only someone with your token or connection string can use it.
Turn it on
Developer mode
On your phone, tap Settings › About › Version twelve times. Taps more than two seconds apart start the count again, and from the eighth tap a note counts down. Then Settings › Developer and Settings › API appear.
Choose how to reach it
APIOn this phoneServe the APIOver HTTP, with a tokenAllow from Wi-FiServed on the phone's address on your network tooCopy the tokenFrom anywhereThrough the relayCopy the connection string- Serve the API: over HTTP on the phone. From a computer by USB:
adb forward tcp:8765 tcp:8765, then callhttp://localhost:8765. Allow from Wi-Fi serves it on your network too. - Through the relay: from anywhere. The connection string (
ghostapi1:…) holds the key every call is sealed with; the relay passes calls along without being able to read them. Keep it as you would a password.
- Serve the API: over HTTP on the phone. From a computer by USB:
Call a method
Over HTTP, POST /api/<method> with the parameters as a JSON body and your token:
curl -s http://localhost:8765/api/conversations.list \
-H 'Authorization: Bearer <token>' \
-d '{"limit": 5}'
Or with the command-line client in the app's repository (tool/ghost-api.mjs):
node tool/ghost-api.mjs --token <token> app.info
node tool/ghost-api.mjs --remote ghostapi1:<secret> networks.chats '{"network": "telegram"}'
With no method it lists them all; --doc <method> shows one's documentation.
Requests and answers
| Request | What it does |
|---|---|
GET /api | Everything the API says of itself: every method, as JSON (api.describe). |
GET /api/<method> | One method's documentation. |
POST /api/<method> | Calls it. The body is its parameters as a JSON object, or empty. |
POST /api | The same as one object: {"method": "…", "params": {…}, "id": …}. The id comes back with the answer. |
Every request but GET / needs Authorization: Bearer <token>. Answers are JSON:
{"ok": true, "result": …}
{"ok": false, "error": {"code": "bad_params", "message": "\"thread\" is needed: …"}}
| Code | Status | Meaning |
|---|---|---|
unauthorized | 401 | The token is missing or wrong. |
not_found | 404 | No such method, or what it named isn't there. |
bad_params | 400 | A parameter is missing or of the wrong type, or the body isn't a JSON object. Also 405 for anything but GET and POST. |
failed | 500 | The method ran and what it asked failed. The message says why. |
Parameter types are string, int, bool, list and object, and each call is checked against them before it runs.
Through the relay
The connection string is ghostapi1: and 64 hex digits: a secret of 32 bytes. Both ends make three things from it with HKDF-SHA256 (salt ghost-api v1): the pairing channel they meet on (info relay channel, its first 16 bytes), that channel's token (relay token), and an AES-256-GCM key (seal key). The app holds the channel as its phone end; a client joins as the other (Pairing channels).
A request is one binary frame: a 12-byte nonce, then {"method", "params", "id"} sealed with the key (additional data ghost-api-v1, GCM's tag at the end). The answer comes back the same way. The relay passes the frames and can't open them. The app must be running to answer. tool/ghost-api.mjs is a client of about 150 lines to read or copy from.
The methods
Settings › API › Methods lists the same, with a place to try each. Those marked changes things send, delete or change something, and ask before running there. The methods for plugins in development need developer mode and aren't in App Store builds.
api
api.describe
Every method, its parameters, what it answers and an example: this documentation as JSON.
Answers {"api", "version", "methods": [...]}
curl -s http://localhost:8765/api/api.describe -H 'Authorization: Bearer <token>'api.ping
Answers at once: whether the API is there and which version it speaks.
Answers {"pong": true, "version": int}
curl -s http://localhost:8765/api/api.ping -H 'Authorization: Bearer <token>'app
app.info
The app's version, the device, whether it is the default texting app, and who is signed in where.
Answers {"version", "platform", "defaultSms", "username", "networks": [...]}
curl -s http://localhost:8765/api/app.info -H 'Authorization: Bearer <token>'app.log
The newest lines of the Developer log (Settings › Developer).
| Parameter | Type | Needed | What |
|---|---|---|---|
limit | int | How many lines, newest first. |
Answers ["line", ...]
curl -s http://localhost:8765/api/app.log -H 'Authorization: Bearer <token>'app.prefs.get
The person's choices as the app keeps them: one by its key, or all whose keys start with a prefix (all of them with none given).
| Parameter | Type | Needed | What |
|---|---|---|---|
key | string | One choice's key. | |
prefix | string | All choices starting with this. |
Answers {"key": "value", ...}
curl -s http://localhost:8765/api/app.prefs.get -H 'Authorization: Bearer <token>' \
-d '{"prefix":"plugin_spam"}'app.prefs.set changes things
Sets one of the person's choices, as Settings would. Some take effect only once the screen they belong to is opened again.
| Parameter | Type | Needed | What |
|---|---|---|---|
key | string | yes | The choice's key. |
value | string | yes | Its value: on/off for a switch. |
Answers null
curl -s http://localhost:8765/api/app.prefs.set -H 'Authorization: Bearer <token>' \
-d '{"key":"sounds","value":"on"}'app.update
Where the app's own update stands: the version installed, any newer one, and whether it is downloading.
Answers object
curl -s http://localhost:8765/api/app.update -H 'Authorization: Bearer <token>'contacts
contacts.get
Who a number is, as the phone's contacts have them.
| Parameter | Type | Needed | What |
|---|---|---|---|
address | string | yes | A phone number. |
Answers person
curl -s http://localhost:8765/api/contacts.get -H 'Authorization: Bearer <token>'conversations
conversations.archive
Archives a conversation, or brings it back.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
archived | bool | yes | true to archive, false to bring back. |
Answers null
curl -s http://localhost:8765/api/conversations.archive -H 'Authorization: Bearer <token>'conversations.delete changes things
Deletes a conversation from the phone, for every app. It cannot be undone.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
Answers null
curl -s http://localhost:8765/api/conversations.delete -H 'Authorization: Bearer <token>'conversations.draft
What is half written in a conversation; with "text", sets it.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
text | string | A new draft (empty clears it). |
Answers string | null
curl -s http://localhost:8765/api/conversations.draft -H 'Authorization: Bearer <token>'conversations.get
One conversation by its number.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
Answers conversation | null
curl -s http://localhost:8765/api/conversations.get -H 'Authorization: Bearer <token>' \
-d '{"thread":4}'conversations.list
Conversations of texts (and RCS beside Google Messages), newest first, a page at a time.
| Parameter | Type | Needed | What |
|---|---|---|---|
limit | int | How many (default 50). | |
offset | int | Where to start: the "next" a page gave. | |
archived | bool | The archived ones instead. |
Answers {"items": [conversation...], "next": int|null}
curl -s http://localhost:8765/api/conversations.list -H 'Authorization: Bearer <token>' \
-d '{"limit":10}'conversations.markRead
Marks a conversation read (in Google Messages too, beside it).
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
Answers null
curl -s http://localhost:8765/api/conversations.markRead -H 'Authorization: Bearer <token>'conversations.messages
A conversation's messages, newest first: texts, picture messages and RCS, with their state and attachments.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
limit | int | How many (default 100). |
Answers [message...]
curl -s http://localhost:8765/api/conversations.messages -H 'Authorization: Bearer <token>' \
-d '{"thread":4,"limit":20}'conversations.mute
Mutes a conversation's notifications, or unmutes them.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
on | bool | yes | true or false. |
Answers null
curl -s http://localhost:8765/api/conversations.mute -H 'Authorization: Bearer <token>'conversations.pin
Pins a conversation to the top of the list, or unpins it.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
on | bool | yes | true or false. |
Answers null
curl -s http://localhost:8765/api/conversations.pin -H 'Authorization: Bearer <token>'conversations.rename
Names a group conversation here (empty takes the name away).
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
name | string | yes | The name. |
Answers null
curl -s http://localhost:8765/api/conversations.rename -H 'Authorization: Bearer <token>'conversations.threadFor
The conversation's number for these people, made if there is none yet.
| Parameter | Type | Needed | What |
|---|---|---|---|
addresses | list | yes | Phone numbers. |
Answers int
curl -s http://localhost:8765/api/conversations.threadFor -H 'Authorization: Bearer <token>'filters
filters.classify
What the filters make of a text from someone: its tags (spam, its kind) and the section it would go to.
| Parameter | Type | Needed | What |
|---|---|---|---|
text | string | yes | The words. |
from | string | Who sent it. | |
contact | bool | Whether they are in your contacts. |
Answers {"tags": {"name": "detail"}, "section": string|null}
curl -s http://localhost:8765/api/filters.classify -H 'Authorization: Bearer <token>' \
-d '{"text":"Congratulations! You've won a gift card. Claim now: http://prize.example/win"}'friends
friends.list
Friends by username, those who asked you, and those you asked; with whether each is on.
Answers [{"username", "name", "state", "presence"}...]
curl -s http://localhost:8765/api/friends.list -H 'Authorization: Bearer <token>'messages
messages.delete changes things
Deletes one message from the phone by its kind and id (as conversations.messages gives them).
| Parameter | Type | Needed | What |
|---|---|---|---|
kind | string | yes | sms, mms or rcs. |
id | int | yes | Its id. |
Answers null
curl -s http://localhost:8765/api/messages.delete -H 'Authorization: Bearer <token>'messages.send changes things
Sends a text to these people, as the app would (RCS beside Google Messages where the conversation is RCS).
| Parameter | Type | Needed | What |
|---|---|---|---|
addresses | list | yes | Phone numbers. |
body | string | yes | The words. |
Answers int: the conversation's number
curl -s http://localhost:8765/api/messages.send -H 'Authorization: Bearer <token>'net
net.status
The app's routes to other installs: this install's name, the relay server it uses, how each route stands, and who it can reach.
Answers object
curl -s http://localhost:8765/api/net.status -H 'Authorization: Bearer <token>'networks
networks.changeGroup changes things
Changes a group on its network: any of title, description, timer (seconds), add, remove, admin, unadmin (lists of ids), announcementsOnly.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
change | object | yes | What to change. |
Answers null
curl -s http://localhost:8765/api/networks.changeGroup -H 'Authorization: Bearer <token>'networks.chats
A network's chats, newest first.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
limit | int | How many (default 50). |
Answers [chat...]
curl -s http://localhost:8765/api/networks.chats -H 'Authorization: Bearer <token>' \
-d '{"network":"telegram","limit":10}'networks.group
A group in full: its name, description, timer, people and rules, and what you may change.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
Answers object | null
curl -s http://localhost:8765/api/networks.group -H 'Authorization: Bearer <token>'networks.list
The other networks: whether each is signed in, and as whom.
Answers [{"id", "name", "state", "account", "chats"}...]
curl -s http://localhost:8765/api/networks.list -H 'Authorization: Bearer <token>'networks.markRead
Marks a chat read on its network.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
Answers null
curl -s http://localhost:8765/api/networks.markRead -H 'Authorization: Bearer <token>'networks.messages
A chat's messages as held, oldest first; loaded from the network first.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
Answers [message...]
curl -s http://localhost:8765/api/networks.messages -H 'Authorization: Bearer <token>'networks.react
Puts a reaction on a message, or takes it off.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
message | string | yes | The message's id. |
emoji | string | yes | The reaction. |
remove | bool | Take it off instead. |
Answers null
curl -s http://localhost:8765/api/networks.react -H 'Authorization: Bearer <token>'networks.reply changes things
Sends words as a reply quoting one of the chat's messages.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
message | string | yes | The id of the message answered. |
text | string | yes | The words. |
Answers null
curl -s http://localhost:8765/api/networks.reply -H 'Authorization: Bearer <token>'networks.send changes things
Sends words in a chat on that network.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
text | string | yes | The words. |
Answers null
curl -s http://localhost:8765/api/networks.send -H 'Authorization: Bearer <token>'plugins
plugins.devInstall changes things
Loads a plugin you are making (a ghost-plugin/1 file) on this phone, unreviewed, as Settings › Developer › Plugins in development does. Developer mode only. dryRun checks it without loading it.
| Parameter | Type | Needed | What |
|---|---|---|---|
pack | object | The plugin file's JSON. Give this or text. | |
text | string | The plugin file's words, as they are on disk. Give this or pack. | |
on | bool | Switch it on once loaded: only where you agreed on the phone to everything it can do already (false where not given). | |
dryRun | bool | Only check it: what is wrong with it, if anything. |
Answers {"ok": bool, "id": "bills", "plugin": "xbills", "on": bool, "needs": "consent on the phone" (where on was asked and could not be), "issues": [{"code", "path", "message", "severity"}...]}
curl -s http://localhost:8765/api/plugins.devInstall -H 'Authorization: Bearer <token>'plugins.devRemove changes things
Removes a plugin in development from this phone.
| Parameter | Type | Needed | What |
|---|---|---|---|
id | string | yes | Its id, as in its file. |
Answers null
curl -s http://localhost:8765/api/plugins.devRemove -H 'Authorization: Bearer <token>'plugins.list
Every plugin, whether it is on, and its own choices: the built-in ones and those from the Marketplace and in development (whose ids start with x).
Answers [{"id", "name", "description", "on", "prefs", "source": "builtIn"|"reviewed"|"dev", "version"}...]
curl -s http://localhost:8765/api/plugins.list -H 'Authorization: Bearer <token>'plugins.pref
One of a plugin's own choices (the spam filter's strictness, a sign on or off); with "value", sets it.
| Parameter | Type | Needed | What |
|---|---|---|---|
id | string | yes | The plugin's id. |
key | string | yes | The choice. |
value | string | A new value. |
Answers string | null
curl -s http://localhost:8765/api/plugins.pref -H 'Authorization: Bearer <token>' \
-d '{"id":"spam","key":"level"}'plugins.set
Turns a plugin on or off.
| Parameter | Type | Needed | What |
|---|---|---|---|
id | string | yes | The plugin's id. |
on | bool | yes | true or false. |
Answers null
curl -s http://localhost:8765/api/plugins.set -H 'Authorization: Bearer <token>'presence
presence.get
Whether someone is on now, and where, or when they were last seen: a number, a friend's @username, or network:id (Telegram).
| Parameter | Type | Needed | What |
|---|---|---|---|
address | string | yes | A phone number, @username, or telegram:<user id>. |
Answers {"network", "online", "lastSeen", "words"} | null
curl -s http://localhost:8765/api/presence.get -H 'Authorization: Bearer <token>'ui
ui.compose
Opens New message, with words already written where given.
| Parameter | Type | Needed | What |
|---|---|---|---|
body | string | Words to start with. |
Answers null
curl -s http://localhost:8765/api/ui.compose -H 'Authorization: Bearer <token>'ui.home
Closes what is open and goes back to the list of conversations.
Answers null
curl -s http://localhost:8765/api/ui.home -H 'Authorization: Bearer <token>'ui.openChat
Opens a Telegram or Signal chat on the screen.
| Parameter | Type | Needed | What |
|---|---|---|---|
network | string | yes | telegram or signal. |
chat | string | yes | The chat's id on that network (networks.chats gives them). |
Answers null
curl -s http://localhost:8765/api/ui.openChat -H 'Authorization: Bearer <token>'ui.openConversation
Opens a conversation of texts on the screen.
| Parameter | Type | Needed | What |
|---|---|---|---|
thread | int | yes | The conversation's number (conversations.list gives them). |
Answers null
curl -s http://localhost:8765/api/ui.openConversation -H 'Authorization: Bearer <token>'ui.openSettings
Opens Settings, at one of its sections where given (messages, sounds, developer, api, ...). plugins and plugin-<id> open the Marketplace instead.
| Parameter | Type | Needed | What |
|---|---|---|---|
section | string | A section's id. |
Answers null
curl -s http://localhost:8765/api/ui.openSettings -H 'Authorization: Bearer <token>'ui.toast
Shows a short note at the foot of the screen.
| Parameter | Type | Needed | What |
|---|---|---|---|
text | string | yes | The words. |
Answers null
curl -s http://localhost:8765/api/ui.toast -H 'Authorization: Bearer <token>'Recent calls on the API page shows the last calls made, from where and how long they took. Make a new token or Make a new connection string shuts out whoever had the old one.
The source
Uplink is open source (AGPL-3.0): github.com/InfamousVague/ghost-messaging.
Developer docs