Graph Explorer ErrorInvalidIdMalformed - microsoft-graph-api

I am using
https://developer.microsoft.com/graph/graph-explorer/
to test out some things. When I use
https://graph.microsoft.com/v1.0/me/mailFolders
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages
I get what I expect, a list of my folders and messages in my Inbox. When change me to my email address I get the same information. Now when I try using a different mailbox I have access to and try to get the messages in "Interesting Messages" I get the ErrorInvalidIdMalformed. I assume the issue is the space in the path
https://graph.microsoft.com/v1.0/users/otheremail#company.com/mailFolders/Interesting Messages/messages
{
"error": {
"code": "ErrorInvalidIdMalformed",
"message": "Id is malformed.",
"innerError": {
"request-id": "f47d4c3b-5681-4b83-b8f4-c2b9be591ff6",
"date": "2019-02-07T22:39:31"
}
}
I've tried using %20 instead of the space and I still get the error. Is there a way of having spaces in the URL or do I need to get the mailbox renamed?
TIA,
Joe

As per the docs for get messages
https://learn.microsoft.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0
GET /users/otheremail#company.com/mailFolders/{id}/messages
You have to use the {id} of the mailFolder. That's why you are getting "ErrorInvalidIdMalformed" as its expecting an id.
You can get this by calling
GET /users/{id | userPrincipalName}/mailFolders
https://learn.microsoft.com/en-us/graph/api/user-list-mailfolders?view=graph-rest-1.0

Related

Teams Export API not allowing me to filter by channel

I'm trying to use the Teams Export API to export a single Teams channel. I have my permissions set up properly; if I make a request to
https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages (without specifying a filter), I get the paginated results of all of the channel messages on my team. If I copy the sample datetime filters in that documentation, I also get a successful response with the appropriate results.
A successful response gives me a list of messages. Each one shows a channelIdentity field, which contains a channelId (fields removed for readability):
{
"value": [
{
"channelIdentity": {
"teamId": "{TEAM ID}",
"channelId": "{CHANNEL ID}"
},
},
]
}
What I want is to use this channelIdentity/channelId field as a filter on the results, so that I can export just the messages from a single channel.
If I run GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=channelIdentity/channelId eq '{CHANNEL ID}', I get an error:
{
"error": {
"code": "BadRequest",
"message": "The entity property 'channelIdentity/channelId' and operationKind 'Equal' is not allowed in $filter query.",
"innerError": {
"date": "2022-11-16T23:47:06",
"request-id": "...",
"client-request-id": "..."
}
}
}
This reads to me like I'm not allowed to use eq with this ID. If I try a 'starts with', I get a different error:
GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=startswith(channelIdentity/teamId, '{CHANNEL ID}')
{
"error": {
"code": "BadRequest",
"message": "Only binary operation expressions are allowed.",
"innerError": {
"date": "2022-11-17T00:11:26",
"request-id": "...",
"client-request-id": "..."
}
}
}
I'm unclear on what this is trying to say - either the ID starts with that phrase or it doesn't; it seems like a binary expression to me.
Is there some other approach I should use to get these results filtered by channel ID?
This API is designed to export everything from a team for backup/archival scenario. So, filtering by a specific channel is not supported now.
If you wish you may suggest this feature on Microsoft Feedback portal.
Any reason why you don't use List Channel Messages?
You can then make a GET call against this URL:
"https://graph.microsoft.com/v1.0/teams/{teamid}/channels/{channel id}/messages"
Note - as per that link you will need to Request access:
https://learn.microsoft.com/en-us/graph/teams-protected-apis
One other method, if you are using Graph Explorer, is add the signed-in user to the team as an owner, and it will let you test this method, you just won't be able to call via an App Registration until you do fill out that form.

Proper syntax for MS GraphAPI filter IN operator

I am trying to simplify a GraphAPI request to get a list of mail folders based on a displayName filter. This seems to work with the eq operator but not with in. Below are the two requests, which should return the same result.
Using eq:
https://graph.microsoft.com/v1.0/me/mailfolders?$filter=displayName eq 'inbox' or displayName eq 'drafts'
Using in:
https://graph.microsoft.com/v1.0/me/mailfolders?$filter=displayName in ('inbox', 'drafts')
When using in I get the error below:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes.",
"innerError": {
"date": "2022-02-16T16:48:51",
"request-id": "",
"client-request-id": ""
}
}
}
From the documentation I've read in should be supported wherever eq is supported by default. Syntax should be correct based on examples I found here: https://learn.microsoft.com/en-us/graph/query-parameters#examples-using-the-filter-query-operator
Can someone shed some light on what the issue might be?
Your last statement applies only to directory objects (resources that are documented as inheriting from the directoryObject resource.
mailFolder isn't one of them
for inbox for example, you can use directly this:
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox
Source: https://learn.microsoft.com/en-us/graph/api/resources/mailfolder?view=graph-rest-1.0

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

"UnknownError" when trying to GET https://graph.microsoft.com/beta/teams/{id}/channels/{id}/messages

When trying to get messages as Admin (with Group.Read.All scope) I am getting following error:
{
"error": {
"code": "UnknownError",
"message": "",
"innerError": {
"request-id": "fc234750-dd35-4748-a1b3-baf4a7c5267c",
"date": "2018-11-14T09:16:55"
}
}
}
Getting teams and channels works.
I tried the same using my user (not an admin, just regular user that created the conversation) in graph explorer and everything works ok.
Is this a bug or a feature (only user giving his permission explicitly allows the app to read conversations) ?
Are you a member of the team? Admins don't get special privileges when working with messages – in order to read a message, they have to be a member of the team like anyone else.

Resources