I am trying to post a discussion comment to a work item using the REST API version=5.1-preview.3.
Summary
Type: POST and C# HttpClient
However no matter how i try to work with it, i always get the response:
StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'
The inner response is something like this:
{"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: d634683c-0b2e-4bfb-9a66-ee99f32404c6.","typeName":"System.Web.Http.HttpResponseException, System.Web.Http","typeKey":"HttpResponseException..
I send the data/comment in the following JSON format:
[
{
"text": "Test Comment"
}
]
As mentioned in the docs :
Request
I am trying to hit the API:
using the below sample code:
public class Comment
{
[JsonProperty("text")]
public string Text { get; set; }
}
var comment = new Comment()
{
Text = "Test Comment"
};
var comments = new List<Comment>();
comments.Add(comment);
var body = JsonConvert.SerializeObject(comments);
var postValue = new StringContent(body, Encoding.UTF8, "application/json-patch+json");
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _token))));
using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage(new HttpMethod("POST"), _apiUrl) { Content = postValue })
{
var httpResponseMessage = httpClient.SendAsync(httpRequestMessage).Result;
}
}
I believe the above snippet should be able to add a comment to the work item. However no matter how i try to work with it, i always get the response:
Response
StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'
The inner response is something like this:
{"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: d634683c-0b2e-4bfb-9a66-ee99f32404c6.","typeName":"System.Web.Http.HttpResponseException, System.Web.Http","typeKey":"HttpResponseException..
Could you please help me here?
Thanks in advance!