AnsweredAssumed Answered

Update Attribute Value : 500 server error (OSI Web Api - C#)

Question asked by Kailash_Ravuri on May 25, 2017
Latest reply on May 26, 2017 by Kailash_Ravuri

I am trying to update the value of an attribute using WebAPI, but i am getting - The remote server returned an error: (500) Internal Server Error.

The details are :

     I am using .net application to connect to OSI PI WebAPI - using kerberos/basic authentication

     All the get methods are working absolutely fine when try to make a Post/Put methods it is not working at all.

     I tried calling using multiple url schems such as Attribute update value, Stream Update, PiPoint Update

     I am converting a dynamic object to json string and passing it to request


                dynamic postData = new


                    Timestamp = measurementOccurence.ToUniversalTime().ToString(CultureInfo.InvariantCulture),

                    Value = newValue



                string json = JsonConvert.SerializeObject(postData);

                string url = $"attributes/{WebID}/value";

                _webRequestHandler.PostRequestAsync(url, json);


     and my method to make web request is as below

        public ApiResponse PostRequestAsync(string postUrl, string postData)



                var apiResponse = new ApiResponse();

                WebRequest request = WebRequest.Create(BaseUrl + postUrl);

                request.Method = WebRequestMethods.Http.Put;

                //request.Credentials = CredentialCache.DefaultCredentials;

                request.Credentials = new NetworkCredential(_username, _password);

                request.ContentType = JsonRequestContentType;



                byte[] byteArray = Encoding.UTF8.GetBytes(postData);

                request.ContentLength = byteArray.Length;



                Stream requestStream = request.GetRequestStream();

                requestStream.Write(byteArray, 0, byteArray.Length);


                WebResponse response = request.GetResponse();

                apiResponse.Status = ((HttpWebResponse)response).StatusCode;

                apiResponse.ResponseData = ConvertStreamtoJson(response.GetResponseStream());

                return apiResponse;




I am not sure what the reason is but i am getting - The remote server returned an error: (500) Internal Server Error. with no more inner exception details.