# Add Agent to Campaign

When integration requires it, agents can be added to a specific campaign through this API. Below, we outline how to perform this action.

<p class="callout info">You can check the [Postman Collection](https://www.postman.com/dev-clever-ideas/ucontact/request/wfrw3il/addagenttocampaign?tab=overview "Add Aget To Campaign") 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;">**Resource**</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/queues/addqueuemember</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><tr><td style="width: 22.284%;">Authorization</td><td style="width: 77.8396%;">Basic {{Token}}</td></tr></tbody></table>

#### Request Body

<table border="1" id="bkmrk-parametro-tipo-descr" style="border-collapse: collapse; width: 100%; height: 59.575px;"><tbody><tr style="height: 29.7875px;"><td class="align-center" style="width: 22.4913%; height: 29.7875px;">**Parameter**</td><td class="align-center" style="width: 17.9194%; height: 29.7875px;">**Type**  
</td><td class="align-center" style="width: 59.5645%; height: 29.7875px;">**Description**</td></tr><tr style="height: 29.7875px;"><td style="width: 22.4913%; height: 29.7875px;">queuemember</td><td style="width: 17.9194%; height: 29.7875px;">Text (String)</td><td style="width: 59.5645%; height: 29.7875px;">An array of objects, where multiple users can be added to multiple campaigns; each object represents a user added to a campaign.</td></tr></tbody></table>

#### JSON Example

```JSON
[
    {
        "membername": "{{UserName}}",
        "queueName": "{{CampaignName}}",
        "interface1": "SIP/{{AgentPhoneNumber}}",
        "penalty": 0,
        "paused": 0
    }
]
```

#### JSON Description

<table border="1" id="bkmrk-parametro-tipo-descr-0" style="border-collapse: collapse; width: 100%; height: 89.3907px;"><tbody><tr style="height: 29.7969px;"><td class="align-center" style="width: 22.6149%; height: 29.7969px;">**Parameter**</td><td class="align-center" style="width: 17.6718%; height: 29.7969px;">**Type**  
</td><td class="align-center" style="width: 59.6886%; height: 29.7969px;">**Description**</td></tr><tr style="height: 29.7969px;"><td style="width: 22.6149%; height: 29.7969px;">UserName</td><td style="width: 17.6718%; height: 29.7969px;">Text (String)</td><td style="width: 59.6886%; height: 29.7969px;">Agent's username</td></tr><tr style="height: 29.7969px;"><td style="width: 22.6149%; height: 29.7969px;">CampaignName</td><td style="width: 17.6718%; height: 29.7969px;">Text (String)</td><td style="width: 59.6886%; height: 29.7969px;">Name of the campaign to which the user wishes to be added</td></tr><tr><td style="width: 22.6149%;"><div><div>PhoneNumber</div></div></td><td style="width: 17.6718%;">Text (String)</td><td style="width: 59.6886%;">Agent's phone number</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/queues/addqueuemember HTTP/1.1
Host: {{domain}}.ucontactcloud.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic {{Token}}
Content-Length: 221

queuemember=[{"membername":"{{UserName}}","queueName":"{{CampaignName}}","interface1":"SIP/{{AgentPhoneNumber}}","penalty":0,"paused":0}]
```

##### cURL

```cURL
curl --location --globoff 'https://{{domain}}.ucontactcloud.com/Integra/resources/queues/addqueuemember' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic {{Token}}' \
--data-urlencode 'queuemember=[{"membername":"{{UserName}}","queueName":"{{CampaignName}}","interface1":"SIP/{{AgentPhoneNumber}}","penalty":0,"paused":0}]'
```

##### JavaScript

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

const urlencoded = new URLSearchParams();
urlencoded.append("queuemember", "[{\"membername\":\"{{UserName}}\",\"queueName\":\"{{CampaignName}}\",\"interface1\":\"SIP/{{AgentPhoneNumber}}\",\"penalty\":0,\"paused\":0}]");

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

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

##### JQuery

```JavaScript
var settings = {
  "url": "https://{{domain}}.ucontactcloud.com/Integra/resources/queues/addqueuemember",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic {{Token}}"
  },
  "data": {
    "queuemember": "[{\"membername\":\"{{UserName}}\",\"queueName\":\"{{CampaignName}}\",\"interface1\":\"SIP/{{AgentPhoneNumber}}\",\"penalty\":0,\"paused\":0}]"
  }
};

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

##### C#

```C#
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://{{domain}}.ucontactcloud.com/Integra/resources/queues/addqueuemember");
request.Headers.Add("Authorization", "Basic {{Token}}");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("queuemember", "[{\"membername\":\"{{UserName}}\",\"queueName\":\"{{CampaignName}}\",\"interface1\":\"SIP/{{AgentPhoneNumber}}\",\"penalty\":0,\"paused\":0}]"));
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, "queuemember=[{\"membername\":\"{{UserName}}\",\"queueName\":\"{{CampaignName}}\",\"interface1\":\"SIP/{{AgentPhoneNumber}}\",\"penalty\":0,\"paused\":0}]");
Request request = new Request.Builder()
  .url("https://{{domain}}.ucontactcloud.com/Integra/resources/queues/addqueuemember")
  .method("POST", body)
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .addHeader("Authorization", "Basic {{Token}}")
  .build();
Response response = client.newCall(request).execute();
```

##### Python

```Python
import http.client

conn = http.client.HTTPSConnection("{{domain}}.ucontactcloud.com")
payload = 'queuemember=[{"membername":"{{UserName}}","queueName":"{{CampaignName}}","interface1":"SIP/{{AgentPhoneNumber}}","penalty":0,"paused":0}]'
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Authorization': 'Basic {{Token}}'
}
conn.request("POST", "/Integra/resources/queues/addqueuemember", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

---

### HTTP Response

<p class="callout warning">Responses indicating an error due to the sent data will generally be delivered with an HTTP 200 code and a "0" or "1" 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 to view the data correctly.</p>

#### Successful Response

```JSON
1
```

#### Error Response

```JavaScript
0
```