How to make your first API call

Step by step guide

Step 1 - Open the answr API Reference

Before you start making your first API call, open the answr API Reference. You can find it in the answr Web app or through the answr documentation.

The documentation provides complete reference on the authentication process, but also on how different statistics and data layers, like Climatic variables and Natural disasters, can be requested.

This guide provides you a short introduction on how to make your first answr API call.

Step 2 - Choose your programming language

Depending on what programming language you prefer, we have currently code examples for requests and responses in cURL, Python, Javascript, MATLAB and R available.

Check out the chapter 👩💻Code Samples and choose the programming language you want to use.

Copy the code from "Step 1" and set up your console for performing your authentication process!

If you wish to get code samples in other programming languages, please send us your request through our community support form.

Step 3 - Authentication

As a first step you will need to authenticate yourself.

Below you can find a code example in Python. Exchange the dummy email and password with your account credentials.

import requests
headers = { 'accept': 'application/json', 'Content-Type': 'application/json', 
} 
json_data = { 'email': 'youremail@mail.com', 'password': 'password', }
response = requests.post('https://api.answr.space/api:auth/auth/login',
 headers=headers, json=json_data)
response.content

If the request was successful (value = 200), you will receive a Authentication Token (Bearer), which will have the following format:

eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiemlwIjoiREVGIn0

Use it to perform your first data requests.

Step 4 - First data request

Once you have authenticated yourself and received your Token, you can start requesting data through the answr API. You will find the Code how to perform your first data request in different programming languages, in "Step2" of the 👩💻Code Samples.

For each API call, we cache the response for 30 minutes. This means that when you call multiple times a specific API endpoint with the same coordinates, the response is instantly available and we do not count additional requests from the authenticated account

Here is again an example in Python. Replace the word "TOKEN" with the Authentication Token you have received in the authentication process:

headers = { 'accept': 'headers = 
{ 'accept': 'application/json', 'Authorization': 'Bearer TOKEN', } 
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.content

Response: (Average frost days per month on the chosen location)

{
"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
}

Congratulations! You successfully performed your first data request.

Last updated