Code Samples
Here are a few simple snippets to get started
cURL
Initially login to get the temporary API key
curl -X 'POST'
'https://api.answr.space/api:auth/auth/login'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-d '{ "email": "your@email.domain", "password": "your_password" }'
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.
curl -X 'GET'
'https://api.answr.space/api:climate-variables/a-frost-days?Input_point=%7B%22type%22%3A%22point%22%2C%22data%22%3A%7B%22lng%22%3A69.104192266327%2C%22lat%22%3A36.2471504211426%7D%7D'
-H 'accept: application/json'
-H 'Authorization: Bearer eyJhbGciOiJBMjU2S1ciLCJlbm'
{ "CV88_M1": 30.26427069577304, "CV88_M2": 26.46405896273526, "CV88_M3": 23.403805472634055, "CV88_M4": 14.639534906907516, "CV88_M5": 9.528541202910922, "CV88_M6": 2.90803387879648, "CV88_M7": 0.089852011000568, "CV88_M8": 0.261099363761869, "CV88_M9": 4.987315048548308, "CV88_M10": 13.34038048847155, "CV88_M11": 20.978858622637663, "CV88_M12": 28.531385161659934 }
Python
Initially login to get the temporary API key
import requests
headers = {
'accept': 'application/json',
# Already added when you pass json= but not when you pass data=
# 'Content-Type': 'application/json',
}
json_data = {
'email': 'your@email.domain',
'password': 'your_password',
}
response = requests.post('https://api.answr.space/api:auth/auth/login', headers=headers, json=json_data)
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.
import requests
headers = {
'accept': 'application/json',
'Authorization': 'Bearer eyJhbGciOiJBMjU2S1ciLCJlbm',
}
params = {
'Input_point': '{"type":"point","data":{"lng":69.104192266327,"lat":36.2471504211426}}',
}
response = requests.get('https://api.answr.space/api:climate-variables/a-frost-days', params=params, headers=headers)
{ "CV88_M1": 30.26427069577304, "CV88_M2": 26.46405896273526, "CV88_M3": 23.403805472634055, "CV88_M4": 14.639534906907516, "CV88_M5": 9.528541202910922, "CV88_M6": 2.90803387879648, "CV88_M7": 0.089852011000568, "CV88_M8": 0.261099363761869, "CV88_M9": 4.987315048548308, "CV88_M10": 13.34038048847155, "CV88_M11": 20.978858622637663, "CV88_M12": 28.531385161659934 }
JavaScript
Initially login to get the temporary API key
fetch('https://api.answr.space/api:auth/auth/login', {
method: 'POST',
headers: {
'accept': 'application/json',
'Content-Type': 'application/json'
},
// body: '{\n "email": "your@email.domain",\n "password": "your_password"\n}',
body: JSON.stringify({
'email': 'your@email.domain',
'password': 'your_password'
})
});
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.
fetch('https://api.answr.space/api:climate-variables/a-frost-days?Input_point=%7B%22type%22%3A%22point%22%2C%22data%22%3A%7B%22lng%22%3A69.104192266327%2C%22lat%22%3A36.2471504211426%7D%7D', {
headers: {
'accept': 'application/json',
'Authorization': 'Bearer eyJhbGciOiJBMjU2S1ciLCJlbm'
}
});
{ "CV88_M1": 30.26427069577304, "CV88_M2": 26.46405896273526, "CV88_M3": 23.403805472634055, "CV88_M4": 14.639534906907516, "CV88_M5": 9.528541202910922, "CV88_M6": 2.90803387879648, "CV88_M7": 0.089852011000568, "CV88_M8": 0.261099363761869, "CV88_M9": 4.987315048548308, "CV88_M10": 13.34038048847155, "CV88_M11": 20.978858622637663, "CV88_M12": 28.531385161659934 }
MATLAB
Initially login to get the temporary API key
%% Web Access using Data Import and Export API
uri = 'https://api.answr.space/api:auth/auth/login';
body = struct(
'email', 'your@email.domain',
'password', 'your_password'
);
options = weboptions(
'MediaType', 'application/json',
'HeaderFields', {'accept' 'application/json'}
);
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = [
HeaderField('accept', 'application/json')
HeaderField('Content-Type', 'application/json')
]';
uri = URI('https://api.answr.space/api:auth/auth/login');
body = JSONProvider(struct(
'email', 'your@email.domain',
'password', 'your_password'
));
response = RequestMessage('post', header, body).send(uri.EncodedURI);
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.
%% Web Access using Data Import and Export API
params = {'Input_point' '{"type":"point","data":{"lng":69.104192266327,"lat":36.2471504211426}}'};
baseURI = 'https://api.answr.space/api:climate-variables/a-frost-days';
uri = [baseURI '?' char(join(join(params, '='), '&'))];
options = weboptions('HeaderFields', {
'accept' 'application/json'
'Authorization' Bearer eyJhbGciOiJBMjU2S1ciLCJlbm
});
response = webread(uri, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
params = {'Input_point' '{"type":"point","data":{"lng":69.104192266327,"lat":36.2471504211426}}'};
header = [
HeaderField('accept', 'application/json')
HeaderField('Authorization', 'Bearer eyJhbGciOiJBMjU2S1ciLCJlbm')
]';
uri = URI('https://api.answr.space/api:climate-variables/a-frost-days', QueryParameter(params'));
response = RequestMessage('get', header).send(uri.EncodedURI);
{ "CV88_M1": 30.26427069577304, "CV88_M2": 26.46405896273526, "CV88_M3": 23.403805472634055, "CV88_M4": 14.639534906907516, "CV88_M5": 9.528541202910922, "CV88_M6": 2.90803387879648, "CV88_M7": 0.089852011000568, "CV88_M8": 0.261099363761869, "CV88_M9": 4.987315048548308, "CV88_M10": 13.34038048847155, "CV88_M11": 20.978858622637663, "CV88_M12": 28.531385161659934 }
R
Initially login to get the temporary API key
require(httr)
headers = c(
`accept` = 'application/json',
`Content-Type` = 'application/json'
)
data = '{\n "email": "your@email.domain",\n "password": "your_password"\n}'
res <- httr::POST(url = 'https://api.answr.space/api:auth/auth/login', httr::add_headers(.headers=headers), body = data)
res <- content(res,"parsed")
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.
require(httr)
headers = c(
`accept` = 'application/json',
`Authorization` = 'Bearer eyJhbGciOiJBMjU2S1ciLCJlbm'
)
params = list(
`Input_point` = '{"type":"point","data":{"lng":69.104192266327,"lat":36.2471504211426}}'
)
res <- httr::GET(url = 'https://api.answr.space/api:climate-variables/a-frost-days', httr::add_headers(.headers=headers), query = params)
res <- content(res,"parsed")
{ "CV88_M1": 30.26427069577304, "CV88_M2": 26.46405896273526, "CV88_M3": 23.403805472634055, "CV88_M4": 14.639534906907516, "CV88_M5": 9.528541202910922, "CV88_M6": 2.90803387879648, "CV88_M7": 0.089852011000568, "CV88_M8": 0.261099363761869, "CV88_M9": 4.987315048548308, "CV88_M10": 13.34038048847155, "CV88_M11": 20.978858622637663, "CV88_M12": 28.531385161659934 }
Last updated