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

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?

Related

Microsoft Graph translateExchangeIds not returning the same id as EWS

I am working with both EWS and the Graph API.
I would like to create events (online meetings with skype/teams) in an calendar that is already available via EWS.
To match the calendar to the one available via Graph API i try to use https://learn.microsoft.com/en-us/graph/api/user-translateexchangeids
The calendar i created has this id when returned by the FindFolder call:
<t:FolderId Id="AAMkAGNiY2YxMjY3LTUxYjgtNGI1Yy1hOTM2LTU4MTM5OTZiNjdjYgAuAAAAAABW2gY0kRG1SqggDTNZN6i8AQAPJkKZ1XJkQ6huFmcVa6XaAAGixNZ3AAA=" ChangeKey="..."/>
<t:DisplayName>Test</t:DisplayName>
I create a request to the graph api:
{
"inputIds": [
"AAMkAGNiY2YxMjY3LTUxYjgtNGI1Yy1hOTM2LTU4MTM5OTZiNjdjYgAuAAAAAABW2gY0kRG1SqggDTNZN6i8AQAPJkKZ1XJkQ6huFmcVa6XaAAGixNZ3AAA="
],
"sourceIdType": "ewsId",
"targetIdType": "restId"}
and get the result
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.convertIdResult)",
"value": [
{
"sourceId": "AAMkAGNiY2YxMjY3LTUxYjgtNGI1Yy1hOTM2LTU4MTM5OTZiNjdjYgAuAAAAAABW2gY0kRG1SqggDTNZN6i8AQAPJkKZ1XJkQ6huFmcVa6XaAAGixNZ3AAA=",
"targetId": "AAMkAGNiY2YxMjY3LTUxYjgtNGI1Yy1hOTM2LTU4MTM5OTZiNjdjYgAuAAAAAABW2gY0kRG1SqggDTNZN6i8AQAPJkKZ1XJkQ6huFmcVa6XaAAGixNZ3AAA="
}
]
}
However, if i call https://graph.microsoft.com/v1.0/me/calendars i get a different id
"id": "AAMkAGNiY2YxMjY3LTUxYjgtNGI1Yy1hOTM2LTU4MTM5OTZiNjdjYgBGAAAAAABW2gY0kRG1SqggDTNZN6i8BwBIq5JjIBY-RqWQllrF0GSkAAAAB353AAAPJkKZ1XJkQ6huFmcVa6XaAAGixNowAAA=",
"name": "Test",
Is there a way to match the (ews) calendar i already have to the one returned by the Graph API?
This is a shot in the dark, because I've never dug this deeply into the weeds on the Graph Ids, but you might try calling Graph with the header that selects "immutable ids." I tried to find some details on what this actually means without much luck.
The header is:
request.Header("Prefer", "IdType=\"ImmutableId\"");
HTH, and if not, sorry for guessing.

Sort people by their phone number Microsoft Graph API

I'm trying to get people by their mobilePhone number with graph api in dotnet.
I can I actually get all people who have a mobilePhone defined ?
the object for phones is :
"phones": [
{
"type": "business",
"value": "....."
}
{
"type": "mobilePhone",
"value":"0672737473"
}
]
As you can see it is in an array. I would like to get all people who have the mobile Phone number because business does not concerns my app.
I could get all contacts with paging but I would prefer not having to sort users on my side.
Thanks.
The mobilePhone doesnot support filtering, it is correctly suggested by #Allen Wu.
You can find the details in this documentation

Using filter on /me/joinedTeams not working

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.

Get multiple mobile phone numbers via microsoft graph api from outlook.com contact

Im trying to read all contact data from my outlook.com account into my app via
https://graph.microsoft.com/beta/me/contacts?$top=10000
At first glance, this seems to work well, but later I noticed this:
For contacts with multiple mobile phone numbers, Microsoft only sends the first mobile phone number.
In v1.0 api version of graph, there is simply no field for a second mobile phone number, but in beta api each contact has the property phones, which is a collection of objects of phone resource type. Therefore it should be possible to get multiple mobile phone numbers.
Is this a bug in the API or am I doing something wrong? Is there a different API, that provides all contact data?
EDIT:
As requested per comment: I really mean multiple mobile phone numbers:
It looks like multiple mobile phone numbers isn't supported by Graph. In v1.0 API, each contact has a mobilePhone string property (not an array). In beta Graph API, when you try adding multiple mobile phone numbers to a contact you get the following error:
PATCH https://graph.microsoft.com/beta/me/contacts/{contact-id}
{
"phones": [
{ "number": "1234567891", type: "home"},
{ "number": "9876543210", type: "mobile"},
{ "number": "4564564562", type: "mobile"}, // second mobile number
]
}
// Response
{
"error": {
"code": "ErrorInvalidProperty",
"message": "The multi-value property Phones has too many entries of the following type: of type: contacts:PhoneNumber:MobilePhone. The maximum number allowed is 1.",
"innerError": {
"request-id": "578d85ba-e467-47a4-8cc1-5671fde4a83f",
"date": "2017-12-29T20:07:46"
}
}
}
However, you can get all phone numbers for all contacts in one call when contacts have different types of numbers - home, mobile, etc. I just tested this with an outlook.com account and here are the API calls to set multiple phone numbers on a contact and get them all in one API call.
I found a random contact to test with, copied their ID and made a PATCH request to https://graph.microsoft.com/beta/me/contacts/[contact-id].
Patch body:
{
"phones": [
{ "number": "1234567891", type: "home"},
{ "number": "9876543210", type: "mobile"},
]
}
To confirm the phones were in fact updated, I sent a request to GET https://graph.microsoft.com/beta/me/contacts/[contact-id]/phones and the two phone numbers were returned in the JSON response.
Sending this same request to the v1.0 endpoint won't work since there isn't a phones property on a contact. However, you can still get this data in v1.0 since it's just split across multiple fields.
It looks like sending a request to GET https://graph.microsoft.com/beta/me/contacts?$select=phones returns phones for all users.
The beta API is subject to change so we don't recommend building production applications that depend on the this endpoint. Please keep an eye on the public changelog for when this will move to v1.0.
If you would like to see support for multiple mobile phones in Graph API, please post on our UserVoice.

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

Resources