# Get Access Token

Endpoint Name: `get_access_token`

Request type : `POST`

Authorization : None

Endpoint Details: The get\_access\_token endpoint will be used to get the access token and the refresh token, The validity of the access token will be some minutes, and the refresh token will be days.

<table data-header-hidden><thead><tr><th width="109.6363525390625"></th><th></th></tr></thead><tbody><tr><td>Method</td><td>URL</td></tr><tr><td>POST</td><td><code>URL/access/klearstack/get_access_token</code></td></tr></tbody></table>

### Request Body

<table data-header-hidden><thead><tr><th width="172.6363525390625"></th><th width="94"></th><th width="123.27276611328125"></th><th></th></tr></thead><tbody><tr><td>Parameters</td><td>Values</td><td>Required </td><td>Description</td></tr><tr><td>username</td><td>string</td><td>Yes</td><td>Username of the user to be logged in.</td></tr><tr><td>password</td><td>string</td><td>Yes</td><td>Password of the user.</td></tr><tr><td>company_name</td><td>string</td><td>Yes</td><td>Name of the company for which the user is logging in.</td></tr></tbody></table>

### Request Code Samples

#### Shell

* Request Body

```sh
curl --location "URL/access/klearstack/get_access_token" \
  --form "username=Replace_User_Name_Here" \
  --form "company_name=Replace_Company_Name_Here" \
  --form "password=Replace_Password_Here"
```

#### Python

* Request Body

```python
import requests

url = "URL/access/klearstack/get_access_token"

payload = {'username': 'Replace_User_Name_Here',
'company_name': 'Replace_Company_Name_Here',
'password': 'Replace_Password_Here'}
files=[

]
headers = {}

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

print(response.text)
```

#### Java (OkHttp)

* Request Body

```java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("username", "Replace_Your_Username_Here")
  .addFormDataPart("company_name", "Replace_Your_Company_Name_Here")
  .addFormDataPart("password", "Replace_Your_Password_Here")
  .build();
Request request = new Request.Builder()
  .url("URL/access/klearstack/get_access_token")
  .method("POST", body)
  .build();
Response response = client.newCall(request).execute();
```

#### Nodejs (Axios)

* Request Body

```typescript
const axios = require('axios');
const FormData = require('form-data');

let formData = new FormData();
formData.append('username', 'Replace_Your_Username_Here');
formData.append('company_name', 'Replace_Your_Company_Name_Here');
formData.append('password', 'Replace_Your_Password_Here');

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'URL/access/klearstack/get_access_token',
  headers: { 
    ...formData.getHeaders()
  },
  data: formData
};

axios.request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });
```

#### Javascript (XHR)

* Request Body

```javascript
// WARNING: For POST requests, body is set to null by browsers.

var formData = new FormData();
formData.append("username", "Replace_Your_Username_Here");
formData.append("company_name", "Replace_Your_Company_Name_Here");
formData.append("password", "Replace_Your_Password_Here");

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "URL/access/klearstack/get_access_token");

xhr.send(formData);
```

### API Response

<table data-header-hidden><thead><tr><th width="143"></th><th></th></tr></thead><tbody><tr><td>Status code</td><td>Example Response</td></tr><tr><td>200</td><td><p><code>{</code></p><p>    <code>"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY1NjU3NjA5OCwiaWF0IjoxNjU2NTcdGkiOiI1ZmEzNGM4YjUyOGI0OWM3OWQzNjk5ZWJlNDRlYzUwZiIsInVzZXJfaWQiOjI2fQ.kvpMWPuxenw2c55nucfQCxHLipiO4DhK2TC5NKpJZEk",</code></p><p>    <code>"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjU2NTc2MDM4LCJpYTY1NzU5MTgsImp0aSI6IjQwMWZlYmJhODg4NDQ1MmRhN2Q3ZTA5ZjEwZmYwOWFkIiwidXNlcl9pZCI6MjZ9.sjU6iVbRRp7dTDt-l4rj7K7tKpPpaL7yskjstAUn2Zs",</code></p><p>   <code>"release_version": “7.8.9”</code></p><p><code>}</code></p></td></tr><tr><td>500</td><td>One or Many Required parameters from company name must be missing, E.g error “Company Name”,</td></tr></tbody></table>
