How do I run the query
https://graph.microsoft.com/v1.0/users?$count=true&$search="displayName:room"&$filter=endsWith(mail,'xxxx.com')&$select=id,displayName,mail
in C#?
this is what I have now:
return await _graphServiceClient
.Users.Request()
.Header("ConsistencyLevel", "eventual")
. .Filter($"(endsWith(mail, 'xxxx.com'))&$count=true")
.Select("id,displayName,mail")
.Top(999)
.GetAsync();
Try this code pls:
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true"),
new QueryOption("$search", "\"displayName:tiny\"")
};
var res = await graphClient
.Users.Request(queryOptions)
.Header("ConsistencyLevel", "eventual")
.Filter("endswith(mail,'contoso.com')")
.OrderBy("userPrincipalName")
.Select("id,displayName,mail")
.Top(999)
.GetAsync();
When we follow the official code snippet, we should use .Search() but it will meet exception:
Then let's see github issue here, and we can set search parameter into query option.
Related
var inboxMessages = await graphClient.Me
.MailFolders["Inbox"]
.Messages
.Request()
.Select("sender,subject")
.Top(5)
.GetAsync();
I want to filter the messages by subject and hasAttachment using C#
I am seeing few examples like this ,but how we need implement this in C# in above code?
/v1.0/me/messages?$search="subject:search term"
/v1.0/me/messages?$filter=contains(subject, 'my search term')
Can anyone help me out on this.
You can filter messages with attachments based on the subject that contains specific text like this
var subjectText = "your text";
var inboxMessages = await graphClient.Me
.MailFolders["Inbox"]
.Messages
.Request()
.Select("sender,subject")
.Filter($"hasAttachments eq true and contains(subject,'{subjectText}')")
.Top(5)
.GetAsync();
Documentation:
$filter query operator
I want to copy a mail from one folder to another.
Referring to the documentation, it should work like this:
var graphClient = new GraphServiceClient(authProvider);
var destinationId = "destinationId-value";
await graphClient.Me.Messages["{message-id}"]
.Copy(destinationId)
.Request()
.PostAsync();
However, when I try to use .Copy() like described I get the error, that I can't use it like a method. If I try to add the information as an [], like it's done for the users or messages property, I receive a different error.
I have tried it like this:
var graphClient = GetGraphClientInstance();
var destinationFolderId = "destinationFolderId-value";
await graphClient.Users["myUserName"].Messages[specificMail.Id]
.Copy(destinationFolderId )
.Request()
.PostAsync();
I'm using Microsoft.Graph version 5.0.0-preview-12.
Does anyone have an idea how to use the Copy property correctly?
Using Microsoft.Graph v5 your original code:
var graphClient = new GraphServiceClient(authProvider);
var destinationId = "destinationId-value";
await graphClient.Me.Messages["{message-id}"]
.Copy(destinationId)
.Request()
.PostAsync();
should be changed to:
var graphClient = new GraphServiceClient(authProvider);
var destinationId = "destinationId-value";
await graphClient.Users["myUserName"].Messages[specificMail.Id]
.MicrosoftGraphCopy
.PostAsync(new CopyPostRequestBody { DestinationId = destinationId });
The following piece of code returns a lot more fields than the ones I´ve specified.
var user = await graphClient.Users["{user-id}"]
.Request()
.Select(u => new {
u.DisplayName,
u.JobTitle,
u.GivenName,
u.PostalCode,
u.Identities
})
.GetAsync();
I am following the instructions from ms docs stated here. What am I missing?
I can submit this query to Microsoft Graph Explorer but in C# I get the an error message: "Microsoft.Graph.ServiceException: "Code: Request_UnsupportedQuery
Message: Unsupported Query."
var users = await graphClient.Users
.Request()
.Filter("endswith(mail,'#mydomain.com')")
.OrderBy("userPrincipalName")
.GetAsync();
You should send a header ConsistencyLevel=eventual and also $count query parameter to make it work.
To add $count query parameter you can use queryOptions.
List<QueryOption> queryOptions = new List<QueryOption>
{
new QueryOption("$count", true)
};
var users = await graphClient.Users
.Request(queryOptions)
.Filter("endswith(mail,'#mydomain.com')")
.OrderBy("userPrincipalName")
.GetAsync();
The API call what look something like this
https://graph.microsoft.com/v1.0/users?$count=true&$filter=endswith(mail, '#domain.live')&$orderBy=userPrincipalName
You can always test these calls in Graph Explorer.
I'm trying to get the user's calendar events for today. So I added some query parameters but they're getting ignored and the graph client returns the user's events as if I didn't supply any parameters (startatetime):
var options = new QueryOption[]
{
new QueryOption("startdatetime", DateTime.UtcNow.ToString("o")),
new QueryOption("enddatetime", DateTime.UtcNow.AddDays(1).ToString("o")),
};
var events = await graphServiceClient
.Me
.Calendar
.Events
.Request(options)
.GetAsync();
I tested it in the graph explorer and it works fine. But in the sdk, it returns calendar events that started before today.
Your code is the equivalent of calling:
`/events?startdatetime={dateTime}&enddatetime={dateTime}`.
That is a valid endpoint, but you're passing invalid query params. What you're looking for is calendarView:
`/calendarView?startdatetime={dateTime}&enddatetime={dateTime}`
Using the SDK, this would look like this:
var options = new QueryOption[]
{
new QueryOption("startDateTime", DateTime.UtcNow.ToString("o")),
new QueryOption("endDateTime", DateTime.UtcNow.AddDays(1).ToString("o")),
};
var events = await graphServiceClient
.Me
.CalendarView
.Request(options)
.GetAsync();