Skip to content

Commit 5536a00

Browse files
AaronDDMsamuelpx
andauthored
feat: add support for include_hidden_folders query parameter in list folders endpoint (#426)
* feat: add support for include_hidden_folders query parameter in list folders endpoint * Fix conflicts, synchronize tests --------- Co-authored-by: Samuel Xavier <107475513+samuelpx@users.noreply.github.com> Co-authored-by: Samuel Xavier <samuelxpp@gmail.com>
1 parent eb178f1 commit 5536a00

File tree

5 files changed

+178
-3
lines changed

5 files changed

+178
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Unreleased
1111
* Added `raw_mime` field to Message model for Base64url-encoded message data
1212
* Added TrackingOptions model for message tracking configuration
1313
* Maintained backwards compatibility for existing message functionality
14+
* Added support for `include_hidden_folders` query parameter for listing folders (Microsoft only)
1415

1516
v6.9.0
1617
----------------
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Include Hidden Folders Example
2+
3+
This example demonstrates how to use the `include_hidden_folders` query parameter when listing folders with the Nylas Python SDK.
4+
5+
## Overview
6+
7+
The `include_hidden_folders` parameter is Microsoft-specific and allows you to include hidden folders in the folder listing response. By default, this parameter is `False` and hidden folders are not included.
8+
9+
## Prerequisites
10+
11+
1. A Nylas application with Microsoft OAuth configured
12+
2. A valid Nylas API key
13+
3. A grant ID for a Microsoft account
14+
15+
## Setup
16+
17+
1. Set your environment variables:
18+
```bash
19+
export NYLAS_API_KEY="your_api_key_here"
20+
export NYLAS_GRANT_ID="your_grant_id_here"
21+
export NYLAS_API_URI="https://api.us.nylas.com" # Optional, defaults to US
22+
```
23+
24+
2. Install the Nylas Python SDK:
25+
```bash
26+
pip install nylas
27+
```
28+
29+
## Running the Example
30+
31+
```bash
32+
python include_hidden_folders_example.py
33+
```
34+
35+
## Code Explanation
36+
37+
The example demonstrates two scenarios:
38+
39+
1. **Default behavior**: Lists folders without hidden folders
40+
```python
41+
folders_response = nylas.folders.list(
42+
identifier=grant_id,
43+
query_params={"limit": 10}
44+
)
45+
```
46+
47+
2. **With hidden folders**: Lists folders including hidden folders (Microsoft only)
48+
```python
49+
folders_with_hidden_response = nylas.folders.list(
50+
identifier=grant_id,
51+
query_params={
52+
"include_hidden_folders": True,
53+
"limit": 10
54+
}
55+
)
56+
```
57+
58+
## Expected Output
59+
60+
The example will show:
61+
- List of regular folders
62+
- List of folders including hidden ones (if any)
63+
- Comparison showing how many additional hidden folders were found
64+
65+
## Note
66+
67+
This feature is **Microsoft-specific only**. For other providers (Google, IMAP), the `include_hidden_folders` parameter will be ignored.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import os
2+
from nylas import Client
3+
4+
5+
def main():
6+
"""
7+
This example demonstrates how to use the include_hidden_folders parameter
8+
when listing folders with the Nylas SDK.
9+
10+
The include_hidden_folders parameter is Microsoft-specific and when set to True,
11+
it includes hidden folders in the response.
12+
"""
13+
14+
# Initialize the client
15+
nylas = Client(
16+
api_key=os.environ.get("NYLAS_API_KEY"),
17+
api_uri=os.environ.get("NYLAS_API_URI", "https://api.us.nylas.com"),
18+
)
19+
20+
# Get the grant ID from environment variable
21+
grant_id = os.environ.get("NYLAS_GRANT_ID")
22+
23+
if not grant_id:
24+
print("Please set the NYLAS_GRANT_ID environment variable")
25+
return
26+
27+
try:
28+
print("Listing folders without hidden folders (default behavior):")
29+
print("=" * 60)
30+
31+
# List folders without hidden folders (default)
32+
folders_response = nylas.folders.list(
33+
identifier=grant_id, query_params={"limit": 10}
34+
)
35+
36+
for folder in folders_response.data:
37+
print(f"- {folder.name} (ID: {folder.id})")
38+
39+
print(f"\nTotal folders found: {len(folders_response.data)}")
40+
41+
# Now list folders WITH hidden folders (Microsoft only)
42+
print("\n\nListing folders with hidden folders included (Microsoft only):")
43+
print("=" * 70)
44+
45+
folders_with_hidden_response = nylas.folders.list(
46+
identifier=grant_id,
47+
query_params={"include_hidden_folders": True, "limit": 10},
48+
)
49+
50+
for folder in folders_with_hidden_response.data:
51+
print(f"- {folder.name} (ID: {folder.id})")
52+
53+
print(
54+
f"\nTotal folders found (including hidden): {len(folders_with_hidden_response.data)}"
55+
)
56+
57+
# Compare the counts
58+
hidden_count = len(folders_with_hidden_response.data) - len(
59+
folders_response.data
60+
)
61+
if hidden_count > 0:
62+
print(f"\nFound {hidden_count} additional hidden folder(s)")
63+
else:
64+
print("\nNo additional hidden folders found")
65+
66+
except Exception as e:
67+
print(f"Error: {e}")
68+
69+
70+
if __name__ == "__main__":
71+
main()

nylas/models/folders.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class ListFolderQueryParams(ListQueryParams):
8585
8686
Attributes:
8787
parent_id: (Microsoft and EWS only.) Use the ID of a folder to find all child folders it contains.
88+
include_hidden_folders: (Microsoft only) When true, Nylas includes hidden folders in its response.
8889
single_level: (Microsoft only) If true, retrieves folders from a single-level hierarchy only.
8990
If false, retrieves folders across a multi-level hierarchy. Defaults to false.
9091
select (NotRequired[str]): Comma-separated list of fields to return in the response.
@@ -96,6 +97,7 @@ class ListFolderQueryParams(ListQueryParams):
9697
"""
9798

9899
parent_id: NotRequired[str]
100+
include_hidden_folders: NotRequired[bool]
99101
single_level: NotRequired[bool]
100102

101103

tests/resources/test_folders.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ def test_list_folders_with_query_params(self, http_client_list_response):
5858
overrides=None,
5959
)
6060

61+
def test_list_folders_with_include_hidden_folders_param(
62+
self, http_client_list_response
63+
):
64+
folders = Folders(http_client_list_response)
65+
66+
folders.list(
67+
identifier="abc-123", query_params={"include_hidden_folders": True}
68+
)
69+
6170
def test_list_folders_with_single_level_param(self, http_client_list_response):
6271
folders = Folders(http_client_list_response)
6372

@@ -72,6 +81,24 @@ def test_list_folders_with_single_level_param(self, http_client_list_response):
7281
overrides=None,
7382
)
7483

84+
def test_list_folders_with_include_hidden_folders_false(
85+
self, http_client_list_response
86+
):
87+
folders = Folders(http_client_list_response)
88+
89+
folders.list(
90+
identifier="abc-123", query_params={"include_hidden_folders": False}
91+
)
92+
93+
http_client_list_response._execute.assert_called_once_with(
94+
"GET",
95+
"/v3/grants/abc-123/folders",
96+
None,
97+
{"include_hidden_folders": False},
98+
None,
99+
overrides=None,
100+
)
101+
75102
def test_list_folders_with_single_level_false(self, http_client_list_response):
76103
folders = Folders(http_client_list_response)
77104

@@ -86,19 +113,26 @@ def test_list_folders_with_single_level_false(self, http_client_list_response):
86113
overrides=None,
87114
)
88115

89-
def test_list_folders_with_combined_params(self, http_client_list_response):
116+
def test_list_folders_with_multiple_params_including_hidden_folders(
117+
self, http_client_list_response
118+
):
90119
folders = Folders(http_client_list_response)
91120

92121
folders.list(
93122
identifier="abc-123",
94-
query_params={"single_level": True, "parent_id": "parent-123", "limit": 10},
123+
query_params={
124+
"limit": 20,
125+
"parent_id": "parent-123",
126+
"include_hidden_folders": True,
127+
"single_level": True,
128+
},
95129
)
96130

97131
http_client_list_response._execute.assert_called_once_with(
98132
"GET",
99133
"/v3/grants/abc-123/folders",
100134
None,
101-
{"single_level": True, "parent_id": "parent-123", "limit": 10},
135+
{"limit": 20, "parent_id": "parent-123", "include_hidden_folders": True, "single_level": True},
102136
None,
103137
overrides=None,
104138
)

0 commit comments

Comments
 (0)