Login
Description
The SpaceSense API is used to analyze fields and retrieve analyzed data
This section will show you how to use the API in a simple way using practical examples
If you already know how to use the API you can checkout the API documention
Login
To access the API and start writing and reading data you need to login.
Upon a successful login you will recieve a token from the API.
This token is required to talk to the API.
For every request done to the API (except Login) you will enter your token like a parameter for a
GET
request.Example :
https://api-address/endpoint?token=__myToken__
in this example the token is
__myToken__
curl -d 'username=__username__&password=__password__' https://spacesense-api.ew.r.appspot.com/login
#import requests
import requests
# Creating the load for the request.
# replace __username__ and __password__ by your SpaceSense username and password
pload = {'username':'__username__','password':'__password__'}
# send the request a a post to the API adress and adds the load to the request
r = requests.post('https://spacesense-api.ew.r.appspot.com/login', data = pload)
# get the response Json in a dictionary.
r_dictionary = r.json()
# this is your API token for this session. you need to store and it and keep it.
token = r_dictionary['token']
// Creates an instance of HttpClients
HttpClient client = HttpClient.newHttpClient();
// Create a new Post on the API for the Login endpoint
HttpRequest request = HttpRequest.newBuilder(URI.create("https://spacesense-api.ew.r.appspot.com/login"))
.build();
// Creates a List to add parameters to the post request
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
// Change __username__ to your SpaceSense API username
params.add(new BasicNameValuePair("username", "__username__"));
// Change __password__ to your SpaceSense API password
params.add(new BasicNameValuePair("password", "__password__"));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
// Create the Token variable
String token;
if (entity != null) {
try (InputStream instream = entity.getContent()) {
BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//Read JSON response and print
JSONObject myResponse = new JSONObject(response.toString());
token = myResponse['token']
}