Using filter on /me/joinedTeams not working - microsoft-graph-api

I'm implementing a search for a user's joined Teams unsing Microsoft Graph. The idea is to make a call to /beta/me/joinedTeams and use a ?$filter=startswith(description,'searchterm') filter.
So for example when I try the request https://graph.microsoft.com/beta/me/joinedTeams?$filter=startswith(description,'Business') in the Microsoft Graph Explorer it ignores the filter and I get these results:
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#groups",
"value": [
{
"id": "02bd9fd6-8f93-4758-87c3-1fb73740a315",
"displayName": "HR Taskforce",
"description": "Welcome to the HR Taskforce team.",
"isArchived": false
},
{
"id": "13be6971-79db-4f33-9d41-b25589ca25af",
"displayName": "Business Development",
"description": "Welcome to the BizDev team.",
"isArchived": false
},
{
"id": "8090c93e-ba7c-433e-9f39-08c7ba07c0b3",
"displayName": "X1050 Launch Team",
"description": "Welcome to the team that we've assembled to launch our product.",
"isArchived": false
}
]
}
Am I doing something wrong with my request?

Your request is right, but the joinedTeams does not support filtering or ordering results. So although we pass the filter/orderby parameter, when Microsoft Graph sees a query parameter it doesn't expect, it simply ignores the unknown filter/orderby parameter and returns an unfiltered/default-sorted result.
I have tried the api with odata query parameters for trial O365 account and real account.
https://developer.microsoft.com/en-us/graph/docs/concepts/query_parameters
Not all parameters are supported across all Microsoft Graph APIs, and
support might differ significantly between the v1.0 and beta
endpoints.
The only suggestion for you is to vote up the existing feature request in User Voice or submit a new one.

Thanks for pointing this out. As Seiya points out, /me/joinedTeams does not support the OData query parameters. The documentation suggested otherwise, I've made a doc fix that should propagate in the next day or two.

Related

Client-side pagination using $skip/$top does not work with Intune

We are currently working on a client application that processes Intune devices by querying all devices on a customer account using the following Microsoft Graph API:
GET https://graph.microsoft.com/v1.0/deviceManagement/managedDevices
After we migrated from our test environment to a Production account we discovered that manual pagination of devices using $skip and $top does not work as per the relevant Microsoft Graph API OData documentation.
As per the said documentation:
$skip: Indexes into a result set. Also used by some APIs to implement paging and can be used together with $top to manually page results.
However, the following query returns an empty result despite there being thousands of devices registered
on the target customer account:
GET https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$top=10&$skip=10
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#deviceManagement/managedDevices",
"#odata.count": 10,
"#odata.nextLink": "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$top=10&$skip=10",
"value": []
}
Also, we found that OData $filter does not work either as demonstrated by the following snippet which queries for devices with operatingSystem equal to 'Android':
GET 'https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$top=100&filter=operatingSystem%20eq%20%27Android%27'
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#deviceManagement/managedDevices",
"#odata.count": 100,
"#odata.nextLink": "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$top=100&$skip=0&filter=operatingSystem+eq+%27Android%27",
"value": [
{
"id": "5bac965e-25e3-4f99-97fb-da21a280f684",
"userId": "some-uuid-value",
"deviceName": "My Iphone",
"managedDeviceOwnerType": "company",
"enrolledDateTime": "2020-02-05T09:52:39Z",
"lastSyncDateTime": "2020-10-19T17:07:20Z",
"operatingSystem": "iOS",
...
We have tested using both v1.0 and beta versions of the said API to no avail. Has anybody got this working?

How to differentiate between Students and Teachers?

In the Microsoft Teams client SDK there is a userLicenseType property which we can use to determine if the user is a student or a teacher.
We want to do the same thing in our backend code to make sure that Students aren't running processes they shouldn't be, but we can't find an easy way of getting this same information from Microsoft Graph.
Does anyone know a way we can find this information? We were hoping it might be available through the access token or through /v1.0/education/me/ or /v1.0/me/ endpoints.
The educationUser has a similar property called primaryRole. You can retrieve this using /v1.0/education/me. Here is an example result:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#education/me/$entity",
"accountEnabled": true,
"displayName": "Megan Bowen",
"givenName": "Megan",
"surname": "Bowen",
"userPrincipalName": "MeganB#M365x214355.onmicrosoft.com",
"userType": "Member",
"id": "48d31887-5fad-4d73-a9f5-3c356e68a038",
"primaryRole": "teacher"
}

Unable to access the Sharepoint List using Microsoft Graph API--

Working with the Microsoft graph api and especially the sharepoint beta api and i am constantly running into issues. I know its beta, but still;)
SO the issue is When i tried to access the sharepoint list using Graph API in graph explorer
URL is: GET https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}
So SiteID i am passing my site tenant GUID and List ID as Sharepoint List GUID
and i am facing the error continously in Response
{
"error": {
"code": "invalidRequest",
"message": "Provided id is not suitable for the current host",
"innerError": {
"request-id": "61efc5b1-88f8-442c-a41d-7213b587318e",
"date": "2017-05-10T07:38:04"
}
}
}
IF any one also has faced this issue please let me know the solution you have resolved
The format of the ID's for sites have changed as part of a set of updates to the API this week. The new format is documented here, but it includes the SharePoint hostname, SPSite.ID, and SPWeb.ID as a triplet:
https://graph.microsoft.com/beta/sites/contoso.sharepoint.com,fc016e3c-d8ae-4ee0-a10c-de6d26788b6a,9a4ea7a5-c3c4-44ae-9f80-273bd67431b8
If you add the hostname into your IDs, your calls should start working again. You can discover the hostname by making a request to:
https://graph.microsoft.com/beta/sites/root/siteCollection/hostname
You can also search for sites now using the following search syntax:
https://graph.microsoft.com/beta/sites?search={keyword}
#Ryan Gregg has the correct answer
The SiteId is not just one GUID but a combination of <HostName,SPSite.ID,SPWeb.ID>.
Example: <contoso.sharepoint.com,fc016e3c-d8ae-4ee0-a10c-de6d26788b6a,9a4ea7a5-c3c4-44ae-9f80-273bd67431b8>
The whole string in the above example is what you should pass for {SiteId} in your request
If you dont have the SPSite.ID but have the URL for the site, you can make a GRAPH API call with relative path to the site
https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/Documetation
This call will return all the properties for the site and you can grab the full SiteId from here:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
"createdDateTime": "2020-04-23T12:18:48.653Z",
"description": "Documentation",
"id": "contoso.sharepoint.com,fc016e3c-d8ae-4ee0-a10c-de6d26788b6a,9a4ea7a5-c3c4-44ae-9f80-273bd67431b8",
"lastModifiedDateTime": "2020-12-09T19:17:21Z",
"name": "Documentation",
"webUrl": "https://contoso.sharepoint.com/sites/Documentation",
"displayName": "Documentation",
"root": {},
"siteCollection": {
"hostname": "contoso.sharepoint.com"
}
}
Try https://graph.microsoft.com/beta/sites/{siteCollectionId},{siteId}/lists
You can find these ids from https://graph.microsoft.com/beta/site/sites

Microsoft API Graph create distribution list

I try to create a distribution list on Office365 with the Microsoft API Graph.
For that, I do a POST request on "https://graph.microsoft.com/beta/blih.bocal.org/groups" with json parameters :
{
"description": "My description",
"displayName": "testlist",
"groupTypes": ['Unified'],
"mailEnabled": True,
"mailNickname": "testlist",
"securityEnabled": False
}
It creates an office365 group or a security group with some little changes, but impossible to create a distribution list. Via the web, I can do it and when I get it with the API, the parameter "groupTypes" is empty.
What's bad on my request or how to do it (if it's possible) ?
http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/group_post_groups
You can create Unified Group or Security Group or Dynamic Group alone with this API. Refer the documentation in the above URL.

Create Plan (BETA) doesn't seem to work

I'm trying to create a planner plan using Graph as per http://graph.microsoft.io/en-us/docs/api-reference/beta/api/user_post_plans
but I'm consistently getting the following BadRequest response:
"error": {
"code": "BadRequest",
"message": "Write requests are only supported on contained entities",
"innerError": {
"request-id": "eae08944-6f47-477e-9950-ade31c473dd7",
"date": "2016-03-07T11:59:04"
}
As per the docs I'm POSTing to https://graph.microsoft.com/beta/me/plans with the following body:
"createdBy": "<my uuid>",
"owner": "<a previously generated group uuid>",
"title": "Blah Plan"
with no luck. The previously generated group looks like the following:
{
"id": "<uuid>",
"classification": null,
"createdDateTime": "2016-03-07T09:53:26Z",
"description": "Int Test",
"displayName": "Int Test",
"groupTypes": [
"Unified"
],
"mail": "<email_address>",
"mailEnabled": true,
"mailNickname": "IntTest",
"onPremisesLastSyncDateTime": null,
"onPremisesSecurityIdentifier": null,
"onPremisesSyncEnabled": null,
"proxyAddresses": [
"SMTP:<email_address>"
],
"renewedDateTime": "2016-03-07T09:53:26Z",
"securityEnabled": false,
"visibility": "Public"
}
I've tried various combinations of request bodies. With and without createdBy values. With and without owner values. Nothing seems to work.
Any ideas where I'm going wrong? The error is consistent across my integration tests as well as through the graph explorer.
Thanks
As Sriram mentioned, this was a documentation bug. It has just been fixed. The updated URL is: https://graph.microsoft.io/en-us/docs/api-reference/beta/api/plan_post_plans
The issue was in which endpoint to call to create a plan. You should call "/plans" instead of "/me/plans". You should also be aware that some of the data you are passing in is read-only. You should not include "createdBy" because this is a read-only property set by the service, not you. The plan resource documentation will show you all of the properties that can be set on a plan.
The last thing to keep in mind is that you can only have one plan per group. If you try to make a second plan, you'll receive an error about this from the API.
In Juli 2017 the API was modified and released. The new endpoint for creating a plan now is:
https://graph.microsoft.com/v1.0/planner/plans
with a request body e.g. like this:
{
"owner": "<group-id>",
"title": "my plan title"
}
where <group-id> must be the id of a previously created group.
Apologies for the confusion here. The documentation has a bug will be updated shortly. To create a plan, please ensure that a group is created, and the user is member of group. Then create the plan with owner set to group id, and createdBy set to user id.
For this issue, can you please try following the below steps exactly?
Create a unified group
Add user to be member of unified group
Create plan by sending {“owner”: group-id, “title”: string} - do not send "createdBy" field since it's a read-only field
For adding tasks to buckets, it should work just fine if you sent
{“planId”: plan-id, “bucketId”: bucket-id, “title”: string}
If this still doesn't work, feel free to reach out to me at lixian#microsoft.com.
Thanks,
Sean

Resources