-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathinclude_hidden_folders_example.py
More file actions
71 lines (53 loc) · 2.11 KB
/
Copy pathinclude_hidden_folders_example.py
File metadata and controls
71 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
from nylas import Client
def main():
"""
This example demonstrates how to use the include_hidden_folders parameter
when listing folders with the Nylas SDK.
The include_hidden_folders parameter is Microsoft-specific and when set to True,
it includes hidden folders in the response.
"""
# Initialize the client
nylas = Client(
api_key=os.environ.get("NYLAS_API_KEY"),
api_uri=os.environ.get("NYLAS_API_URI", "https://api.us.nylas.com"),
)
# Get the grant ID from environment variable
grant_id = os.environ.get("NYLAS_GRANT_ID")
if not grant_id:
print("Please set the NYLAS_GRANT_ID environment variable")
return
try:
print("Listing folders without hidden folders (default behavior):")
print("=" * 60)
# List folders without hidden folders (default)
folders_response = nylas.folders.list(
identifier=grant_id, query_params={"limit": 10}
)
for folder in folders_response.data:
print(f"- {folder.name} (ID: {folder.id})")
print(f"\nTotal folders found: {len(folders_response.data)}")
# Now list folders WITH hidden folders (Microsoft only)
print("\n\nListing folders with hidden folders included (Microsoft only):")
print("=" * 70)
folders_with_hidden_response = nylas.folders.list(
identifier=grant_id,
query_params={"include_hidden_folders": True, "limit": 10},
)
for folder in folders_with_hidden_response.data:
print(f"- {folder.name} (ID: {folder.id})")
print(
f"\nTotal folders found (including hidden): {len(folders_with_hidden_response.data)}"
)
# Compare the counts
hidden_count = len(folders_with_hidden_response.data) - len(
folders_response.data
)
if hidden_count > 0:
print(f"\nFound {hidden_count} additional hidden folder(s)")
else:
print("\nNo additional hidden folders found")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()