LogoLogo
HomeProductSolutionsAbout usContactLog in
  • Overview
    • Welcome to answr
    • Our Features
    • Data Layer Availability
  • Start Here
    • How to make your first API call
  • Coding Examples
    • Code Samples
    • Simple climatic variables plotting
    • Climatic variables spatial plotting
    • Reporting tool
  • Integrations
    • Connect answr with Zapier
    • Connect answr with Make
  • Data Sources
    • Sentinel-1 imagery
    • Sentinel-2 imagery
    • Sentinel-3 imagery
    • Landsat 8 imagery
    • Landsat 9 imagery
    • MODIS
    • Global Surface Water
    • Flood Hazard Maps at European and Global Scale
    • AgERA5
    • Soil moisture
  • API Data Layers
    • Climate Analytics
      • Climatic Variables
      • Köppen–Geiger Zones
      • Universal Thermal Climate Index
    • Natural Disasters
      • Cold Wave Probability
      • Drought Probability
      • Flood Severity
      • Heat Wave Probability
      • Windstorm Probability
      • Wildfire Frequency Occurrence
      • Extreme Heat Probability
      • Extreme Cold Probability
  • API Reference
    • Authentication
    • Climatic Variables
    • Natural Disasters
  • Surveys
    • Feedback
Powered by GitBook
On this page
  • cURL
  • Python
  • JavaScript
  • MATLAB
  • R
  1. Coding Examples

Code Samples

Here are a few simple snippets to get started

cURL

Initially login to get the temporary API key

Command
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" }'

Response
{ "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'

Response
{ "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)

Response
{ "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)

Response
{ "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'
 })
});

Response
{ "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'
 }
});

Response
{ "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);

Response
{ "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);

Response
{ "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")

Response
{ "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")

Response
{ "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 }
PreviousHow to make your first API callNextSimple climatic variables plotting

Last updated 2 years ago