Microsoft Graph API Java - get group using displayName - microsoft-graph-api

I am using Microsoft Graph API( java SDK) to add members to the group. But I see that I could only pull a group using the "id" .But there should be an easy way to pull the group information using name or displayName? I am trying to get the group id, so that I could use it to add members
Group group = graphClient.groups("id")
.buildRequest()
.get();

Have you tried something like this?
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new QueryOption("$filter", "startswith(displayName, 'Hello')"));
IGroupCollectionPage groups = graphClient.groups()
.buildRequest(requestOptions)
.get();
This should filter all groups with "displayName" starting with "Hello".

Related

Graph API .net SDK - Filter Me.MemberOf based on displayName of groups

I am trying to filter out the groups of a user he is a member of based on some words that the group name may contain.
I am using this code -
var groups = _graphServiceClient.Me.MemberOf.Request().Filter($"displayName -eq 'abhi'").GetAsync().Result;
but I am getting the error that filter request is invalid.
Any help with this is always appreciated, thanks.
Based on aad advanced queries here your request is supported when the request headers contains ConsistencyLevel = eventual and count = true
To get it to work here is the sample code:
List<Option> options = new List<Option>();
options.Add(new HeaderOption("ConsistencyLevel", "eventual"));
options.Add(new QueryOption("$filter", $"displayName eq 'abhi'"));
options.Add(new QueryOption("$count", "true"));
var groups = await graphServiceClient.Me
.MemberOf
.Request(options)
.GetAsync();

Finding a message across multiple folder trees with one call with microsoft-graph java sdk

In converting from an older bit of code that uses the EWS (ews-java-api v 2.0) SDK/API/Scope to Graph (microsoft-graph v5.4.0), I found that I could search (say by InternetMessageId) across multiple folder hierarchies at once in EWS with (simplifying how to get FolderId values a bit):
SearchFilter.SearchFilterCollection filter =
new SearchFilter.SearchFilterCollection(LogicalOperator.And);
filter.add(new SearchFilter.IsEqualTo(EmailMessageSchema.InternetMessageId, msgId));
List<FolderId> folders = Arrays.asList(new FolderId("AllItems"), new FolderId("Deletions"));
ItemView view = new ItemView(10);
ServiceResponseCollection<FindItemResponse<Item>> findResultsCollection =
service.findItems(searchFolders, filter, null, view, null, ReturnErrors);
With that EWS search whether my message of interest is in the Inbox, some user-created sub-folder, JunkEmail, DeletedItems, RecoverableItemsDeletions I find it by InternetMessageId in one go.
With Graph I issue two calls to be able to ensure the message does not exist
UserRequestBuilder u = GraphServiceClient
.builder()
.authenticationProvider(authenticationProvider)
.buildClient()
.users(user);
for (String folderTree : Arrays.asList("AllItems", "RecoverableItemsDeletions")) {
MessageCollectionPage mcp = u.mailFolders(folderTree)
.messages()
.buildRequest()
.filter("internetMessageId eq '" + msgId + "'")
.get();
Is there a way to search multiple trees in one go with Graph to be more like the EWS path that took a List?
Use List Messages endpoint to get the messages in the signed-in user's mailbox (including the Deleted Items and Clutter folders).
Depending on the page size and mailbox data, getting messages from a mailbox can incur multiple requests. The default page size is 10 messages. Use $top to customize the page size, within the range of 1 and 1000.
To improve the operation response time, use $select to specify the exact properties you need. Refer documentation here.
Java Code Snippet -
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
MessageCollectionPage messages = graphClient.me().messages()
.buildRequest()
.select("sender,subject")
.get();

Retrieving chatinfo and attendees using MS Graph SDK

Starting with a sample oauth app I am trying to retrieve info about an online meeting that occurred.
Create the client:
var graphClient = _graphServiceClientFactory.GetAuthenticatedGraphClient((ClaimsIdentity)User.Identity);
Make request:
var returnObj = await graphClient.Me.OnlineMeetings.CreateOrGet(meetingID).Request().PostAsync();
The problem is the lack of information returned. I am trying to retrive the chat from the meeting, which seems like it should be in returnObj.ChatInfo but this is all I get back:
{
"threadId":"19:meeting_SOMELONGUNIQUESTRINGHERE#thread.v2",
"messageId":"0",
"#odata.type":"microsoft.graph.chatInfo"
}
Also missing are the attendees in Participants (count=0). I know there are non zero attendees and that a chat log exists.
Trying Select or Expand does not help. Select returns nothing new,and expand gives an error along the lines of Message: Parsing OData Select and Expand failed: Property 'participants' on type 'microsoft.graph.onlineMeeting' is not a navigation property or complex property. Only navigation properties can be expanded., and similarly for chatinfo.
Also, using the threadId I thought maybe I could do this:
var groups = await graphClient.Groups.Request().GetAsync();
Group group = groups[0];
ConversationThread chat;
chat = await graphClient.Groups[group.Id].Threads[chatId].Request().GetAsync();
where for chatId I used the threadId from chatinfo, wholey and parsed out in different ways but I get Not Found.
No idea if what I'm trying to do is even possible as the documentation is rather lacking in terms of tying different pieces together (Like what is the threadId for? where is it used?).
Also, here are the various scopes I am requesting
"GraphScopes": "User.Read User.ReadBasic.All Mail.Send OnlineMeetings.ReadWrite Group.Read.All Team.ReadBasic.All"

Microsoft Graph Java API - Filter Groups based on a boolean value

I am trying to filter the groups using java sdk based on the parameters like mailEnabled or securityEnabled.
I am trying out the following code to perform the same as suggested in the Graph Explorer interface. (https://developer.microsoft.com/en-us/graph/graph-explorer)
LinkedList requestOptions = new LinkedList();
requestOptions.add(new QueryOption("$filter", "mailEnabled+eq+true"));
IGroupCollectionPage groups = graphClient.groups()
.buildRequest(requestOptions)
.get();
But this throws an exceptio saying that "Invalid filter"
I can filter out the groups using the "startsWith" paramter as mentioned in "https://stackoverflow.com/questions/60417041/microsoft-graph-api-java-get-group-using-displayname"
Looks like there is some issue with + sign here.
Any suggestions ?
You can use the below code to get a filtered data for mailEnabled property.
List<Option> requestOptions = new ArrayList<Option>();
requestOptions.add(new QueryOption("$filter", "mailEnabled eq true"));
IGroupCollectionPage data = graphClient.groups()
.buildRequest(requestOptions)
.get();

How to get TFS user groups and users in particular group using TFS API?

I want to list TFS user groups in a DropDown and based on selection of user group I need to populate users in that particular group using TFS API.
This page has several examples: http://blogs.microsoft.co.il/blogs/shair/archive/2009/01/14/tfs-api-part-4-get-tfs-user-list-mail-sid-account-domain.aspx
The last example is probably the most relevant.
IGroupSecurityService gss = (IGroupSecurityService)server.GetService(typeof(IGroupSecurityService));
Identity[] UserId = gss.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None);
// Connect to the team project collection.
TfsConfigurationServer tfsServer = m_tfsServer;
Guid collectionGuid = m_collectionGuid;
TfsTeamProjectCollection tpc = tfsServer.GetTeamProjectCollection(collectionGuid);
// Get the group security service.
var gss = tpc.GetService<IGroupSecurityService2>();
// Retrieve each user's SID.
Identity sids = gss.ReadIdentity(SearchFactor.AccountName, "[My Team Project]\\Contributors", QueryMembership.Expanded);
// Resolve to named identities.
Identity[] users = gss.ReadIdentities(SearchFactor.Sid, sids.Members, QueryMembership.None);

Resources