Does `/messages` in Graph API include shared mailboxes? - microsoft-graph-api

I'm calling https://graph.microsoft.com/v1.0/users/{user_id}/messages/ to paginate through all user messages. I'm using app permissions for access, which works fine.
But I'm getting more messages than expected, and I'm not sure why. Is it possible the /messages endpoint includes messages from shared mailboxes available to user_id, too?
If so, what is the way to suppress that? Thanks.

What gives you the impression that you are getting more messages than is expected? Note that /messages returns all of the messages in the mailbox across all of the folders.
The documentation states that shared message access is performed with delegated permissions. You shouldn't be seeing shared messages when using application permissions. Does your application use the Mail.Read.Shared or Mail.ReadWrite.Shared scopes? If so, you should be able to remove them and I'd expect it shouldn't have access.

From Microsoft's Known Issues page:
GET messages returns chats in Microsoft Teams
In both the v1 and beta endpoints, the response of GET /users/id/messages includes the user's Microsoft Teams chats that occurred outside the scope of a team or channel. These chat messages have "IM" as their subject.
So the solution is to ignore all messages with subject == "IM".

Related

Missing Permissions for Microsoft Graph Add Chat message

I am trying to use Microsoft.Graph to send add a message to a chat. I have successfully found my team and created a channel for the messages to go into but when I try to actually send the message, I get a Forbidden error message. This is covered by the ticket:
Microsoft Graph API for Teams: Send Channel/ Chat messages and I am getting the same problem that #Koelier originaly got.
The reason that this is not fixed is that following the answer does not fix my problem. Indeed, the ChannelMessage.ReadWrite.All does not appear in my list. I am looking for the app to run as a service, in the background so the Application Permissions is the method I need to use.
I note that I am not alone in this as #johnnycardy notes that he has had exactly the same problem as me. Furthermore, I linked to the document referenced by #nastassiar and it did not reference the ChannelMessage.ReadWrite.All at all. I can assume it did once but not anymore.
Any guidance would be gratefully received.
Just checked the permissions to perform the same using graph explorer and the below are the ones that I had to add.
ChannelMessage.Send - Allows the app to send channel messages in Microsoft Teams, on your behalf.
Chat.ReadWrite - Allows an app to read and write your 1 on 1 or group chat messages in Microsoft Teams, on your behalf.
ChatMessage.Send - Allows an app to send one-to-one and group chat messages in Microsoft Teams, on your behalf.
Group.ReadWrite.All - Allows the app to create groups and read all group properties and memberships on your behalf. Additionally allows the app to manage your groups and to update group content for groups you are a member of.
enter image description here

Can list messages but cant create subscription

I have an app that creates subscriptions for office365 users and does something whenever it gets a notification.
For 99% of users it works fine.
There's one user that I can't create subscription for even though he has an enabled exchange plan.
When I try to create subscription for him I get status code 404 and message: REST API is not yet supported for this mailbox.
However, I can list the user messages (i.e. mails) with API (GET request to https://graph.microsoft.com/v1.0/Users/{user_id}/messages)
Is it normal behavior? That user have no rest services enables for his mailbox (and therefore cant create subscription) but other rest services such as listing messages works just fine?
You are most likely getting this error because the organization has an hybrid deployment (Exchange on prem "linked" to the organization) and the mailbox that's failing is located on premises, not in the cloud.
Your application should handle the error and/or let the administrators know that this mailbox is failing, but there isn't much that can be done besides migrating the mailbox. For reference

Accessing and creating Teams Chats via Graph API

I'm going over the Microsoft Teams section of the Graph API and trying to find out how to do two things:
Create a new chat, giving it a topic that correlates to an entity in our app (essentially creating a chat around an entity), invite specific users into it, and send messages to the chat.
Access the currently logged-in user's private chats, filtered by their topic, and show their contents inside our app.
For #2, it looks like it should be possible using beta endpoint of the Graph API, but I get 403 Forbidden errors both in the Graph Explorer when trying to access https://graph.microsoft.com/beta/me/chats, and in my own app, after enabling the Chat.Read permissons for it.
For #1, it looks like the API doesn't officially support creating new chats at all.
Is there any approach we can use to create and manage chats? Is there an alternative, perhaps not MicrosoftGraph-based API?
as you mention, the ms graph doesn't yet support initiating group chat. You would use the MS Bot Framework for this: https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bot-conversations/bots-conv-proactive
I see the docs on these Chat api do exist, but they are not present in the Graph Explorer. I tired testing them in the OfficeApiEditor tool with a v2.0 App Registration and Delegated permissions (Chat.Read) and i get this:
Failure - Status Code 500
"code": "InternalServerError",
"message": "Error while processing response.",
so maybe it will take some time before they are really available in beta.
In MS teams, there is a api called ChatMessage to post a message to a chat(only if the chat already exist or started). But, there is no api to create/start a new chat. I have raised a feature request. Do vote for this to suggest this idea to Microsoft.
https://microsoftteams.uservoice.com/forums/913786-microsoft-teams-free/suggestions/38776681-it-would-be-awesome-l-if-there-is-an-api-functiona

No longer possible to determine Chats of Microsoft Teams

Until now to get Microsoft Teams messages I check the subject field to see if it contains "IM" as described in the documentation:
GET messages returns chats in Microsoft Teams
In both the v1 and beta endpoints, the response of GET /users/id/messages includes the user's Microsoft Teams chats that occurred outside the scope of a team or channel. These chat messages have "IM" as their subject.
For the past few days, that "IM" is no longer showing up in the subject of the message, so now we have no information to determine if it's a Teams chat.
The "known issue" was that /messages was returning these messages. It sounds like they rolled out a fix for this issue. Since this was considered a bug, the current state is how it was designed to work - /messages was intended to only return email messages.
This is why it's not a good idea to pull a dependency on a known issue; when they fix the issue, it breaks your code. At the moment there doesn't seem to be a mechanism to retrieve these messages but, based on this PR in the documentation, it looks like it will be coming soon.

MS Graph API Teams: Application access to Channel Messages

I am looking at Teams Channel Create Chat Message method (currently only available in beta).
We have an application which manages groups of users and would like to integrate with MS Teams - create a Team, add Channels and send messages to the channel - all without a user. For this I have followed "Get access without a user".
However I notice that for this and other message level functions (list messages) Application permission is "Not Supported" and for our use case Delegated permissions is not really an option (similar to this).
Does anyone know why these are only available for Delegated Permission? is there a plan to enable this or is will this always not be "Not supported" for Application Access?
I appreciate that giving an Application full access to all messages may be something that Admins would not be keen on, but being able to post and retrieve messages from channels the application has created seems (to me) to be reasonable (perhaps the permissions model isn't that fine grained yet).
This is possibly an overlap of Unable to “List channel messages” on Azure AD Graph API Beta - the OPs answer contains an unanswered similar question.
We aren't currently sharing road map externally of when these types of things are being updated.
What we do ask is that you request these on our UserVoice channel so that we can track the demand and prioritize accordingly. If you can go here and add this request I'd appreciate this and I'll let the PM who owns this know https://developer.microsoft.com/en-us/graph/support

Resources