cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

AMA-CUCM Troubleshooting: Best Practices for Reading Trace Files

145
Views
0
Helpful
0
Replies

UCCE - AgentSkill Add/Remove Help

Hi,

When i try to update skills on an agent through the API (on a c# code) on a ucce I am  getting 400 Bad Request.

Here is my c# code where i am m using  HttpWebRequest:

 

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"https://*****/unifiedconfig/config/agent/" + "5056");


XmlDocument xmlDoc = new XmlDocument();
DateTime dtStart;
TimeSpan tsDuration;
try
{
dtStart = DateTime.Now;

req.ProtocolVersion = HttpVersion.Version11;
req.Method = "PUT";

req.ContentType = "application/xml";
// req.Accept = "text/xml";
//req.ContentType = "application/x-www-form-urlencoded";
req.Timeout = 50000;


string auth = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("*****:*****"));
req.Headers.Add("Authorization", "Basic " + auth);

System.Net.ServicePointManager.ServerCertificateValidationCallback =
delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};


string mes = @"<?xml version='1.0' encoding='UTF - 8' standalone='yes'?>
<operation>
<operationType>update</operationType>
<refURLs>
<refURL>/unifiedconfig/config/agent/124</refURL>
</refURLs>
<changeSet>
<agent>
<skillGroupsRemoved>
<skillGroup>
<refURL>/unifiedconfig/config/skillgroup/5023</refURL>
</skillGroup>
</skillGroupsRemoved>
</agent>
</changeSet>
</operation>";

 


req.ContentLength = mes.Length;
Stream s = req.GetRequestStream();

byte[] buffer = System.Text.Encoding.UTF8.GetBytes(mes);

s.Write(buffer, 0, mes.Length);
s.Close();

try
{
string responseStr;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();

if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
responseStr = new StreamReader(responseStream).ReadToEnd();

if (responseStr != "" && responseStr.Length > 1)
{
xmlDoc.LoadXml(responseStr);
}
}
else if (response.StatusCode == HttpStatusCode.NoContent)
{
string aa = @"<Credential><NoContent>204</NoContent></Credential>";
xmlDoc.LoadXml(aa);
}

tsDuration = DateTime.Now.Subtract(dtStart);
// WriteTextFile(logStr + " Completed - Duration: " + tsDuration.TotalMilliseconds + "ms");
}
catch (WebException e)
{
string exMessage = e.Message;
// WriteTextFile(logStr + " - WebException, message:" + exMessage);

if (e.Response != null)
{
using (StreamReader responseReader = new StreamReader(e.Response.GetResponseStream()))
{
exMessage = responseReader.ReadToEnd();
if (exMessage != "")
{
xmlDoc.LoadXml(exMessage);
//WriteTextFile(logStr + " - WebException, the rest of the message:" + exMessage);

}
}
}
}
catch (Exception ex)
{
string excep = ex.ToString();
// WriteTextFile(logStr + " - Exception (WebException), message:" + excep);
}
}
catch (Exception ex)
{
string excep = ex.ToString();
// WriteTextFile(funcName + " - ERROR for sKillTargetID [" + sKillTargetID + "]: " + ex.ToString());
}
return xmlDoc;

 

Kindly need your input on this.

 

Thanks.

Everyone's tags (1)
CreatePlease to create content
Content for Community-Ad
August's Community Spotlight Awards