# Authentication

### [OAuth 2.0 Password Grant](https://oauth.net/2/grant-types/password/)

Request

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

```bash
curl --location --request POST 'https://api.butlr.io/api/v2/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "your@email.com",
    "password": "your_password"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.butlr.io/api/v2/login"
  method := "POST"

  payload := strings.NewReader(`{
    "username": "your@email.com",
    "password": "your_password"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.butlr.io/api/v2/login"

payload = json.dumps({
  "username": "your@email.com",
  "password": "your_password"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

Response

```json
{
    "access_token": "your_access_token",
    "refresh_token": "your_refresh_token",
    "id_token": "your_id_token",
    "scope": "your_scopes",
    "expires_in": 1000,
    "token_type": "Bearer"
}
```

### [OAuth 2.0 Client Credentials Grant](https://oauth.net/2/grant-types/client-credentials/)

#### How to create your client credentials

1. Go to the [Butlr Web App](https://app.butlr.io).
2. Sign in using your username and password.
3. Click the expandable menu (v) in the top navigation bar (upper right corner) and select **Account Settings**.

<figure><img src="/files/MZZSnflAe1C7sbPfQTP7" alt=""><figcaption></figcaption></figure>

4. Navigate to the **API tokens** tab.
5. Click the **Create token** button.
6. Enter a **Name** and a **Description**, then click **Create**.
7. A dialog box will display your **Client ID** and **Client Secret**.

<figure><img src="/files/SiBhdWuRvT1zqJXXNKCe" alt=""><figcaption></figcaption></figure>

* ⚠️ Important: Be sure to copy and securely store these credentials. For security reasons, they will not be shown again after you close the dialog.

Request

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

```bash
curl --location --request POST 'https://api.butlr.io/api/v2/clients/login' \
--header 'Content-Type: application/json' \
--data '{
    "client_id": "your_client_id",
    "client_secret": "your_client_secret",
    "audience": "https://butlrauth/",
    "grant_type": "client_credentials"
}'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.butlr.io/api/v2/clients/login"
  method := "POST"

  payload := strings.NewReader(`{
    "client_id": "your_client_id",
    "client_secret": "your_client_secret",
    "audience": "https://butlrauth/",
    "grant_type": "client_credentials"
}`)

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")

  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.butlr.io/api/v2/clients/login"

payload = json.dumps({
  "client_id": "your_client_id",
  "client_secret": "your_client_secret",
  "audience": "https://butlrauth/",
  "grant_type": "client_credentials"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Response**

```json
{
    "access_token": "your_access_token",
    "scope": "your_scopes",
    "expires_in": 1000,
    "token_type": "Bearer"
}
```


---

# 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.butlr.io/getting-started/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.
