# Client Authentication

This resource is used to obtain a token authentication to access the uContact APIs, created for logging in from another application to enable integrations.

<p class="callout info">You can check the [Postman Collection](https://www.postman.com/dev-clever-ideas/ucontact/request/m41rw3t/getusertoken?tab=overview "Client Authentication") to test in your instance.</p>

<p class="callout info">All data enclosed in "{{ }}" are values that will be replaced with the client's own data and/or the corresponding instance.</p>

---

### HTTP Request

<table border="1" id="bkmrk-opcion-http-valor-re" style="border-collapse: collapse; width: 100%; height: 89.3625px;"><tbody><tr style="height: 29.7875px;"><td class="align-center" style="width: 20.3971%; height: 29.7875px;">**Method**</td><td class="align-center" style="width: 79.6029%; height: 29.7875px;">**Resource**</td></tr><tr style="height: 29.7875px;"><td style="width: 20.3971%; height: 29.7875px;">POST</td><td style="width: 79.6029%; height: 29.7875px;">/Integra/resources/auth/getUserToken</td></tr></tbody></table>

#### Request Header


<table border="1" id="bkmrk-key-value-content-ty" style="border-collapse: collapse; width: 100%; height: 89.3907px;"><tbody><tr style="height: 29.7969px;"><td class="align-center" style="width: 20.3971%; height: 29.7969px;">**Key**</td><td class="align-center" style="width: 79.6029%; height: 29.7969px;">**Value**</td></tr><tr style="height: 29.7969px;"><td style="width: 20.3971%; height: 29.7969px;">Content-Type</td><td style="width: 79.6029%; height: 29.7969px;">application/x-www-form-urlencoded</td></tr></tbody></table>

#### Request Body

<table border="1" class="align-center" id="bkmrk-parametro-tipo-descr" style="border-collapse: collapse; width: 100%; height: 89.175px;"><tbody><tr style="height: 29.7875px;"><td style="width: 21.0136%; height: 29.7875px;">**Key**</td><td style="width: 24.9735%; height: 29.7875px;">**Type**</td><td style="width: 54.0129%; height: 29.7875px;">**Description**</td></tr><tr style="height: 29.7875px;"><td class="align-left" style="width: 21.0136%; height: 29.7875px;">user</td><td class="align-left" style="width: 24.9735%; height: 29.7875px;">Text (String)</td><td class="align-left" style="width: 54.0129%; height: 29.7875px;">User Name</td></tr><tr style="height: 29.6px;"><td class="align-left" style="width: 21.0136%; height: 29.6px;">password</td><td class="align-left" style="width: 24.9735%; height: 29.6px;">Text (String)</td><td class="align-left" style="width: 54.0129%; height: 29.6px;">User Password</td></tr></tbody></table>

---

### Code Examples  


<p class="callout info">You can copy the following code examples and replace the "{{variable}}" with the correct data.</p>

#### HTTP

```HTTP
POST /Integra/resources/auth/getUserToken HTTP/1.1
Host: {{domain}}.ucontactcloud.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 32

user={{User}}&password={{Password}}
```

##### cURL

```
curl --location --request POST 'https://{{domain}}.ucontactcloud.com/Integra/resources/auth/getUserToken' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'user={{UserName}}' \
--data-urlencode 'password={{PasswordUser}}'
```

##### JavaScript

```JavaScript
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

var urlencoded = new URLSearchParams();
urlencoded.append("user", "{{UserName}}");
urlencoded.append("password", "{{PasswordUser}}");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded,
  redirect: 'follow'
};

fetch("https://{{domain}}.ucontactcloud.com/Integra/resources/auth/getUserToken", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

##### JQuery

```JavaScript
var settings = {
  "url": "https://{{domain}}.ucontactcloud.com/Integra/resources/auth/getUserToken",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "data": {
    "user": "{{UserName}}",
    "password": "{{PasswordUser}}"
  }
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
```

##### C#

```C#
var client = new RestClient("https://{{domain}}.ucontactcloud.com/Integra/resources/auth/getUserToken");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("user", "{{User}}");
request.AddParameter("password", "{{UserPassword}}");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
```

##### Java

```Java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "user={{User}}&password={{UserPassword}}");
Request request = new Request.Builder()
  .url("https://{{domain}}.ucontactcloud.com/Integra/resources/auth/getUserToken")
  .method("POST", body)
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .build();
Response response = client.newCall(request).execute();
```

---

### HTTP Response

```
"{{token}}"
```

#### Respuesta de error

```
"0"
```