Dinesh Kumar Lalchand
Dinesh Kumar Lalchand

Reputation: 41

How to pass $value in request to get mime content of mail using graph sdk not api

I am using Graph SDK in C# to read mail messages and I am able to do that. I want Mime Content of my mail message. How do we pass $value in my request using SDK.

Sample code:

mails = await graphserviceclient
    .Me
    .Messages
    .Request()
    .Top(2)
    .GetAsync();

Please let me know how we can pass $value in C# code which uses graphserviceclient.

Upvotes: 3

Views: 2049

Answers (2)

Darrel Miller
Darrel Miller

Reputation: 142242

We are waiting for some metadata updates to make this easier in the SDK. For the moment, the workaround for getting the MIME content looks something like this:

GraphServiceClient graphClient = new 
GraphServiceClient("https://graph.microsoft.com/beta/",authProvider);

var messageId = "...";
var request = graphClient.Me.Messages[messageId].Request()
            .GetHttpRequestMessage();

request.RequestUri = new Uri(request.RequestUri.OriginalString +"/$value");
var response = await graphClient.HttpProvider.SendAsync(request);

var message = await response.Content.ReadAsStringAsync();

In the near future you should be able to do:

var aStream = await graphClient.Me.Messages[messageId].Content.Request().GetAsync();

Upvotes: 8

Marc LaFleur
Marc LaFleur

Reputation: 33122

Regardless of the SDK, you cannot request $value of a collection. The API only allows this on an individual message.

Specifically, in terms of the SDK, this isn't supported. This is still an undocumented preview/feature so you will need to call this endpoint directly rather than through the SDK. It's also worth noting that even if it were supported, the SDK still couldn't deserialize the MIME.

Upvotes: 0

Related Questions