Failing to expand extensions on only one account - microsoft-graph-api

Trying to run just a basic https://graph.microsoft.com/v1.0/me?$expand=extensions
But either get this error
Expected ',' instead of '{'
with
{"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity"{
"error": {
"code": "BadRequest",
"message": "The entity instance value of type 'microsoft.graph.user' doesn't have a value for property 'id'. To compute an entity's metadata, its key and concurrency-token property values must be provided.",
"innerError": {
"request-id": "39759fbe-06ed-4176-8cc3-efe167a532cb",
"date": "2017-05-17T22:47:35"
}
}
}
I am trying to find the id of my openExtensions my account so I can delete some to make room because I must of accidentally added too many but I can't even get a list of the extensions and I can't even filter it by id. All works fine with other accounts I think i must have just bricked my account while playing around with it. Any ideas?
EDIT
Trying the query https://graph.microsoft.com/v1.0/me?$select=id,displayName&$expand=extensions
results in
{"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,extensions)/$entity","id":"MY ID","displayName":"MY NAME","extensions#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('MY ID')/extensions","extensions":[{"#odata.type":"#microsoft.graph.openTypeExtension"{
"error": {
"code": "InternalServerError",
"message": "Unsupported extension property type.",
"innerError": {
"request-id": "9fe3c7aa-f3d8-48be-90e4-b440516f9010",
"date": "2017-05-17T23:14:46"
}
}
}

I think I just ran into a similar problem.
I created my extension like this
var ext = new OpenTypeExtension();
ext.ExtensionName = "[Unique Name]";
ext.AdditionalData = new Dictionary<string, object>();
ext.AdditionalData.Add("[settingName]", "[settingValue]");
await graph.Me.Extensions.Request().AddAsync(ext);
But now I can no longer expand the extensions property for my account.
var profile = await graph.Me
.Request()
.Expand("extensions")
.GetAsync();
This throws a Microsoft.Graph.ServiceException:
Code: generalException
Message: Unexpected exception returned from the service.
When I try to make the request in the graph explorer, I get the following response,
{
"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity"
{
"error": {
"code": "BadRequest",
"message": "The entity instance value of type 'microsoft.graph.user' doesn't have a value for property 'id'. To compute an entity's metadata, its key and concurrency-token property values must be provided.",
"innerError": {
"request-id": "5e3887db-1687-461a-8d5c-da0f34eea83b",
"date": "2018-06-01T01:41:12"
}
}
}
}

So one of our devs took a look at the data and it looks like you were calling the API incorrectly - which was valid JSON, but not what our service can handle - especially on read back.
It looks like when you were creating an open extension, you were pushing the following in the payload:
{ "openTypeExtension": {
"#odata.type": "#Microsoft.Graph.Extensibility.openTypeExtension",
"extensionName": "roaming.settings",
"randvalue": 1
} }
But the openTypeExtension bit is not required and throws us off on a read back. What you should be sending is:
{
"#odata.type": "#Microsoft.Graph.Extensibility.openTypeExtension",
"extensionName": "roaming.settings",
"randvalue": 1
}
We've implemented a fix to prevent this in the future, which will roll out next week.
We have the IDs for your extensions, so you could delete them, but we're not sure how to communicate these to you securely. If you are OK with us providing them on this thread, please let us know.
Hope this helps,

I got the same error. I use Graph API lib.
Finally I was able to retrieve the extension other way - using Users.Extensions property (I guess it can be done against current user analogically - Me.Extensions).
I added the extension this way:
var additionalData = new Dictionary<string, object> { { "DataName", value } };
await graph.Users["userId"]
.Extensions
.Request()
.AddAsync(new OpenTypeExtension { ExtensionName = "uniqueExtensionName", AdditionalData = additionalData });
..and retrieving:
var extensionObject = ( await graph.Users["userId"].Extensions.Request().GetAsync() )
.CurrentPage[0];

Related

How to Filter Query Results from Microsoft-Graph-People?

I am trying to make a Get Request to the Microsoft Graph API for a specific user's email within my organization. Therefore, I have created the following query, to return the displayName, scoredEmailAddresses, and userPrincipalName for user "jane doe", whose userPrincipalName endsWith #something.com (see below). However, when I run this query in Graph Explorer, I receive the error below. Can any advise how I can fix this query?
QUERY:
https://graph.microsoft.com/v1.0/me/people?$search="Jane
Doe"&$select=displayName,scoredEmailAddresses,userPrincipalName&$count=true&$filter=endsWith(userPrincipalName,
'#something.com')
ERROR:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes.",
"innerError": {
"date": "2022-07-26T14:16:45",
}
}
}
It looks like that userPrincipalName does not support filtering.
If I try the simple filter query
https://graph.microsoft.com/v1.0/me/people?$filter=userPrincipalName eq 'john.doe#something.com'
The response returns an error
{
"error": {
"code": "ErrorInvalidProperty",
"message": "The property 'UserPrincipalName' does not support filtering.",
"innerError": {
"date": "2022-07-27T09:45:45",
"request-id": "9500af61-d1a9-4c9b-b405-05f9c07c81f1",
"client-request-id": "a0bda440-4f9b-aa4a-5d6c-4a0271bda023"
}
}
}
If you can directly search the user by following below API , why you are

Microsoft Graph API: Teams App - Problem with "List members of a channel" using "team id"

I have a Teams App with a bot and am attempting to use Microsoft Graph API to retrieve all the members of a channel conversation.
According to the Microsoft Doc here, the GET URL is...
GET https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/members
When I send a bot mention in the channel, it provides an event context dictionary which includes a "channelData" param like the below (slightly redacted with "X"):
channelData: {
teamsChannelId: '19:9b9d91fb85ec4146972XXXXXXXXXXXXX.tacv2',
teamsTeamId: '19:B9zDXPWNaGn03wB8iifYw6XXXXXXXXXXXXXX#thread.tacv2',
channel: { id: '19:9b9d91fb85ec414XXXXXXXXXXXXXXXXa#thread.tacv2' },
team: {
id: '19:B9zDXPWNaGn03wB8iifYw6XXXXXXXXXXXXXX#thread.tacv2'
},
tenant: { id: 'b06932a5-6eed-4e9a-XXXX-XXXXXXXXX' }
However, when I make a call to the GET endpoint with teams-id = team{id} or tenant{id} and channel-id = channel{id} it returns the following:
{
"error": {
"code": "NotFound",
"message": "No Team found with Group id: b06932a5-6eed-4e9a-XXXX-XXXXXXXXX",
"innerError": {
"message": "No Team found with Group id: b06932a5-6eed-4e9a-XXXX-XXXXXXXXX",
"code": "ItemNotFound",
"innerError": {},
"date": "2022-05-30T21:13:42",
"request-id": "d8e2dfc5-0410-422b-b79d-96b73f38196b",
"client-request-id": "d8e2dfc5-0410-422b-b79d-96b73f38196b"
}
}
}
I think what the API really wants is team-id = "groupID" because when I go into the Teams Desktop app and "Get link to channel" it gives me the following...
https://teams.microsoft.com/l/channel/19%3a3ca3a04e49c447XXXXXXXXXXXXXXXXXXthread.tacv2/Test%2520Channel%25201?groupId=8325270c-856a-4271-XXXXXXXXXXXXXX&tenantId=b06932a5-6eed-4e9a-XXXX-XXXXXXXX
...and then if I use the "groupId" in the same GET call, it gives the expected response where all the members of the conversation are listed.
Now, this would be totally fine except...I can't fine the "groupId" anywhere in the bot message turn context...even on the "onMembersAdded" event which occurs when the bot is first added.
I've read every article / forum listing I can find on this, but so far am completely stumped...hopefully I'm missing something simple that someone can point out!
Ok, finally figured this out...the link here shows how to get additional context for the bot.
You have to call the TeamsInfo.getTeamDetails(turnContext) to retrieve the aadGroupID:
export class MyBot extends TeamsActivityHandler {
constructor() {
super();
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
this.onMessage(async (turnContext, next) => {
const teamDetails = await TeamsInfo.getTeamDetails(turnContext);
if (teamDetails) {
await turnContext.sendActivity(`The group ID is: ${teamDetails.aadGroupId}`);
} else {
await turnContext.sendActivity('This message did not come from a channel in a team.');
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
}
}

Get 404 "The resource could not be found" when call /beta/informationprotection/policy/labels

according to documentation we may use the following endpoints for fetching sensitivity labels:
/me/informationProtection/policy/labels (using delegated permissions)
/informationProtection/policy/labels (using application permission. App should have InformationProtectionPolicy.Read.All permission to use this end point)
The following C# code uses app permissions and it works on tenant1:
static void Main(string[] args)
{
string accessToken = getTokenImpl().Result;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("User-Agent", "PostmanRuntime/7.24.1");
using (var response = client.GetAsync($"https://graph.microsoft.com/beta/informationprotection/policy/labels").Result)
{
using (var content = response.Content)
{
string result = content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
Console.WriteLine(result);
}
}
}
}
}
private static async Task<string> getTokenImpl()
{
string clientId = "...";
string clientSecret = "...";
string tenant = "{...}.onmicrosoft.com";
string authority = string.Format("https://login.microsoftonline.com/{0}", tenant);
var authContext = new AuthenticationContext(authority);
var creds = new ClientCredential(clientId, clientSecret);
var authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", creds);
return authResult.AccessToken;
}
But it doesn't work on another tenant2 - there it always returns 404 "The resource could not be found" with the following inner exception "User not found to have labels, policy is empty". Here is full response:
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"code": "notFound",
"message": "User not found to have labels, policy is empty",
"target": "userId",
"exception": null,
"date": "2020-11-18T09:29:20",
"request-id": "657ad51c-9cab-49f2-a242-50929cdc6950",
"client-request-id": "657ad51c-9cab-49f2-a242-50929cdc6950"
}
}
}
Interesting that attempt to call endpoint /me/informationProtection/policy/labels with delegated permissions on the same tenant2 gives the same error, but on tenant1 it also works. Did anybody face with this problem or have idea why it may happen? Need to mention that on tenant2 earlier we created and published several sensitivity labels for specific user - this user doesn't have neither O365 license nor Azure subscription. I.e. when you try to login to SPO/Azure and create site/group - sensitivity labels were not shown at all for this user. We tried to remove these sensitivity labels and their policies with audience targeting to this user, but both end points still return error.
PS. AAD app is Ok on tenant2 - it has InformationProtectionPolicy.Read.All permission and admin consent is granted:
Update 2020-11-25: behavior has been changed on both tenants without any change from our side: now on both tenants we get 502 Bad Gateway. Does MS rolls out this functionality globally now? Here is response which we get now from /beta/me/informationProtection/policy/labels:
{
"error":{
"code":"UnknownError",
"message":"<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body>\r\n<center><h1>502 Bad Gateway</h1></center>\r\n<hr><center>Microsoft-Azure-Application-Gateway/v2</center>\r\n</body>\r\n</html>\r\n",
"innerError":{
"date":"2020-11-25T12:59:51",
"request-id":"93557ae1-b0d9-44a9-bbea-871f18e379ea",
"client-request-id":"93557ae1-b0d9-44a9-bbea-871f18e379ea"
}
}
}
Update 2020-12-07: it started to work by its own. I.e. MS has fixed that on backend side somehow for the tenant when this issue was reproduced.

ErrorInvalidIdMalformed while accessing message through Microsoft Graph API

I am trying to access message using graph API with the following URL.
_graphAPIEndpoint = Uri.EscapeUriString("https://graph.microsoft.com/v1.0/me/messages/8577e5c2-3d1b-4882-b930-02de5ad18809#CH1GMEHUB07.gme.gbl");
However, I keep getting the following response:
{
"error": {
"code": "ErrorInvalidIdMalformed",
"message": "Id is malformed.",
"innerError": {
"request-id": "8b2d8f88-ff5b-44f7-bb71-8867a03136b7",
"date": "2018-06-07T18:00:32"
}
}
}
Any suggestions on what's wrong?
My bad. Message ID value should be taken from id field passed by Graph API. To use message ID, following query works:
_graphAPIEndpoint = "https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq ''"

Sort Events by Start Date

I need to be able to get the events in both directions ASC/DESC using Microsoft Graph API. I'm trying the following API to achieve that:
https://graph.microsoft.com/v1.0/me/events?$orderby=start
However, when I perform the request I get the following error:
{
"error": {
"code": "BadRequest",
"message": "The $orderby expression must evaluate to a single value of primitive type.",
"innerError": {
"request-id": "c00d676d-ef8e-418b-8561-80e08729da71",
"date": "2017-11-16T13:31:59"
}
}
}
Also, I tried to access the date directly:
https://graph.microsoft.com/v1.0/me/events?$orderby=start.dateTime
Got the following error:
{
"error": {
"code": "BadRequest",
"message": "The child type 'start.dateTime' in a cast was not an entity type. Casts can only be performed on entity types.",
"innerError": {
"request-id": "240342f5-d7f6-430b-9bd0-190dc3e1f73b",
"date": "2017-11-16T13:32:39"
}
}
}
Is there a way to sort events by date in ASC/DESC order?
You're very close but you're referencing DateTime incorrectly. The proper format is {parent}/{child}. These will work:
https://graph.microsoft.com/v1.0/me/events?$orderby=start/dateTime
https://graph.microsoft.com/v1.0/me/events?$orderby=start/dateTime desc

Resources