cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1703
Views
0
Helpful
4
Replies

C# , UCCX , Rest API , PUT (to update a resource) and Unsupported Media Type

alban.faverot
Level 1
Level 1

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 "";
            }

1 Accepted Solution

Accepted Solutions

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

View solution in original post

4 Replies 4

Deepak Rawat
Cisco Employee
Cisco Employee

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

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.

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

thanks I will post it there !