03-17-2016 03:32 AM - last edited on 03-25-2019 07:30 PM by ciscomoderator
Hi , i'm developping an app to update the resources skills with REST API.
I can get all the values I want (GET) , but when I try to update a resource using PUT , then I get a webException "415 Unsupported Media Type".
I have discovered that C#/UCCX work with the request.MediaType (instead of request.ContentType).
I had this error when I was trying to GET the data. now it works for the GET .
But for the PUT I have the error. , Method is set as PUT , MediaType="application/xml"
I have tried empty , "text/xml" ...
Looked on internet , websites always saying to specify ContentType/MediaType = "application/xml" , what I have already done.
I got also the same error if I try a PUT request and without sending data.
Thanks for your help !
public string MakeRequest()
{
var request = (HttpWebRequest)WebRequest.Create(EndPoint);
request.Credentials = new System.Net.NetworkCredential(login, password);
request.Method = Method.ToString();
request.ContentLength = 0;
request.Accept = ContentType;
request.MediaType = ContentType;
#region if PUT
if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.PUT)
{
var encoding = new UTF8Encoding();
PostData = PostData.Replace("\n", "");
var bytes = Encoding.UTF8.GetBytes(PostData);
request.ContentLength = bytes.Length;
using (var writeStream = request.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
}
}
#endregion
try
{
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;
if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}
// grab the response
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}
return responseValue;
}
}
catch (WebException wex)
{
string error = wex.Message;
return "";
}
Solved! Go to Solution.
03-17-2016 05:48 AM
Ok got you, in that case post your query at the below forum as well which is looked specifically by the Developers and you can expect a concrete reply/explanation on the same
https://communities.cisco.com/community/developer/express-configuration-api
Regards
Deepak
03-17-2016 05:38 AM
Not sure why you are creating an app when you already have Rest APIs available to do all this within UCCX natively starting version 9.x
http://developer.cisco.com/site/uccxapi/documentation/
Regards
Deepak
03-17-2016 05:42 AM
Hi , i'm creating an app as I want to adapt the skills of a team based on an excel file that can be changed everyday by the Supervisor. instead of changing one by one the agents in the uccx , we will work with a matrix , read by my app. And I'm already using the document you have attached to TRY to modify the resource.
03-17-2016 05:48 AM
Ok got you, in that case post your query at the below forum as well which is looked specifically by the Developers and you can expect a concrete reply/explanation on the same
https://communities.cisco.com/community/developer/express-configuration-api
Regards
Deepak
03-17-2016 05:49 AM
thanks I will post it there !
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide