Answer
If you're experiencing the error:
"Unable to retrieve folders. The response from Microsoft couldn't be processed correctly."
The response from Microsoft couldn't be processed correctly" when calling the Get all Folders endpoint for Microsoft accounts, this typically indicates an issue with processing complex folder hierarchies. Especially if there are folders with a high volume of child folders, example:
{
"id": "99887766554433221100",
"grant_id": "a12b34cd-12ef-12ui-90cd-ef1234567890",
"name": "Folders Test",
"object": "folder",
"attributes": [],
"total_count": 0,
"unread_count": 0,
"parent_id": "AQMkAGQyNzFiY2QtZDM1Zi00ZTU3LTg1NTQtNDIxZjU5NzFkYjM1LgAuAAAD7ZDp65SFBKZT6KcA0JNVwQEAwM7HaJwKcAtV34U7BAAAIBCAAAAA==",
"child_count": 289
}
Solution
Use the single_level parameter to retrieve folders from a single-level hierarchy only:
Â
API Request:
curl --request GET \
--url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/folders?single_level=true' \
--header 'Accept: application/json, application/gzip' \
--header 'Authorization: Bearer <NYLAS_API_KEY>' \
--header 'Content-Type: application/json'
Â
For a complete workaround that retrieves all folders including nested ones:
1. First, get top-level folders:
GET /v3/grants/{grant_id}/folders?single_level=true
2. Then, loop through each folder that has children:
GET /v3/grants/{grant_id}/folders?parent_id={folder_id}
Example workflow:
-
Call the API with
single_level=trueto get the initial folder list -
For each folder in the response that has
child_count > 0, make additional requests using that folder'sidas theparent_idparameter - Repeat this process for any sub-folders that also have children
- Continue until you've retrieved the complete folder hierarchy
When to Use This Parameter
- When experiencing timeout errors or processing failures with Microsoft folder requests
- For accounts with complex nested folder structures
- When you need faster response times for folder retrieval
Additional Troubleshooting
If the issue persists even with single_level=true:
-
Try reducing the
limitparameter (e.g.,limit=20or lower) - Consider implementing pagination to retrieve folders in smaller batches
- Contact Nylas support if the problem continues
For more information, see the Get all Folders endpoint documentation.
Â
Updated
Comments
0 comments
Please sign in to leave a comment.