Outlook REST API - getFolders not returning all folders
Asked Answered
H

1

1

I'm just getting started with the Outlook REST API. My baseline is the tutorial that uses node-outlook.

First order of business is to retrieve all of the folders in my mail account.

So I issue this REST request:

GET https://outlook.office.com/api/v2.0/Me/MailFolders

Instead of returning all of my folders, it only returns the "well known" folders:

Clutter
Deleted Items
Drafts
Inbox
Junk Email
Outbox
Sent Items
Trash

Am I missing a query parameter or something that says, "no, really, all of them please"?

UPDATE

I tried a different email account, and I also don't get all of my actual folders, but I get a different subset (some of which are well-known, others aren't).

I am implementing the paging protocol (using the @nextLink parameter) so it's not a matter of page sizes. I am getting these 8 folders on one account, and 18 folders on another.

So there must be something that decides what folders will be returned.

UPDATE 2

I changed to doing a folder sync instead using the "beta" API. In this case, I also get an unnamed folder in the list, which is the parent of the other folders. It comes along with a ChildFolderCount which is accurate. However, when I do a child folder request on that folder id I get the same list.

UPDATE 3

Here's the request url I'm using when I attempt to read the child folders of the one folder that comes back with a non-zero ChildFolderCount.

GET https://outlook.office.com/api/beta/Me/MailFolders/AAMkADRmMzFmNjZmLWU3MjctNGZiNi1iZTg4LTRmNGQwYTVhMDgxYgAuAAAAAAB8IxaZ5KGbQom4EPywGCSdAQDVy0eYwAzLS63k5pohzykCAAAAAAEJAAA=/childfolders
Hifi answered 14/2, 2016 at 22:26 Comment(3)
The docs say that /Me/MailFolders returns the top-level folders, so if you've got child folders (say under the Inbox), they wouldn't be returned. Does the explain the discrepancy you're seeing?Rhiana
In my case, I have all of my folders at the top level, but it's only returning a subset.Hifi
Also, the "ChildFolderCount" property is coming back zero for each folder.Hifi
H
0

Here's what appears to define what folders are returned by this API and what are not:

  • If I create a folder in office365 directly on outlook webmail, it shows up in this query.

  • If I create a folder in Mac Mail, it does not.

Mac Mail accesses the service using EWS, so I would expect a folder created by it would be like any other folder.

So there is something about folders created on Mac Mail that prevents them from being returned by this API.

Folders created in Mac Mail DO show up in web mail and vice versa.

Folders created on an iPhone DO show up, so in my limited testing it looks like Mac Mail may be the only app suffering from this problem. The problem I have is most of my folders were created in Mac Mail and I have no easy way of rebuilding them.

I'm thinking this is just a BUG in the API. At any rate, this answers my original question and should help anyone out there trying to use the new API.

If I find a workaround I'll post it here.

Hifi answered 16/2, 2016 at 0:59 Comment(5)
One thing to note: if you do a folder sync vs. just getting folders, it returns the root folder and all known folders as a flat list, so there's no need to iterate; you just match up parent folder ids to understand the hierarchy. If you just do a sync, it looks like you get only one level at a time.Hifi
Nice catch! I tried creating a folder with EWS and I can reproduce this. Unless you set the FolderClass property when creating it, by default folders created with EWS don't set a value for the PR_CONTAINER_CLASS property, which is used to indicate the type of items a folder holds. It looks like our query for the REST API limits the results to folders with a class of "IPF.Note". The good news is we are already aware of this issue and there's a fix making its way through the process.Rhiana
Awesome! In the meantime, is there a way to fix the folders I've already created?Hifi
You could write some EWS code to update the FolderClass property on these folders or use a MAPI-based viewer (MFCMapi, OutlookSpy, etc.) to set the PR_CONTAINER_CLASS. I'm not sure what you have access to.Rhiana
It looks like there's a similar problem with flagging messages. If I flag a message with Mail.app on the mac (EWS) it doesn't propagate to IMAP clients. But it does if I flag on the web interface, or from another IMAP client.Hifi

© 2022 - 2024 — McMap. All rights reserved.