# Get Access Token From UserID

Endpoint Name: `getaccesstokenfromuserid`

Request type : `POST`

Authorization : None

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

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

### Request Body

<table data-header-hidden><thead><tr><th width="174"></th><th width="93.45452880859375"></th><th width="118.63623046875"></th><th></th></tr></thead><tbody><tr><td>Parameters</td><td>Values</td><td>Required </td><td>Description</td></tr><tr><td>user_id</td><td>string</td><td>Yes</td><td>UserId  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/getaccesstokenfromuserid' \
--form 'user_id="Replace_User_id_Here"' \
--form 'company_name="Replace_Company_Name_Here"'
```

#### Python

* Request Body

```python
import requests

url = "URL/access/klearstack/getaccesstokenfromuserid"

payload = {'user_id': 'Replace_User_id_Here',
'company_name': 'Replace_Company_Name_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("user_id", "Replace_Your_User_id_Here")
  .addFormDataPart("company_name", "Replace_Your_Company_Name_Here")
  .build();
Request request = new Request.Builder()
  .url("URL/access/klearstack/getaccesstokenfromuserid")
  .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('user_id', 'Replace_Your_User_id_Here');
formData.append('company_name', 'Replace_Your_Company_Name_Here');

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'URL/access/klearstack/getaccesstokenfromuserid',
  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("user_id", "Replace_Your_User_id_Here");
formData.append("company_name", "Replace_Your_Company_Name_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/getaccesstokenfromuserid");

xhr.send(formData);
```

### API Response

<table data-header-hidden><thead><tr><th width="150"></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>


---

# 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://klearstack.gitbook.io/klearstack-api-documentation/authentication-and-user-details/get-access-token-from-userid.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.
