I'm trying to to update email category and also mark it as read after that with the help of Outlook 365 API
and HttpClient
. Following this tutorial.
In the tutorial the code is as below to update category and mark as read but, I'm not getting that how should I attach these details to HttpClient
and request.
PATCH https://outlook.office.com/api/v2.0/me/messages/AAMkAGE0Mz8S-AAA=
Content-Type: application/json
{
"Categories": [
"Orange category",
"Green category"
],
"IsRead": true
}
The method and HttpClient I'm using are as below:
Update 1
public string UpdateCategory(AuthenticationResult result, string mediator)
{
//HTTPMethod.PATCH not available to adding it manualy.
var httpMethod = new HttpMethod("PATCH");
HttpRequestMessage request = new HttpRequestMessage(httpMethod, mediator);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
//JSON in a string variable for test
var tempJson = @"{""Categories"" : ""Checking""}";
Converting string to JSON
var jsonData = JsonConvert.SerializeObject(tempJson);
//Adding the JSON to request.Content
request.Content =new StringContent(jsonData,Encoding.UTF8, "application/json");
HttpResponseMessage response = httpClient.SendAsync(request).Result;
if (!response.IsSuccessStatusCode)
throw new WebException(response.StatusCode.ToString() + ": " + response.ReasonPhrase);
mediator = response.Content.ReadAsStringAsync().Result;
return mediator;
}
It's throwing Bad Request
error.
I am using 365 API with a WPF application. Please advise.