# Code Samples

## cURL

{% tabs %}
{% tab title="Step 1 - API key generation" %}
Initially login to get the temporary API key

{% code title="Command" overflow="wrap" %}

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

{% endcode %}

{% code title="Response" lineNumbers="true" %}

```json
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
```

{% endcode %}
{% endtab %}

{% tab title="Step 2 - Get the data" %}
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.

{% code overflow="wrap" %}

```
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'
```

{% endcode %}

{% code title="Response" overflow="wrap" lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

## Python

{% tabs %}
{% tab title="Step 1 - API key generation" %}
Initially login to get the temporary API key

{% code overflow="wrap" lineNumbers="true" %}

```python
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)
```

{% endcode %}

{% code title="Response" lineNumbers="true" %}

```json
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
```

{% endcode %}
{% endtab %}

{% tab title="Step 2 - Get the data" %}
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.

{% code overflow="wrap" lineNumbers="true" %}

```python
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)
```

{% endcode %}

{% code title="Response" overflow="wrap" lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

## JavaScript

{% tabs %}
{% tab title="Step 1 - API key generation" %}
Initially login to get the temporary API key

{% code overflow="wrap" lineNumbers="true" %}

```javascript
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'
 })
});
```

{% endcode %}

{% code title="Response" lineNumbers="true" %}

```json
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
```

{% endcode %}
{% endtab %}

{% tab title="Step 2 - Get the data" %}
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.

{% code overflow="wrap" lineNumbers="true" %}

```javascript
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'
 }
});
```

{% endcode %}

{% code title="Response" overflow="wrap" lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

## MATLAB

{% tabs %}
{% tab title="Step 1 - API key generation" %}
Initially login to get the temporary API key

{% code overflow="wrap" lineNumbers="true" %}

```matlab
%% 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);
```

{% endcode %}

{% code title="Response" lineNumbers="true" %}

```json
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
```

{% endcode %}
{% endtab %}

{% tab title="Step 2 - Get the data" %}
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.

{% code overflow="wrap" lineNumbers="true" %}

```matlab
%% 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);
```

{% endcode %}

{% code title="Response" overflow="wrap" lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}

## R

{% tabs %}
{% tab title="Step 1 - Request" %}
Initially login to get the temporary API key

{% code overflow="wrap" lineNumbers="true" %}

```r
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")
```

{% endcode %}

{% code title="Response" lineNumbers="true" %}

```json
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
```

{% endcode %}
{% endtab %}

{% tab title="Step 2 - Request" %}
Then make the GET request to one of the data layer API endpoint, using the requested API key and the latitude and longitude values.

{% code overflow="wrap" lineNumbers="true" %}

```r
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")
```

{% endcode %}

{% code title="Response" overflow="wrap" lineNumbers="true" %}

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

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.answr.space/coding-examples/code-samples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
