> For the complete documentation index, see [llms.txt](https://doklado-mnojd9vj.documentationai.com/llms.txt).
> Use it to discover all available pages before exploring further.

# Obtain access token

Získa access token cez OAuth 2.0 client_credentials.


<PlaygroundComponent />

<BodyParams contentTypes={["application/json"]} defaultType="application/json">
  <ContentType type="application/json">
<ParamField showLocation="false" body="client_id" param-type="string" required="true">

</ParamField>

<ParamField showLocation="false" body="client_secret" param-type="string" required="true">

</ParamField>

<ParamField showLocation="false" body="grant_type" param-type="string" required="true" enum="client_credentials">

</ParamField>

<ParamField showLocation="false" body="scope" param-type="string" required="false" examples-b64="W3sibmFtZSI6ImV4YW1wbGUiLCJ2YWx1ZSI6ImRvY3VtZW50OnNlbmQgZG9jdW1lbnQ6cmVjZWl2ZSJ9XQ==">

</ParamField>
  </ContentType>
</BodyParams>

<Request tabs="curl,python,javascript,go,ruby">

```bash
curl -X POST "https://einvoice-v1-ynyiur6quq-ey.a.run.app/v1/sapi/auth/token" \
  -H "Content-Type: application/json" \
  -d '{
  "client_id": "example_string",
  "client_secret": "example_string",
  "grant_type": "client_credentials",
  "scope": "document:send document:receive"
}'
```

```python
import requests
import json

url = "https://einvoice-v1-ynyiur6quq-ey.a.run.app/v1/sapi/auth/token"
headers = {
  "Content-Type": "application/json"
}
data = {
  "client_id": "example_string",
  "client_secret": "example_string",
  "grant_type": "client_credentials",
  "scope": "document:send document:receive"
}

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

```javascript
const response = await fetch("https://einvoice-v1-ynyiur6quq-ey.a.run.app/v1/sapi/auth/token", {
  method: "POST",
  headers: {
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "client_id": "example_string",
  "client_secret": "example_string",
  "grant_type": "client_credentials",
  "scope": "document:send document:receive"
})
});

const data = await response.json();
console.log(data);
```

```go
package main

import (
    "fmt"
    "net/http"
    "bytes"
    "encoding/json"
)

func main() {
    data := []byte(`{
  "client_id": "example_string",
  "client_secret": "example_string",
  "grant_type": "client_credentials",
  "scope": "document:send document:receive"
}`)

    req, err := http.NewRequest("POST", "https://einvoice-v1-ynyiur6quq-ey.a.run.app/v1/sapi/auth/token", bytes.NewBuffer(data))
    if err != nil {
        panic(err)
    }

    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("Response Status:", resp.Status)
}
```

```ruby
require 'net/http'
require 'json'

uri = URI('https://einvoice-v1-ynyiur6quq-ey.a.run.app/v1/sapi/auth/token')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request.body = '{
  "client_id": "example_string",
  "client_secret": "example_string",
  "grant_type": "client_credentials",
  "scope": "document:send document:receive"
}'

response = http.request(request)
puts response.body
```

</Request>

### Responses

<div data-component="ResponsesCollection"><Expandable title="200 - Úspešná odpoveď podľa V1." default-open="true">

<ResponseField name="access_token" field-type="string" required="false">

</ResponseField>

<ResponseField name="token_type" field-type="string" required="false" enum="Bearer">

</ResponseField>

<ResponseField name="expires_in" field-type="integer" required="false">
Životnosť tokenu v sekundách.
</ResponseField>

<ResponseField name="scope" field-type="string" required="false">

</ResponseField>

<ResponseField name="refresh_token" field-type="string" required="false">
Voliteľné, iba ak je obnova podporovaná.
</ResponseField>

</Expandable>

<Expandable title="400 - Neplatný vstup alebo grant_type." default-open="false">

*Neplatný vstup alebo grant\_type.*

</Expandable>

<Expandable title="401 - Neplatné klientské prístupy." default-open="false">

*Neplatné klientské prístupy.*

</Expandable>

<Expandable title="403 - Prístup nie je povolený." default-open="false">

*Prístup nie je povolený.*

</Expandable>

<Expandable title="423 - Klient je dočasne zablokovaný." default-open="false">

*Klient je dočasne zablokovaný.*

</Expandable>

</div>

<Response tabs={["200","400","401","403","423"]} dropdown="true">

```json
{
  "access_token": "example_string",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "example_string",
  "refresh_token": "example_string"
}
```

```json
{
  "error": "Bad Request",
  "message": "The request contains invalid parameters or malformed data",
  "code": 400,
  "details": [
    {
      "field": "email",
      "message": "Invalid email format"
    }
  ]
}
```

```json
{
  "error": "Unauthorized",
  "message": "Authentication required. Please provide a valid API token",
  "code": 401
}
```

```json
{
  "error": "Forbidden",
  "message": "You don't have permission to access this resource",
  "code": 403
}
```

```json
{
  "error": "Error",
  "message": "Klient je dočasne zablokovaný.",
  "code": 423
}
```

</Response>

