The TextSpaced API is in development but allows for gathering game data and playing the game programmatically. Information on how to use the API and full documentation can be found at https://api.textspaced.com.
A working example of using the API in jQuery can be viewed at https://www.textspaced.com/examples/nearby/index.html with the option to download the entire source.
Using the API is rather straight forward. Simply perform GET or POST request to the endpoints listed in the documentation with any required parameters. An example in vanilla JavaScript using XHR and jQuery of an AJAX call to the API are as follows:
let data = "";
let xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.textspaced.com/owned/ships/?key=value");
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.send(data);
$.ajax({
url: "https://api.textspaced.com/owned/ships/",
type: 'POST',
datType: 'JSON',
headers: {
"Authorization": "Bearer " + token
},
data: params
})
This example performs a POST request to the specified URL, which in this case is a list of ships that you own. The authorisation bearer token is required with every call to identify who you are. You can retrieve your API token by typing API in the Messenger version of TextSpaced or opening settings in the web version and coping your API token from there.
In the jQuery example the token parameter must be replaced with your actual API token and the params parameters are any parameters you wish to send, as detailed in the documentation.
An similar POST request using cURL in PHP would look like:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.textspaced.com/owned/ships/?key=value',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer $token',
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
In this PHP example the same endpoint is called as the jQuery example, parameters are appended to the URL and the authorisation bearer token included as a header.
The API is JSON based and will return responses in JSON format as described in the documentation. In the PHP example, using the json_decode function will convert the JSON into a PHP object for easier use. We recommend using an app such as Postman for helping to debug your requests before creating your own code. For API calls that are actions, such as move, a response format is used with a code and description about the outcome of the action. These codes are broken down below for convenience.
M category response codes are related to movement.
D category response codes are related to docking.