Microsoftgraph Which Ids to remove license? - microsoft-graph-api

I would like to remove a license from a user using the microsoft graph API. I am currently using graph explorer to experiment with this.
I have not found much information here regarding microsoftgraph. I find the microsoft documentation and examples unclear on this point.
Here is the data I have to work with. graph explorer snip_one I have tried option A)
When I post to the assignLicense endpoint, I get this error message, and I find little information via google/SO about this. graph explorer snip_two Specifically, I find little about
"Cannot convert a primitive value to the expected type 'Edm.Guid'"
{
"error": {
"code": "Request_BadRequest",
"message": "Cannot convert a primitive value to the expected type 'Edm.Guid'. See the inner exception for more details.",
"innerError": {
"request-id": "7e63fcf2-8fce-4a5c-9f40-3348fba1fb13",
"date": "2019-12-05T01:37:14"
}
} }

OK, with more experimentation, the skuID was what was needed in the removedLicenses list

It's the GUID here: https://learn.microsoft.com/en-us/azure/active-directory/enterprise-users/licensing-service-plan-reference
Note there's a link to the latest version in CSV file format.

Related

issue with Microsoft graph api with forward slashes "/" in /me/events/{id}

I am having a similar issue to the post described here.
How to get an event ID from the HitID returned by a Microsoft Graph search query?
In my case I am not trying to do a patch, but just a lookup via the v1.0/me/events/{id} get request. I am using the search API of Microsoft graph API. It returns me a HitId with forward slashes in it. I tried to resolve it in the exact same way as the post describes, but cant seem to get it to work. My id parameter is:
AAMkADgwZjlhNmJjLWNiMGQtNGE5MS1hMDVkLTNkNTU2ZWE5ZmM5ZgBGAAAAAAAjq0f6CrWJSoJ6oKcYbrJfBwAyr2CWzX9CSrX7fgfr1AFOAAAAAAENAAAyr2CWzX9CSrX7fgfr1AFOAAV/rENQAAA=
I replaced the / with %252F and the call still fails. The new request id is:
AAMkADgwZjlhNmJjLWNiMGQtNGE5MS1hMDVkLTNkNTU2ZWE5ZmM5ZgBGAAAAAAAjq0f6CrWJSoJ6oKcYbrJfBwAyr2CWzX9CSrX7fgfr1AFOAAAAAAENAAAyr2CWzX9CSrX7fgfr1AFOAAV%252FrENQAAA=
which still fails in exactly the same way. To isolate the problem I used Microsoft Graph API explorer to test the request, which returns the following error message
{
"error": {
"code": "RequestBroker--ParseUri",
"message": "Resource not found for the segment 'rENQAAA='.",
"innerError": {
"date": "2021-03-18T07:48:24",
"request-id": "83cecc8b-f510-4cf0-b5f1-e4cd5f09e223",
"client-request-id": "530677e9-fa2d-a842-149e-a8db4939f3b8"
}
}
}
I cant seem to find any suitable documentation on how to resolve the issue.
Thanks in advance for any help.
Where ever you get / simply replace it with -. This will resolve your issue.

How to get a list of just files in a particular folder on OneDrive using Microsoft Graph API

Can anybody tell me how to get a list of just files in a particular folder on OneDrive using Microsoft Graph API? I believe I found an approach I have to use but either I don't understand something or it is impossible. I can get a list of children items in a folder. I can use $filter=folder ne null to get just a list of folders but I don't understand how to get a list of files. If I negate the expression, make it $filter=folder eq null it gives me an error. I tried many other possible expressions like $filter=file ne null, $filter=size ne 0 even though it is not exactly a filter for files a files can be 0 size but anyway it gives an error as well.
Update:
Tested in a test tool. It gives
{
"error": {
"code": "invalidRequest",
"message": "Invalid request",
"innerError": {
"date": "2021-02-23T06:25:08",
"request-id": "4d1903d3-d989-4d90-8130-479ac1b24af2",
"client-request-id": "4d1903d3-d989-4d90-8130-479ac1b24af2"
}
}
for this query
https://graph.microsoft.com/v1.0/me/drive/root/children$filter=folder eq null
Here is the link to the tool
https://developer.microsoft.com/en-us/graph/graph-explorer

preferredDataLocation field in microsoft graph API not working in v1.0

I am working on a feature where I need to find preferredDataLocation field for all the users but it turns out that it is currently in beta version. How can we check estimated date of this feature going into stable version? I tried to check on Microsoft 365 Roadmap but couldn't find it. I tried to use following request
https://graph.microsoft.com/v1.0/users/delta$select=id,preferredDataLocation
but it gives the following error
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Invalid property: preferredDataLocation",
"innerError": {
"request-id": "c93a43cb-fa9d-4803-801a-5864439ad66d",
"date": "2020-06-02T09:24:30"
}
}
}
If I use request without delta then it works fine. Example
https://graph.microsoft.com/v1.0/users$select=id,preferredDataLocation
After checking in the metadata the property is not available in v1.0 for users today (only groups). Hence why it fails when requested for delta query. I created a documentation issue to get the documentation fixed.
You can perform the same query using the beta endpoint today as a workaround.

Support for Assigning User Licenses in Microsoft Graph API?

When will support for assigning user licenses in O365 be added for the Microsoft Graph API? Currently in version 1.0, I get the following error when trying to assign a license,
{
"error": {
"code": "Request_BadRequest",
"message": "Property 'assignedLicenses' is read-only and cannot be set.",
"innerError": {
"request-id": "0827887a-4e46-48d6-93c6-81825aeaac61",
"date": "2017-06-16T18:35:29"
}
}
}
Will this be supported in version 2.0? If so, is there a timeframe it will be added?
Assigning licenses is supported, but not through updating the property. This property is indeed read only. We should improve our error message here to indicate how this can be set - sorry about that.
What you need to do is use the assignLicense method. The info is here: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_assignlicense. Please let me know if you have any further challenges using this method.
Hope this helps,

GraphApi API error codes

I am attempting to create a interface between our web application and the GraphApi.
I am currently struggling to handle error correctly as the documentation for graph API seems to be at best incomplete. Is there a reference to full list of errors one should expect.
An example of the issue is where I make a request after my access token has expired. The error code is not on the list (graph.microsoft.io docs/overview/errors page) and in a different format (capitalization). It also seems to vary drastically from the azure error codes such as "Request_BadRequest". This was found in an MSDN article titled "Error codes and error handling | Graph API concepts".
The document states "You may use the information returned here instead of, or in addition to the HTTP status code returned.". However, this is really hard if they are changing despite being out of beta.
example of an error response body:
{ "error": {
"code": "InvalidAuthenticationToken",
"message": "Access token has expired.",
"innerError": {
"request-id": "267438d2-4cc5-4621-9307-2af26d2f5b49",
"date": "2016-02-16T13:30:24"
}
}
}

Resources