# Hacer Llamada

En algunas ocasiones, es necesario que un agente genere una llamada a un número de teléfono desde otra aplicación, como podría ser un CRM. Se puede utilizar esta API, y la llamada será enviada al agente.

<p class="callout info">Usted puede verificar la [Colección de Postman](https://www.postman.com/dev-clever-ideas/ucontact/request/lly7qi2/agentcall?tab=overview "Agent Call") para ver un ejemplo y probar con su instancia.</p>

<p class="callout info">Todos los datos que esten encerrados por "{{ }}" son valores que serán reemplazado con los datos del propio cliente y/o la instancia correspondiente.</p>

---

### HTTP Request

<table border="1" id="bkmrk-opci%C3%B3n-http-valor-re" style="border-collapse: collapse; width: 100%; height: 89.3625px;"><tbody><tr style="height: 29.7875px;"><td class="align-center" style="width: 22.284%; height: 29.7875px;">**Metodo**</td><td class="align-center" style="width: 77.8396%; height: 29.7875px;">**Recurso**</td></tr><tr style="height: 29.7875px;"><td style="width: 22.284%; height: 29.7875px;">POST</td><td style="width: 77.8396%; height: 29.7875px;">/Integra/resources/Agents/AgentCall</td></tr></tbody></table>

#### Request Header


<table border="1" id="bkmrk-opcion-valor-content" style="width: 116.914%; height: 107px;"><tbody><tr><td class="align-center" style="width: 22.3747%;">**Clave**</td><td class="align-center" style="width: 77.7241%;">**Valor**</td></tr><tr><td style="width: 22.3747%;">Content-Type</td><td style="width: 77.7241%;">application/x-www-form-urlencoded</td></tr><tr><td style="width: 22.3747%;">Authorization</td><td style="width: 77.7241%;">Basic {{Token}}</td></tr></tbody></table>

#### Request Body

<table border="1" id="bkmrk-parametro-tipo-descr" style="border-collapse: collapse; width: 100%; height: 279.788px;"><tbody><tr style="height: 29.7875px;"><td class="align-center" style="width: 21.997%; height: 29.7875px;">**Parametro**</td><td class="align-center" style="width: 13.4701%; height: 29.7875px;">**Tipo**  
</td><td style="width: 14.5867%; height: 29.7875px;">**Requerido**</td><td class="align-center" style="width: 50.045%; height: 29.7875px;">**Descripción**</td></tr><tr style="height: 46.4px;"><td style="width: 21.997%; height: 46.4px;">callerid</td><td style="width: 13.4701%; height: 46.4px;">Número</td><td class="align-center" style="width: 14.5867%; height: 46.4px;">Si</td><td style="width: 50.045%; height: 46.4px;">DID asignado a la campaña por la cual se realizará la llamada.</td></tr><tr style="height: 29.6px;"><td style="width: 21.997%; height: 29.6px;">agent</td><td style="width: 13.4701%; height: 29.6px;">Texto</td><td class="align-center" style="width: 14.5867%; height: 29.6px;">Si</td><td style="width: 50.045%; height: 29.6px;">Agente que tomará la llamada.</td></tr><tr style="height: 34.4px;"><td style="width: 21.997%; height: 34.4px;"><div><span class="Text__TextContainer-sc-1kqigik-0 ggvUCn sc-fznXWL cEvDCP item-key" data-aether-id="aether-text" data-click="" data-testid="aether-text">phone</span></div></td><td style="width: 13.4701%; height: 34.4px;">Número</td><td class="align-center" style="width: 14.5867%; height: 34.4px;">Si</td><td style="width: 50.045%; height: 34.4px;">Número de teléfono del agente.</td></tr><tr style="height: 29.6px;"><td style="width: 21.997%; height: 29.6px;">tech</td><td style="width: 13.4701%; height: 29.6px;">Texto</td><td class="align-center" style="width: 14.5867%; height: 29.6px;">Si</td><td style="width: 50.045%; height: 29.6px;">Protocolo de comunicación, agregar SIP.</td></tr><tr style="height: 46.4px;"><td style="width: 21.997%; height: 46.4px;">context</td><td style="width: 13.4701%; height: 46.4px;">Texto</td><td class="align-center" style="width: 14.5867%; height: 46.4px;">Si</td><td style="width: 50.045%; height: 46.4px;">Nombre del contexto para flujos por el cual saldrá la llamada. Puede ser "agentes" o "agents"</td></tr><tr style="height: 29.6px;"><td style="width: 21.997%; height: 29.6px;">outqueue</td><td style="width: 13.4701%; height: 29.6px;">Texto</td><td class="align-center" style="width: 14.5867%; height: 29.6px;">Si</td><td style="width: 50.045%; height: 29.6px;">Nombre de la campaña manual.</td></tr><tr style="height: 34px;"><td style="width: 21.997%; height: 34px;">destination</td><td style="width: 13.4701%; height: 34px;">Número</td><td class="align-center" style="width: 14.5867%; height: 34px;">Si</td><td style="width: 50.045%; height: 34px;">Nombre de la campaña por la cual se generará la llamada.</td></tr></tbody></table>

---

### Ejemplos de Código

<p class="callout info">Puede copiar los siguientes ejemplos de codigo y reemplazar las variables "{{variable}}" con los datos correctos.</p>

#### HTTP

```HTTP
POST /Integra/resources/Agents/AgentCall HTTP/1.1
Host: {{instance}}.ucontactcloud.com
Authorization: Basic {{Token}}
Content-Type: application/x-www-form-urlencoded
Content-Length: 116

callerid={{callerid}}agent={{agent}}&phone={{phone}}&tech=SIP&context={{context}}&outqueue={{outqueue}}&destination={{destination}}
```

##### cURL

```cURL
curl --location 'https://{{instance}}.ucontactcloud.com/Integra/resources/Agents/AgentCall' \
--header 'Authorization: Basic {{Token}}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'callerid={{callerid}}' \
--data-urlencode 'agent={{agent}}' \
--data-urlencode 'phone={{phone}}' \
--data-urlencode 'tech=SIP' \
--data-urlencode 'context={{context}}' \
--data-urlencode 'outqueue={{outqueue}}' \
--data-urlencode 'destination={{destination}}'
```

##### JavaScript

```JavaScript
const myHeaders = new Headers();
myHeaders.append("Authorization", "Basic {{Token}}");
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");

const urlencoded = new URLSearchParams();
urlencoded.append("callerid", "{{callerid}}");
urlencoded.append("agent", "{{agent}}");
urlencoded.append("phone", "{{phone}}");
urlencoded.append("tech", "SIP");
urlencoded.append("context", "{{context}}");
urlencoded.append("outqueue", "{{outqueue}}");
urlencoded.append("destination", "{{destination}}");

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: urlencoded,
  redirect: "follow"
};

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

##### JQuery

```JavaScript
var settings = {
  "url": "https://{{instance}}.ucontactcloud.com/Integra/resources/Agents/AgentCall",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Authorization": "Basic {{Token}}",
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "data": {
    "callerid": "{{callerid}}",
    "agent": "{{agent}}",
    "phone": "{{phone}}",
    "tech": "SIP",
    "context": "{{context}}",
    "outqueue": "{{outqueue}}",
    "destination": "{{destination}}"
  }
};

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

##### C#

```C#
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://{{instance}}.ucontactcloud.com/Integra/resources/Agents/AgentCall");
request.Headers.Add("Authorization", "Basic {{Token}}");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("callerid", "{{callerid}}"));
collection.Add(new("agent", "{{agent}}"));
collection.Add(new("phone", "{{phone}}"));
collection.Add(new("tech", "SIP"));
collection.Add(new("context", "{{context}}"));
collection.Add(new("outqueue", "{{outqueue}}"));
collection.Add(new("destination", "{{destination}}"));
var content = new FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

```

##### Java

```Java
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "callerid={{callerid}}&agent={{agent}}&phone={{phone}}&tech=SIP&context={{context}}&outqueue={{outqueue}}&destination={{destination}}");
Request request = new Request.Builder()
  .url("https://{{instance}}.ucontactcloud.com/Integra/resources/Agents/AgentCall")
  .method("POST", body)
  .addHeader("Authorization", "Basic {{Token}}")
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .build();
Response response = client.newCall(request).execute();
```

##### Python

```Python
import http.client

conn = http.client.HTTPSConnection("{{instance}}.ucontactcloud.com")
payload = 'callerid={{callerid}}&agent={{agent}}&phone={{phone}}&tech=SIP&context={{context}}&outqueue={{outqueue}}&destination={{destination}}'
headers = {
  'Authorization': 'Basic {{Token}}',
  'Content-Type': 'application/x-www-form-urlencoded'
}
conn.request("POST", "/Integra/resources/Agents/AgentCall", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

---

### HTTP Response

<p class="callout warning">Las respuestas en las que se obtubo error por parte de los datos enviados por lo general serán entregados con codigo HTTP 200 con un "0" en el body de la respuesta, por lo tanto hay que tener cuidado al validar por el HTTP Code Response.</p>

<p class="callout info">La respuesta exitosa será un GUID como identificador de la llamada; con este dato se podrán realizar futuras acciones mediante APIs.</p>

#### Respuesta exitosa

```XML
8cf8570e-60e7-44ed-b799-3baab211b04d
```

#### Respuesta de error

```JavaScript
0
```