This example demonstrates how to use the single_level query parameter when listing folders to control folder hierarchy traversal for Microsoft accounts.
The single_level parameter is a Microsoft-only feature that allows you to control whether the folders API returns:
single_level=true: Only top-level folders (single-level hierarchy)single_level=false: All folders including nested ones (multi-level hierarchy, default)
This parameter is useful for:
- Performance optimization: Reducing response size when you only need top-level folders
- UI simplification: Building folder trees incrementally
- Microsoft-specific behavior: Taking advantage of Microsoft's folder hierarchy structure
- Nylas API key
- Nylas grant ID for a Microsoft account (this parameter only works with Microsoft accounts)
-
Install the SDK in development mode:
cd /path/to/nylas-python pip install -e .
-
Set your environment variables:
export NYLAS_API_KEY="your_api_key" export NYLAS_GRANT_ID="your_microsoft_grant_id"
python examples/folders_demo/folders_single_level_example.py- Multi-level folder hierarchy (default behavior)
- Single-level folder hierarchy using
single_level=true - Combined parameters showing how to use
single_levelwith other query parameters - Hierarchy comparison showing the difference in folder counts
The example will show:
- Folders returned with multi-level hierarchy
- Folders returned with single-level hierarchy only
- Count comparison between the two approaches
- How to combine the parameter with other options like
limitandselect
- Folder tree UI: Load top-level folders first, then expand as needed
- Performance: Reduce API response size for Microsoft accounts with deep folder structures
- Microsoft-specific integrations: Take advantage of Microsoft's native folder organization
This parameter only works with Microsoft accounts. If you use it with other providers, it will be ignored.