# Agent Authentication

When an integration with uContact involving agent activities is required, authentication is performed through this resource, which logs the agent into the SIP. This allows the agent to be considered for calls and to interact via VoIP, in addition to having access.

<p class="callout info">You can check the [Postman Collection](https://www.postman.com/dev-clever-ideas/ucontact/request/ixfd2hv/agentlogin?tab=overview "Agent 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-opci%C3%B3n-http-valor-re" style="border-collapse: collapse; width: 100%; height: 89.3907px;"><tbody><tr style="height: 29.7969px;"><td class="align-center" style="width: 22.284%; height: 29.7969px;">**Method**</td><td class="align-center" style="width: 77.8396%; height: 29.7969px;">**Value**</td></tr><tr style="height: 29.7969px;"><td style="width: 22.284%; height: 29.7969px;">POST</td><td style="width: 77.8396%; height: 29.7969px;">/Integra/resources/auth/AgentLogin</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: 22.284%; height: 29.7969px;">**Key**</td><td class="align-center" style="width: 77.8396%; height: 29.7969px;">**Value**</td></tr><tr style="height: 29.7969px;"><td style="width: 22.284%; height: 29.7969px;">Content-Type</td><td style="width: 77.8396%; height: 29.7969px;">application/x-www-form-urlencoded</td></tr></tbody></table>



#### Request Body

<table border="1" id="bkmrk-parametro-tipo-descr" style="border-collapse: collapse; width: 100%; height: 89.3907px;"><tbody><tr style="height: 29.7969px;"><td class="align-center" style="width: 33.2909%; height: 29.7969px;">**Parameter**</td><td class="align-center" style="width: 33.2909%; height: 29.7969px;">**Type**  
</td><td class="align-center" style="width: 33.2948%; height: 29.7969px;">**Description**</td></tr><tr style="height: 29.7969px;"><td style="width: 33.2909%; height: 29.7969px;">agent</td><td style="width: 33.2909%; height: 29.7969px;">Text (String)</td><td style="width: 33.2948%; height: 29.7969px;">User Agent</td></tr><tr style="height: 29.7969px;"><td style="width: 33.2909%; height: 29.7969px;">password</td><td style="width: 33.2909%; height: 29.7969px;">Text (String)</td><td style="width: 33.2948%; height: 29.7969px;">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/AgentLogin HTTP/1.1
Host: {{dominio}}.ucontactcloud.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 33

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

##### cURL

```cURL
curl --location --request POST 'https://{{dominio}}.ucontactcloud.com/Integra/resources/auth/AgentLogin' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'agent={{Usuario}}' \
--data-urlencode 'password={{AgentPassword}}'
```

##### JavaScript

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

var urlencoded = new URLSearchParams();
urlencoded.append("agent", "{{User}}");
urlencoded.append("password", "{{Password}}");

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

fetch("https://{{domain}}.ucontactcloud.com/Integra/resources/auth/AgentLogin", 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/AgentLogin",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "data": {
    "agent": "{{User}}",
    "password": "{{Password}}"
  }
};

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

##### C#

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

##### Java

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

##### Python

```JavaScript
import http.client

conn = http.client.HTTPSConnection("{{domain}}.ucontactcloud.com")
payload = 'agent={{User}}&password={{Password}}'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded'
}
conn.request("POST", "/Integra/resources/auth/AgentLogin", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

---

### HTTP Response

<p class="callout warning">Responses that indicate an error due to the data sent will generally be returned with an HTTP 200 code and a "0" or "Error" in the body of the response, so caution should be exercised when validating the HTTP Response Code.</p>

<p class="callout warning">The received response is in text format, so it will need to be converted to JSON in order to view the data correctly.</p>

#### Response converted to JSON

```JSON
{
    "id": 4,
    "name": "1997",
    "host": "{{domain}}.ucontactcloud.com",
    "nat": "yes",
    "type": "friend",
    "accountcode": "Vcisneros",
    "callgroup": "",
    "callerid": "1997",
    "canreinvite": "",
    "context": "agents",
    "dtmfmode": "rfc2833",
    "insecure": "",
    "language": "es",
    "mailbox": "",
    "md5secret": "07a46a13aa5434e21e6a9aa870482720",
    "pickupgroup": "",
    "qualify": "yes",
    "secret": "",
    "disallow": "all",
    "allow": "alaw;ulaw",
    "port": "",
    "defaultuser": "1997",
    "subscribecontext": "default",
    "record": "agent",
    "email": "",
    "phonetype": "SoftPhone",
    "LogLevel": "SEVERE",
    "limite": 0,
    "transport": "wss",
    "encryption": "yes",
    "did": "",
    "outboundproxy": "",
    "fullname": "Victor Cisneros",
    "token": "VmNpc25lcm9zOjJhZGUzNjAxLTNhMjgtNDhjNy1hNDg2LTczNTY3ZmI1ZDI2MQ=="
}
```

#### Error Response

```JavaScript
0
```