# Authentication

To enable users to programatically perform CRUD operations on organizations and SLIs, Os and As we have implemented m2m (machine to machine) authentication. You need to be authenticated in order to access it, i.e. by logging into slaOS on the frontend.&#x20;

## Create token flow

Once logged in, use the javascript provided below to create the token. You can copy and paste this javascript in the browser console and run it.&#x20;

```javascript
(fetch(`${window.location.protocol}//${window.location.host}/api/slaos/v1/users/m2m-token`, {method: 'GET'}).then(response => response.json()).then(json => json["jwt"]).then(console.log))();
```

<figure><img src="/files/QBz3NbGuTYIPviie9BGq" alt=""><figcaption><p>generating the token via browser console</p></figcaption></figure>

This token can be used to access the slaOS APIs programmatically. On our end, the machine will be identified with the id of the user that obtained the token.

{% hint style="info" %}
Note that the token has an expiry date of one year.&#x20;
{% endhint %}

The token is then added  in the API request headers with the value `Authorization: Bearer <token>`

Your token carries many privileges, so be sure to keep them secure! Do not share your token in publicly accessible areas such as GitHub, client-side code, and so forth.

All API requests must be made over [HTTPS](http://en.wikipedia.org/wiki/HTTP_Secure). Calls made over plain HTTP will fail. API requests without authentication will also fail.

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

<pre class="language-java"><code class="lang-java"><strong>#Authenticated Request
</strong>curl -v -X 'POST' \
'https://api.rated.co/v1/slos/' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer &#x3C;YOUR-TOKEN-HERE>'
-d '{
  "name": "Uptime percentage SLO",
  "description": "Uptime percentage must be greater than 99.9% for the calendar month",
  "service_level_indicator_id": "string",
  "time_window_type": "calendar",
  "time_window_value": "1",
  "time_window_unit": "month",
  "target_value": "99.9",
  "target_unit": "percentage",
  "interval": 86400,
  "on_missing_interval": "exclude",
  "benchmark_operator": "ge",
  "benchmark_value": "50000"
}'
</code></pre>

{% endtab %}

{% tab title="undefined" %}

```python
import requests

# api endpoint
url = "https://api.rated.co/v1/slos/"

# headers with authorization
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <YOUR-TOKEN-HERE>",
}

# data payload
data = {
    "name": "Uptime percentage SLO",
    "description": "Uptime percentage must be greater than 99.9% for the calendar month",
    "service_level_indicator_id": "string",
    "time_window_type": "calendar",
    "time_window_value": "1",
    "time_window_unit": "month",
    "target_value": "99.9",
    "target_unit": "percentage",
    "interval": 86400,
    "on_missing_interval": "exclude",
    "benchmark_operator": "ge",
    "benchmark_value": "50000",
}

# send post request
response = requests.post(url, headers=headers, json=data)

# print response
print(response.status_code)
print(response.json())

```

{% 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.rated.co/api-beta/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.
