HTTP API
- Endpoints return JSON, for example
{"version":"1.0.1","code":0}. A nonzerocodeindicates an error. Call the endpoint to inspect any returned data. - The HTTP service uses port
8080. Make sure no other local service is using that port. - For
setcurrentrecordparam, first write the parameters to/var/mobile/ctwparams.txt. - For endpoints that require a record ID, use
getbakidfromnameto look up the ID from its name.
Use the client device's IP address. The examples below use http://127.0.0.1:8080.
| Endpoint | Description |
|---|---|
/version | Get the client version. |
/newrecord | Clear all records and create a new one. |
/nextrecord | Get the next record. |
/deleteallrecords | Clear all records. |
/activerecord?ID=XXX | Activate the record with ID XXX. |
/activefirstrecord | Activate the first record. |
/activelastrecord | Activate the last record. |
/deleterecord?ID=XXX | Delete the record with ID XXX. |
/importdirect | Import records directly. |
/exportrecord?ID=XXX | Export the record with ID XXX. |
/exportallrecords | Export all records. |
/renamecurrentrecord?name=XXX | Rename the current record. URL-encode names containing Chinese characters. |
/getbakidfromname?name=XXX | Look up the ID for the record named XXX. |
/getcurrentrecordparam | Get the current record's parameters. |
/setcurrentrecordparam | Read parameters from /var/mobile/ctwparams.txt and apply them to the current record. This command is unsupported after 1.5.2. See Customer identifier for sending custom parameters. |
/enablerecordapp | Enable or disable an app for the current record. Pass bid as the bundle ID and enable as 1 or 0. |
/getallrecordsname | Get a list of all record names. |
/relocationwithbid | Set a GPS position. The parameters x, y, z, r and bid supply coordinates, altitude, randomization range and bundle ID. |
/loadcloudconfig?device_id=XXX | Download a configuration shared by QR code. Use the sharing device's ID. |
OpenURL commands
| Action | Command and notes |
|---|---|
| Launch the app | openURL("CTW://?cmd=open"); |
| One-Tap Reset | openURL("CTW://?cmd=newrecord"); |
| Next record | openURL("CTW://?cmd=nextrecord"); |
| Clear all records | openURL("CTW://?cmd=deleteallrecords"); |
| Activate a specific record | openURL("CTW://?cmd=activerecord&ID="); |
| Activate the first record | openURL("CTW://?cmd=activefirstrecord"); |
| Activate the last record | openURL("CTW://?cmd=activelastrecord"); |
| Delete a specific record | openURL("CTW://?cmd=deleterecord&ID="); |
| Import records directly | openURL("CTW://?cmd=importdirect");Place records in /var/mobile/Media/CTWImport/. |
| Export a specific record | openURL("CTW://?cmd=exportrecord&ID=");Output is written to /var/mobile/Media/CTWExport/. |
| Export all records | openURL("CTW://?cmd=exportallrecords");Output is written to /var/mobile/Media/CTWExport/. |
| Rename the current record | openURL("CTW://?cmd=renamecurrentrecord&name=");URL-encode names containing Chinese characters. |
| Find an ID by record name | openURL("CTW://?cmd=getbakidfromname&name="); |
| Get current record parameters | openURL("CTW://?cmd=getcurrentrecordparam");The output is in /var/mobile/ctwparams.txt. |
| Set current record parameters | openURL("CTW://?cmd=setcurrentrecordparam");Supply parameters in /var/mobile/ctwparams.txt. This command is unsupported after 1.5.2. See Customer identifier for sending custom parameters. |
| Enable or disable an app | openURL("CTW://?cmd=enablerecordapp");Use bid for the bundle ID and enable=1 or enable=0. |
| List all record names | openURL("CTW://?cmd=getallrecordsname");The list is written to /var/mobile/ctwrecords.txt. |
| Set a GPS location | openURL("CTW://?cmd=relocationwithbid");Use x, y, z, r and bid for coordinates, altitude, randomization range and bundle ID. |
| Download a QR-shared configuration | openURL("CTW://?cmd=loadcloudconfig&device_id=");Supply the sharing device's ID. |
Return codes
Read the return code from /var/mobile/ctwresult.txt.
| Code | Meaning |
|---|---|
| 0 | The command completed successfully. |
| 1 | The command failed. |
| 2 | The command is still running. |
| 4 | There is no next record. Applies only to nextrecord. |
Parameter file
/var/mobile/ctwparams.txt holds the current record's parameters. Write one parameter per line using chr(10) for line breaks and a colon between each name and value. Run getcurrentrecordparam and open the file to see the format.
| Parameter | Description |
|---|---|
RecordID | Record identifier, for example WeChat001. |
RecordName | Record name, generated automatically by default. |
DeviceName | Device name, for example xxxx iPhone. |
SystemVersion | System version, for example 10.3.1. |
IDFA | Advertising identifier. |
IDFV | Vendor identifier. |
UDID | Device UDID. |
IMEI | Device IMEI. |
SerialNum | Device serial number. |
MAC | MAC address. |
SSID | SSID value. |
BSSID | BSSID value. |
TouchSprite examples
URL encoding
function encodeURI(s)
s = string.gsub(s, "([^%w%.%- ])", function(c)
return string.format("%%%02X", string.byte(c))
end)
return string.gsub(s, " ", "+")
end
Activate a record
recordId = encodeURI("1458774551");
url = string.format("CTW://?cmd=activerecord&ID=%s", recordId);
openURL(url);
Rename the current record
recordName = encodeURI("1458774551");
url = string.format("CTW://?cmd=renamecurrentrecord&name=%s", recordName);
openURL(url);
Launch the app
openURL("CTW://?cmd=open");
