# Authentication

## Signup

{% tabs %}
{% tab title="curl" %}

```sh
curl --location 'https://api.terrak.io/users/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "YOUR_EMAIL",
    "password": "YOUR_PASSWORD"
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = 'https://api.terrak.io/users/signup'
headers = {
    'Content-Type': 'application/json'
}
data = {
    "email": "YOUR_EMAIL",
    "password": "YOUR_PASSWORD"
}

requests.post(url, headers=headers, json=data)
```

{% endtab %}
{% endtabs %}

## Login

{% tabs %}
{% tab title="curl" %}

```sh
curl --location 'https://api.terrak.io/users/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "YOUR_EMAIL",
    "password": "YOUR_PASSWORD"
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = 'https://api.terrak.io/users/login'
headers = {
    'Content-Type': 'application/json'
}
data = {
    "email": "YOUR_EMAIL",
    "password": "YOUR_PASSWORD"
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
```

{% endtab %}
{% endtabs %}

Will return `{"token": token}`. You will need to use this token as part of the 'authorization' header for the subsequent requests. This token will will expire after some time so if it is no longer working, you will need to use the login endpoint again to regenerate one.

## Generate Key

{% tabs %}
{% tab title="curl" %}

```sh
curl --location --request POST 'https://api.terrak.io/users/generate_key' \
--header 'Authorization: YOUR_TOKEN'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = 'https://api.terrak.io/users/generate_key'
headers = {
    'Authorization': 'YOUR_TOKEN'
}

response = requests.post(url, headers=headers)
print(response.json())
```

{% endtab %}
{% endtabs %}

This endpoint will generate your API key or refresh it if it has already been generated previously. This will return `{"apiKey" : YOUR_APIKEY}`. You can use this apiKey to access the core api endpoints of terrakio such as WMS and WCS requests by putting it as part of the 'x-api-key' header or as part of the 'api-key' url parameter.

## View Key

{% tabs %}
{% tab title="curl" %}

```sh
curl --location 'https://api.terrak.io/users/key' \
--header 'Authorization: YOUR_TOKEN'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = 'https://api.terrak.io/users/key'
headers = {
    'Authorization': 'YOUR_TOKEN'
}

response = requests.get(url, headers=headers)
print(response.json())
```

{% endtab %}
{% endtabs %}

This will return `{"apiKey" : YOUR_APIKEY}`. You can use this apiKey to access the core api endpoints of terrakio such as WMS and WCS requests by putting it as part of the 'x-api-key' header or as part of the 'api-key' url parameter.


---

# 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://test-341.gitbook.io/terrakio/terrak.io/authentication.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.
