Hello again Zach,
i think i found the additional method i need to call to mark the message as read, since it does not automatically do it when replied to.
the api method i found is PatchMessage, however, even though the response status is ok - the response body is always empty and the email does not get marked as read - so it does not work for some reason and i don't see an error message or something that will tell me what is the issue.
here is my C# code:
private async Task markAsRead()
{
//Establish Token for System Admin Communication
ApiAauthenticateUserResponse authResult = await core.Authenticate_User_Async(Username, Password);
if (authResult.success == false)
{
//Do Nothing - display error message
lblResult.Text = "failed to get token";
return;
}
else
{
//Save Access Token
accessToken = authResult.accessToken;
//lblResult.Text = accessToken;
}
var url = core.GetOperationURI("mail/message-patch");
PatchMessage patchMessage = new PatchMessage
{
ownerEmailAddress = Username,
folder="Inbox",
markRead = true
};
patchMessage.uid.Add(Convert.ToInt32(hidLatestMsgId.Value));
var jsonData = JsonConvert.SerializeObject(patchMessage);
std.dbg(url, jsonData, accessToken);
using (var requestMarkAsRead = new HttpRequestMessage(HttpMethod.Post, url))
{
requestMarkAsRead.Content = new StringContent(jsonData, Encoding.UTF8, "application/json");
requestMarkAsRead.Headers.Add("Authorization", "Bearer " + accessToken);
//std.dbg("Request headers:");
//foreach (var header in requestMarkAsRead.Headers)
//{
// std.dbg($"{header.Key}: {string.Join(",", header.Value)}");
//}
var requestContent = await requestMarkAsRead.Content.ReadAsStringAsync();
//std.dbg("Request body:");
//std.dbg(requestContent);
using (var clientMarkAsRead = new HttpClient())
{
var responseMarkAsRead = await clientMarkAsRead.SendAsync(requestMarkAsRead);
//std.dbg("Response headers:");
//foreach (var header in responseMarkAsRead.Headers)
//{
// std.dbg($"{header.Key}: {string.Join(",", header.Value)}");
//}
std.dbg("Response status code:", responseMarkAsRead.StatusCode, "responseMarkAsRead.IsSuccessStatusCode:", responseMarkAsRead.IsSuccessStatusCode);
var responseContentMarkAsRead = await responseMarkAsRead.Content.ReadAsStringAsync();
std.dbg("Response body:");
std.dbg(responseContentMarkAsRead);
PatchMessageResponse patchMessageResponse = JsonConvert.DeserializeObject<PatchMessageResponse>(responseContentMarkAsRead);
// Successful response
if (responseMarkAsRead.IsSuccessStatusCode)
{
if (!patchMessageResponse.success)
{
lblSendResults.Text =
$"Message Sent but failed to mark As Read. Error Message:{patchMessageResponse.message}.";
lblSendResults.CssClass = "error";
}
}
else // Unsuccessful response
{
lblSendResults.Text = $"Message Sent but failed to mark As Read.";
lblSendResults.CssClass = "error";
}
//response.EnsureSuccessStatusCode();
}
}
}
The variable responseContentMarkAsRead is always empty, even though the responseMarkAsRead.IsSuccessStatusCode is true.
And to make the code full, here are the 2 classes i am using in the above code:
public class PatchMessage
{
public string ownerEmailAddress { get; set; }
public string folder { get; set; }
public List<int> uid { get; set; } = new List<int>();
public bool markDeleted { get; set; }
public bool markRead { get; set; }
public bool markReplied { get; set; }
public bool markForwarded { get; set; }
public bool markFlagged { get; set; }
public bool bypassRemoteContent { get; set; }
public bool markSpam { get; set; }
public bool markNotSpam { get; set; }
}
public class PatchMessageResponse
{
public bool success { get; set; }
public string message { get; set; }
public Dictionary<string, object> variables { get; set; }
public string actionGuid { get; set; }
}
Thanks a lot,
ilan.