Skip to content

Commit 443e661

Browse files
authored
feat: add support for include_hidden_folders query parameter in folders API (#285)
1 parent 1ab79b2 commit 443e661

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Support for `logo` field in `EmailTemplate` class to specify a custom logo URL for booking emails
88
* Support for `show_nylas_branding` field in `EmailTemplate` class to control Nylas branding visibility in booking emails
99
* Support for `metadata` field type in `AdditionalFieldType` enum for scheduler additional fields
10+
* Support for `include_hidden_folders` query parameter in `ListFoldersQueryParams` for Microsoft accounts to control whether hidden folders are included in the response
1011

1112
## [2.10.0] - Release 2025-06-12
1213

examples/src/main/java/com/nylas/examples/FoldersExample.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,42 @@ public static void main(String[] args) {
6262
System.out.println();
6363
}
6464

65+
System.out.println("\n📁 Listing folders including hidden ones (Microsoft only)...");
66+
67+
// List folders including hidden folders (Microsoft only)
68+
ListFoldersQueryParams hiddenFoldersParams = new ListFoldersQueryParams.Builder()
69+
.includeHiddenFolders(true) // This is the new parameter - Microsoft only
70+
.limit(50)
71+
.build();
72+
73+
ListResponse<Folder> hiddenFolders = nylasClient.folders().list(grantId, hiddenFoldersParams);
74+
System.out.println("Found " + hiddenFolders.getData().size() + " folders including hidden ones:");
75+
for (Folder folder : hiddenFolders.getData()) {
76+
System.out.println(" - " + folder.getName() + " (ID: " + folder.getId() + ")");
77+
}
78+
79+
System.out.println("\n📁 Demonstrating all parameters together...");
80+
81+
// Example with all parameters including both new ones
82+
ListFoldersQueryParams comprehensiveParams = new ListFoldersQueryParams.Builder()
83+
.singleLevel(false) // Multi-level hierarchy
84+
.includeHiddenFolders(true) // Include hidden folders
85+
.limit(10)
86+
.select("id,name,parent_id,unread_count")
87+
.build();
88+
89+
ListResponse<Folder> comprehensiveFolders = nylasClient.folders().list(grantId, comprehensiveParams);
90+
System.out.println("Found " + comprehensiveFolders.getData().size() + " folders with comprehensive options:");
91+
for (Folder folder : comprehensiveFolders.getData()) {
92+
System.out.println(" - " + folder.getName());
93+
System.out.println(" ID: " + folder.getId());
94+
System.out.println(" Unread Count: " + (folder.getUnreadCount() != null ? folder.getUnreadCount() : 0));
95+
if (folder.getParentId() != null) {
96+
System.out.println(" Parent ID: " + folder.getParentId());
97+
}
98+
System.out.println();
99+
}
100+
65101
} catch (Exception exception) {
66102
System.out.println("❌ Error listing folders: " + exception.getMessage());
67103
System.out.println("Note: The single_level parameter is Microsoft-specific and may not work with other providers.");

examples/src/main/kotlin/com/nylas/examples/KotlinFoldersExample.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,42 @@ fun main() {
5959
println()
6060
}
6161

62+
println("\n📁 Listing folders including hidden ones (Microsoft only)...")
63+
64+
// List folders including hidden folders (Microsoft only)
65+
val hiddenFoldersParams = ListFoldersQueryParams.Builder()
66+
.includeHiddenFolders(true) // This is the new parameter - Microsoft only
67+
.limit(50)
68+
.build()
69+
70+
val hiddenFolders = nylasClient.folders().list(grantId, hiddenFoldersParams)
71+
println("Found ${hiddenFolders.data.size} folders including hidden ones:")
72+
hiddenFolders.data.forEach { folder ->
73+
println(" - ${folder.name} (ID: ${folder.id})")
74+
}
75+
76+
println("\n📁 Demonstrating all parameters together...")
77+
78+
// Example with all parameters including both new ones
79+
val comprehensiveParams = ListFoldersQueryParams.Builder()
80+
.singleLevel(false) // Multi-level hierarchy
81+
.includeHiddenFolders(true) // Include hidden folders
82+
.limit(10)
83+
.select("id,name,parent_id,unread_count")
84+
.build()
85+
86+
val comprehensiveFolders = nylasClient.folders().list(grantId, comprehensiveParams)
87+
println("Found ${comprehensiveFolders.data.size} folders with comprehensive options:")
88+
comprehensiveFolders.data.forEach { folder ->
89+
println(" - ${folder.name}")
90+
println(" ID: ${folder.id}")
91+
println(" Unread Count: ${folder.unreadCount ?: 0}")
92+
if (folder.parentId != null) {
93+
println(" Parent ID: ${folder.parentId}")
94+
}
95+
println()
96+
}
97+
6298
} catch (exception: Exception) {
6399
println("❌ Error listing folders: ${exception.message}")
64100
println("Note: The single_level parameter is Microsoft-specific and may not work with other providers.")

src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ data class ListFoldersQueryParams(
3737
*/
3838
@Json(name = "single_level")
3939
val singleLevel: Boolean? = null,
40+
/**
41+
* (Microsoft only) When true, Nylas includes hidden folders in its response.
42+
* Defaults to false.
43+
*/
44+
@Json(name = "include_hidden_folders")
45+
val includeHiddenFolders: Boolean? = null,
4046
) : IQueryParams {
4147
class Builder {
4248
private var limit: Int? = null
4349
private var pageToken: String? = null
4450
private var parentId: String? = null
4551
private var select: String? = null
4652
private var singleLevel: Boolean? = null
53+
private var includeHiddenFolders: Boolean? = null
4754

4855
/**
4956
* Sets the maximum number of objects to return.
@@ -83,6 +90,13 @@ data class ListFoldersQueryParams(
8390
*/
8491
fun singleLevel(singleLevel: Boolean?) = apply { this.singleLevel = singleLevel }
8592

93+
/**
94+
* Sets whether to include hidden folders in the response. (Microsoft only)
95+
* @param includeHiddenFolders If true, includes hidden folders in the response.
96+
* @return The builder.
97+
*/
98+
fun includeHiddenFolders(includeHiddenFolders: Boolean?) = apply { this.includeHiddenFolders = includeHiddenFolders }
99+
86100
/**
87101
* Builds the [ListFoldersQueryParams] object.
88102
* @return The [ListFoldersQueryParams] object.
@@ -93,6 +107,7 @@ data class ListFoldersQueryParams(
93107
parentId = parentId,
94108
select = select,
95109
singleLevel = singleLevel,
110+
includeHiddenFolders = includeHiddenFolders,
96111
)
97112
}
98113
}

src/test/kotlin/com/nylas/resources/FoldersTests.kt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,89 @@ class FoldersTests {
200200
assertEquals(null, queryParams.singleLevel)
201201
}
202202

203+
@Test
204+
fun `listing folders with include_hidden_folders parameter calls requests with the correct params`() {
205+
val queryParams =
206+
ListFoldersQueryParams(
207+
limit = 10,
208+
pageToken = "abc-123",
209+
select = "id,updated_at",
210+
includeHiddenFolders = true,
211+
)
212+
213+
folders.list(grantId, queryParams)
214+
215+
val pathCaptor = argumentCaptor<String>()
216+
val typeCaptor = argumentCaptor<Type>()
217+
val queryParamCaptor = argumentCaptor<IQueryParams>()
218+
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
219+
verify(mockNylasClient).executeGet<ListResponse<Folder>>(
220+
pathCaptor.capture(),
221+
typeCaptor.capture(),
222+
queryParamCaptor.capture(),
223+
overrideParamCaptor.capture(),
224+
)
225+
226+
assertEquals("v3/grants/$grantId/folders", pathCaptor.firstValue)
227+
assertEquals(Types.newParameterizedType(ListResponse::class.java, Folder::class.java), typeCaptor.firstValue)
228+
assertEquals(queryParams, queryParamCaptor.firstValue)
229+
}
230+
231+
@Test
232+
fun `listing folders with include_hidden_folders false calls requests with the correct params`() {
233+
val queryParams =
234+
ListFoldersQueryParams(
235+
limit = 10,
236+
includeHiddenFolders = false,
237+
)
238+
239+
folders.list(grantId, queryParams)
240+
241+
val pathCaptor = argumentCaptor<String>()
242+
val typeCaptor = argumentCaptor<Type>()
243+
val queryParamCaptor = argumentCaptor<IQueryParams>()
244+
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
245+
verify(mockNylasClient).executeGet<ListResponse<Folder>>(
246+
pathCaptor.capture(),
247+
typeCaptor.capture(),
248+
queryParamCaptor.capture(),
249+
overrideParamCaptor.capture(),
250+
)
251+
252+
assertEquals("v3/grants/$grantId/folders", pathCaptor.firstValue)
253+
assertEquals(Types.newParameterizedType(ListResponse::class.java, Folder::class.java), typeCaptor.firstValue)
254+
assertEquals(queryParams, queryParamCaptor.firstValue)
255+
}
256+
257+
@Test
258+
fun `builder includeHiddenFolders parameter works correctly`() {
259+
val queryParams = ListFoldersQueryParams.Builder()
260+
.limit(10)
261+
.includeHiddenFolders(true)
262+
.build()
263+
264+
assertEquals(true, queryParams.includeHiddenFolders)
265+
}
266+
267+
@Test
268+
fun `builder includeHiddenFolders false parameter works correctly`() {
269+
val queryParams = ListFoldersQueryParams.Builder()
270+
.limit(10)
271+
.includeHiddenFolders(false)
272+
.build()
273+
274+
assertEquals(false, queryParams.includeHiddenFolders)
275+
}
276+
277+
@Test
278+
fun `builder includeHiddenFolders null parameter works correctly`() {
279+
val queryParams = ListFoldersQueryParams.Builder()
280+
.limit(10)
281+
.build()
282+
283+
assertEquals(null, queryParams.includeHiddenFolders)
284+
}
285+
203286
@Test
204287
fun `finding a folder calls requests with the correct params`() {
205288
val folderId = "folder-123"

0 commit comments

Comments
 (0)