MS Teams Graph API: Get all teams user(s) are apart of - microsoft-graph-api

I want to use the graph api to get the teams a list of users is a member/owner of. I am using this endpoint to pass the list of users, then select the properties of the group that I am interested in:
/beta/users/$filter=id+in+('user-1','user-2','user-15')$expand=transitiveMemberOf($select=id,resourceProvisioningOptions,displayName,mailNickname)&$select=id,resourceProvisioningOptions,displayName
This will return a list of groups the member is apart of, including the Teams the member is apart of (up to 15 users). It will filter the groups to only return id,resourceProvisioningOption,displayName and mailNickname.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,resourceProvisioningOptions,displayName,transitiveMemberOf(id,resourceProvisioningOptions,displayName,mailNickname))",
"value": [
{
"id": "user-1",
"displayName": "Jeff Smith",
"transitiveMemberOf": [
{
"#odata.type": "#microsoft.graph.directoryRole",
"id": "directoryRole-1",
"displayName": null
},
{
"#odata.type": "#microsoft.graph.directoryRole",
"id": "directoryRole-2",
"displayName": null
},
{
"#odata.type": "#microsoft.graph.group",
"id": "team-id-1",
"resourceProvisioningOptions": [
"Team"
],
"displayName": "My Team 1",
"mailNickname": "MyTeam1"
},
{
"#odata.type": "#microsoft.graph.directoryRole",
"id": "directoryRole-3",
"displayName": null
},
{
"#odata.type": "#microsoft.graph.group",
"id": "team-id-2",
"resourceProvisioningOptions": [
"Team"
],
"displayName": "My Team 2",
"mailNickname": "MyTeam2"
}
]
}
]
}
Since the user is apart of Azure directory groups, those are returned, but the resourceProvisioningOptions identifies if the user is on a team. In this case - 2 teams.
Problem
When looking in the Teams App, we see that the user is actually apart of the 10 different teams.
When calling this endpoint: https://graph.microsoft.com/v1.0/users/user-1/joinedTeams we see that the user is apart of 10 teams
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams",
"#odata.count": 10,
"value": [
{
"id": "team-id-1",
"createdDateTime": null,
"displayName": "Team 1",
"description": "Team1",
"internalId": null,
"classification": null,
"specialization": null,
"visibility": null,
"webUrl": null,
"isArchived": false,
"isMembershipLimitedToOwners": null,
"memberSettings": null,
"guestSettings": null,
"messagingSettings": null,
"funSettings": null,
"discoverySettings": null,
"summary": null
},
{
"id": "team-id-2",
"createdDateTime": null,
"displayName": "Team 2",
"description": "Team2",
"internalId": null,
"classification": null,
"specialization": null,
"visibility": null,
"webUrl": null,
"isArchived": false,
"isMembershipLimitedToOwners": null,
"memberSettings": null,
"guestSettings": null,
"messagingSettings": null,
"funSettings": null,
"discoverySettings": null,
"summary": null
},
...
{
"id": "team-id-10",
"createdDateTime": null,
"displayName": "Team 3",
"description": "Team3",
"internalId": null,
"classification": null,
"specialization": null,
"visibility": null,
"webUrl": null,
"isArchived": false,
"isMembershipLimitedToOwners": null,
"memberSettings": null,
"guestSettings": null,
"messagingSettings": null,
"funSettings": null,
"discoverySettings": null,
"summary": null
}
]
}
Questions:
Is there another endpoint that I can use to pass a list of users and get the teams they are owner/member of?
Why is the data different between endpoints
I am trying to avoid calling the /joinedTeams endpoint due to number of users and rate limiting.

You could use the /joinedTeams endpoint, but also put those calls in a batch to MS Graph.
See: https://learn.microsoft.com/en-us/graph/json-batching
This would allow you to send a batch of 20 (i think) requests in one call to the graph making it much faster and less likely to be throttled.

Related

Retrieve homePhone, mobilePhone and faxPhone from Delve Profile using Graph API

I am trying to retrieve the information in the red box via the graph api resource:
https://graph.microsoft.com/beta/me/profile
Here is the return:
"phones": [
{
"displayName": null,
"type": "business",
"number": "xxxxxxxxxx",
"allowedAudiences": "organization",
"createdDateTime": "2021-06-21T23:36:38.0912984Z",
"inference": null,
"lastModifiedDateTime": "2021-06-21T23:36:38.0912984Z",
"id": "a28e87ba-25xx-45xx-8fxx-5f340b597fxx",
"isSearchable": false,
"createdBy": {
"device": null,
"user": null,
"application": {
"displayName": "AAD",
"id": null
}
},
"lastModifiedBy": {
"device": null,
"user": null,
"application": {
"displayName": "AAD",
"id": null
}
},
"source": {
"type": [
"AAD"
]
}
}
],
It looks to only be returning the info from AAD, not the fields in the Delve profile. Upon further research I found these fields are actually linked to the SharePoint online profile. Is there a way to grab this information using the Graph API?

How to build a Ms graph api query filter on array object?

I am planning to leverage List Groups Ms graph API to list O365 groups in my organization and, later filter them for Yammer groups.
When I use this API in graph explorer it returns following response object.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
"#odata.nextLink": "https://graph.microsoft.com/v1.0/groups?,
"value": [
{
"id": "",
"description": "",
"displayName": "",
"groupTypes": [
"Unified"
],
"isAssignableToRole": null,
"mail": "",
"mailEnabled": true,
"mailNickname": "",
"onPremisesDomainName": null,
"onPremisesLastSyncDateTime": null,
"onPremisesNetBiosName": null,
"onPremisesSamAccountName": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": null,
"proxyAddresses": [
"",
"SMTP:",
"smtp:"
],
"renewedDateTime": "2018-09-07T16:23:37Z",
"onPremisesProvisioningErrors": []
},
{
"id": "",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2019-01-11T17:34:30Z",
"**creationOptions**": [
"Team",
"ExchangeProvisioningFlags"
],
"description": "Discuss",
"displayName": "I&O",
"groupTypes": [
"Unified"
],
"isAssignableToRole": null,
"mail": "",
"preferredDataLocation": null,
"proxyAddresses": [
"SPO",
"SMTP:",
"smtp:"
],
"renewedDateTime": "2019-01-11T17:34:30Z",
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [
"Team"
],
"onPremisesProvisioningErrors": []
},
{
"id": "",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-12-10T21:14:47Z",
"**creationOptions**": [
"YammerProvisioning"
],
"description": "",
"displayName": "",
"groupTypes": [
"Unified"
],
"isAssignableToRole": null,
"mailEnabled": true,
"onPremisesDomainName": null,
"onPremisesLastSyncDateTime": null,
"onPremisesNetBiosName": null,
"onPremisesSamAccountName": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": null,
"proxyAddresses": [],
"renewedDateTime": "2018-12-10T21:14:47Z",
"resourceBehaviorOptions": [
"CalendarMemberReadOnly"
],
"resourceProvisioningOptions": [],
"onPremisesProvisioningErrors": []
}
]
}
As you can see each object in json has 'creationOptions', that means a group might have this field populated with some value. I am interested to return only those groups where creationOptions = YammerProvisioning.
But $filter could only applied on string and not on array so I am not sure how would right that query. I tried following but, its Invalid filter clause.
https://graph.microsoft.com/v1.0/groups?$filter=equals(creationOptions,'YammerProvisioning')
Another approach I tried is as follows, it gave same array.
https://graph.microsoft.com/v1.0/groups?$filter=startswith(creationOptions,['YammerProvisioning'])
My goal is to simple fetch all the groups having creationOptions as 'YammerProvisioning'
An help or examples are appreciated :) Thanks
This syntax should work, but it may be unsupported in v1.0.
?$filter=creationOptions/any(r:r+eq+'YammerProvisioning')
Beta endpoint doesn't seem to have creationOptions, but you could try going against resourceBehaviorOptions.
https://www.techmikael.com/2017/11/how-to-list-all-office-365-groups-which.html?m=1
Although it's not reliable in all tenants ("However, not all Yammer-enabled groups are reported by looking at the ResourceBehaviorOptions. It seems like Yammer communities that already used Office 365 Groups before the migration had the property configured while communities converted to Office 365 Groups during the migration did not. Perhaps some background process will update the property for the other groups over time.")
https://office365itpros.com/2020/04/13/moving-yammer-networks-native-mode-microsoft-365/

How do I retrieve the owners of a Distribution List using Microsoft Graph?

I am unsure if I found a bug, or if I am using this the wrong way: I am unable to retrieve the owners of a DL group using Graph.
Steps:
Let's assume my email is admin#contoso.com. I created a Distribution List group in the Microsoft 365 Admin Center of my Exchange server, and set myself (the admin) as the owner of that DL. I named this DL "TestDG1". I also added this same user as the sole member of the DL.
I then visited the Graph Explorer website, logged in as the admin, gave myself Read permissions to access groups, contacts, users, and executed this query:
https://graph.microsoft.com/v1.0/groups/?$filter=startswith(displayName,'TestDG')
I got a successful response with this information:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
"value": [
{
"id": "01234567-89AB-CDEF-0123-456789ABCDEF",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-10-15T18:38:08Z",
"creationOptions": [],
"description": null,
"displayName": "TestDG1",
"groupTypes": [],
"mail": "testdg1#contoso.com",
"mailEnabled": true,
"mailNickname": "TestDG1",
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": null,
"proxyAddresses": [
"SMTP:testdg1#contoso.com"
],
"renewedDateTime": "2018-10-15T18:38:08Z",
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [],
"securityEnabled": false,
"visibility": null,
"onPremisesProvisioningErrors": []
}
]
}
Using the ID of my group (01234567-89AB-CDEF-0123-456789ABCDEF), I checked if I could retrieve that DL's information using:
https://graph.microsoft.com/v1.0/groups/01234567-89AB-CDEF-0123-456789ABCDEF
And I got a successful response:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups/$entity",
"id": "01234567-89AB-CDEF-0123-456789ABCDEF",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-10-15T18:38:08Z",
"creationOptions": [],
"description": null,
"displayName": "TestDG1",
"groupTypes": [],
"mail": "testdg1#contoso.com",
"mailEnabled": true,
"mailNickname": "TestDG1",
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": null,
"proxyAddresses": [
"SMTP:testdg1#contoso.com"
],
"renewedDateTime": "2018-10-15T18:38:08Z",
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [],
"securityEnabled": false,
"visibility": null,
"onPremisesProvisioningErrors": []
}
If I request the owners, nothing comes back. I used two methods:
A) Expanding the owners array:
https://graph.microsoft.com/v1.0/groups/01234567-89AB-CDEF-0123-456789ABCDEF/?$expand=owners
I get a successful response, but the owners array is empty:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups",
"value": [
{
"id": "01234567-89AB-CDEF-0123-456789ABCDEF",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-10-15T18:38:08Z",
"creationOptions": [],
"description": null,
"displayName": "TestDG1",
"groupTypes": [],
"mail": "testdg1#contoso.com",
"mailEnabled": true,
"mailNickname": "TestDG1",
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": null,
"proxyAddresses": [
"SMTP:testdg1#contoso.com"
],
"renewedDateTime": "2018-10-15T18:38:08Z",
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [],
"securityEnabled": false,
"visibility": null,
"onPremisesProvisioningErrors": [],
"owners": []
}
]
}
B) Querying for the DL's owners directly:
https://graph.microsoft.com/v1.0/groups/01234567-89AB-CDEF-0123-456789ABCDEF/owners
I got a successful response, but the value array is empty:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
"value": []
}
Interestingly, I can retrieve the members without problems:
https://graph.microsoft.com/v1.0/groups/01234567-89AB-CDEF-0123-456789ABCDEF/members
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryObjects",
"value": [
{
"#odata.type": "#microsoft.graph.user",
"id": "00001111-2222-3333-4444-555566667777",
"businessPhones": [],
"displayName": "Contoso Administrator",
"givenName": "Admin",
"jobTitle": null,
"mail": "admin#contoso.com",
"mobilePhone": null,
"officeLocation": null,
"preferredLanguage": "en-US",
"surname": "Contoso",
"userPrincipalName": "admin#contoso.com"
}
]
}
Or by expanding members:
https://graph.microsoft.com/v1.0/groups/01234567-89AB-CDEF-0123-456789ABCDEF?$expand=members
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups/$entity",
"id": "01234567-89AB-CDEF-0123-456789ABCDEF",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-10-15T18:38:08Z",
"creationOptions": [],
"description": null,
"displayName": "TestDG1",
"groupTypes": [],
"mail": "testdg1#contoso.com",
"mailEnabled": true,
"mailNickname": "TestDG1",
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"preferredDataLocation": null,
"proxyAddresses": [
"SMTP:testdg1#contoso.com"
],
"renewedDateTime": "2018-10-15T18:38:08Z",
"resourceBehaviorOptions": [],
"resourceProvisioningOptions": [],
"securityEnabled": false,
"visibility": null,
"onPremisesProvisioningErrors": [],
"members": [
{
"#odata.type": "#microsoft.graph.user",
"id": "00001111-2222-3333-4444-555566667777",
"deletedDateTime": null,
"accountEnabled": true,
"ageGroup": null,
"businessPhones": [],
"city": null,
"companyName": null,
"consentProvidedForMinor": null,
"country": null,
"createdDateTime": null,
"department": null,
"displayName": "Contoso Administrator",
"givenName": "Admin",
"jobTitle": null,
…
…
… // and all its properties
}
]
}
So is this a bug, or am I doing something wrong? If it's a bug, where do I report it?
At the moment (as 2019-04-18), owners for mail-enabled security groups and distribution lists are not currently included in owners in Microsoft Graph. Owners are currently available only for security groups (not mail-enabled), and Office 365 groups.

Filter contacts in outlook API using startswith()

I am trying to get a list of contacts that are filtered by email address from Microsoft Outlook API (Contact API). The url I am using for the request is:
https://outlook.office.com/api/v2.0/me/contacts/?$filter=EmailAddresses/any(email: startswith(email/Address,'ab'))
The filter property $filter=EmailAddresses/any(email: email/Address eq 'ab') is working fine.
Here EmailAddresses field is a list containing name, address fields.
UPDATE
Original response :
{
"#odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/Contacts",
"value": [
{
..................................
..................................
"DisplayName": "Abhishek R",
"GivenName": "Abhishek",
"Initials": null,
"MiddleName": null,
"NickName": null,
"Surname": "R",
"Title": null,
"YomiGivenName": null,
"YomiSurname": null,
"YomiCompanyName": null,
"Generation": null,
"ImAddresses": [],
"JobTitle": null,
"CompanyName": null,
"Department": null,
"OfficeLocation": null,
"Profession": null,
"BusinessHomePage": null,
"AssistantName": null,
"Manager": null,
"HomePhones": [],
"MobilePhone1": null,
"BusinessPhones": [],
"SpouseName": null,
"PersonalNotes": null,
"Children": [],
"EmailAddresses": [
{
"Name": "abhishek#gmail.com",
"Address": "abhishek#gmail.com"
},
{
"Name": "abcdef#gmail.com",
"Address": "abcdef#gmail.com"
}
],
"HomeAddress": {},
"BusinessAddress": {},
"OtherAddress": {}
}
]
}
The response I got is:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes."
}
}
Looking for a solution to this.

O365 Graph API, GET /groups return null entities

i'm trying develop an app that integrate with O365 Groups, for that i need all the info i can get. using the Graph API Explorer when i call "https://graph.microsoft.com/v1.0/groups/"
i get answer like this:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups/$entity",
"id": "8143b56b-a4bb-43ef-8b17-a747b1cacec1",
"createdDateTime": "2016-02-23T11:03:33Z",
"description": "asd asd asd ",
"displayName": "Test Group",
"groupTypes": [
"Unified"
],
"mail": "testgroup#fastgroup.onmicrosoft.com",
"mailEnabled": true,
"mailNickname": "testgroup",
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"proxyAddresses": [
"SMTP:testgroup#fastgroup.onmicrosoft.com"
],
"renewedDateTime": "2016-02-23T11:03:33Z",
"securityEnabled": false,
"visibility": "Public"
}
but once i'm calling the same rest function from my app i get most of the entities as null, like this:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups/$entity",
"id": "8143b56b-a4bb-43ef-8b17-a747b1cacec1",
"createdDateTime": null,
"description": null,
"displayName": "Test Group",
"groupTypes": [],
"mail": null,
"mailEnabled": null,
"mailNickname": null,
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"proxyAddresses": [],
"renewedDateTime": null,
"securityEnabled": null,
"visibility": null
}
can someone please tell me what i'm missing?
Access token scopes in my app: Group.Read.All User.Read.
Thanks!
Currently we only return the basic properties of the group with the group.read.all permission. We will be changing that in the future to return all properties (as long as the signed-in user has permissions to read the group property information).
For now you will need to use group.readwrite.all to get the full properties of the group.
I'll update this answer once we make the update.
Hope this helps,

Resources