# 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></th><th></th></tr></thead><tbody><tr><td>Parameters</td><td>Description</td><td>Required or Optional</td></tr><tr><td>user_id</td><td>UserId  of the user</td><td>Required</td></tr><tr><td>company_name</td><td>Name of the company for which the user is logging in</td><td>Required</td></tr></tbody></table>

### Request Code Samples

#### Shell

* Request Body

```sh
curl --location 'https://test.klearstack.com/access/klearstack/getaccesstokenfromuserid' \
--form 'user_id="Replace_User_id_Here"' \
--form 'company_name="Replace_Company_Name_Here"'
```

#### Python

* Request Body

```python
import requests

# API URL
url = "URL/access/klearstack/getaccesstokenfromuserid"

# Request payload
data = {
    'user_id': 'Replace_User_id_Here',
    'company_name': 'Replace_Company_Name_Here'
}

# Make the POST request
response = requests.post(url, data=data)

# Print the response
if response.status_code == 200:
    print(response.json())
else:
    print("Error:", response.text)

```

#### Java

* Request Body

```java
import okhttp3.*;

import java.io.IOException;

public class ApiRequestExample {

    public static void main(String[] args) {
        OkHttpClient client = new OkHttpClient();

        // Form data (username, company_name, password)
        RequestBody formBody = new FormBody.Builder()
                .add("user_id", "Replace_User_id_Here")
                .add("company_name", "Replace_Company_Name_Here")
                .build();

        // Create the request
        Request request = new Request.Builder()
                .url("URL/access/klearstack/getaccesstokenfromuserid")
                .post(formBody)
                .addHeader("Content-Type", "application/x-www-form-urlencoded")
                .build();

        // Execute the request and handle the response
        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) {
                System.out.println("Response: " + response.body().string());
            } else {
                System.out.println("Error: " + response.body().string());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

```

#### Nodejs

* Request Body

```typescript
var request = require('request');

const form_data = {
  'user_id': 'Replace_User_id_Here',
  'company_name': 'Replace_Company_Name_Here',
};

const options = {
  url: 'URL/access/klearstack/getaccesstokenfromuserid',
  formData: form_data,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
};

request.post(options, function(err, httpResponse, body) {
  if (err) {
    console.error('Request failed:', err);
    return;
  }

  console.log('Response:', body);
});

```

#### Javascript

* Request Body

```javascript
// Create a new FormData object
var data = new FormData();
data.append('user_id', 'Replace_User_id_Here');
data.append('company_name', 'Replace_Company_Name_Here');

// Create a new XMLHttpRequest object
var xhr = new XMLHttpRequest();

// Set up the request
xhr.addEventListener("readystatechange", function () {
    if (this.readyState === this.DONE) {
        console.log(this.responseText); // Log the response
    }
});

// Open the request
xhr.open("POST", "URL/access/klearstack/getaccesstokenfromuserid");

// Set the Authorization header (if necessary)
xhr.setRequestHeader("Authorization", "Basic " + btoa("REPLACE_API_KEY:"));

// Send the request
xhr.send(data);
```

### 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>
