@@ -13,6 +13,7 @@ import {
1313 WorkspacePlanDetails ,
1414 JoinWorkspaceResult ,
1515 Workspace ,
16+ Folder ,
1617} from './types/entities'
1718import {
1819 AddCommentArgs ,
@@ -72,6 +73,10 @@ import {
7273 WorkspaceLogoResponse ,
7374 MoveProjectToWorkspaceArgs ,
7475 MoveProjectToPersonalArgs ,
76+ GetFoldersArgs ,
77+ GetFoldersResponse ,
78+ AddFolderArgs ,
79+ UpdateFolderArgs ,
7580} from './types/requests'
7681import { CustomFetch } from './types/http'
7782import { request , isSuccess } from './rest-client'
@@ -118,6 +123,7 @@ import {
118123 ENDPOINT_WORKSPACE_USERS ,
119124 getWorkspaceActiveProjectsEndpoint ,
120125 getWorkspaceArchivedProjectsEndpoint ,
126+ ENDPOINT_REST_FOLDERS ,
121127} from './consts/endpoints'
122128import {
123129 validateAttachment ,
@@ -141,6 +147,8 @@ import {
141147 validateWorkspacePlanDetails ,
142148 validateJoinWorkspaceResult ,
143149 validateWorkspaceArray ,
150+ validateFolder ,
151+ validateFolderArray ,
144152} from './utils/validators'
145153import { formatDateToYYYYMMDD } from './utils/url-helpers'
146154import { uploadMultipartFile } from './utils/multipart-upload'
@@ -1506,6 +1514,115 @@ export class TodoistApi {
15061514 return isSuccess ( response )
15071515 }
15081516
1517+ /* Folder methods */
1518+
1519+ /**
1520+ * Retrieves a paginated list of folders.
1521+ *
1522+ * @param args - Optional filter parameters such as workspace ID.
1523+ * @returns A promise that resolves to a paginated response of folders.
1524+ */
1525+ async getFolders ( args ?: GetFoldersArgs ) : Promise < GetFoldersResponse > {
1526+ const {
1527+ data : { results, nextCursor } ,
1528+ } = await request < GetFoldersResponse > ( {
1529+ httpMethod : 'GET' ,
1530+ baseUri : this . syncApiBase ,
1531+ relativePath : ENDPOINT_REST_FOLDERS ,
1532+ apiToken : this . authToken ,
1533+ customFetch : this . customFetch ,
1534+ payload : args ,
1535+ } )
1536+
1537+ return {
1538+ results : validateFolderArray ( results ) ,
1539+ nextCursor,
1540+ }
1541+ }
1542+
1543+ /**
1544+ * Retrieves a single folder by its ID.
1545+ *
1546+ * @param id - The unique identifier of the folder.
1547+ * @returns A promise that resolves to the requested folder.
1548+ */
1549+ async getFolder ( id : string ) : Promise < Folder > {
1550+ z . string ( ) . parse ( id )
1551+ const response = await request < Folder > ( {
1552+ httpMethod : 'GET' ,
1553+ baseUri : this . syncApiBase ,
1554+ relativePath : generatePath ( ENDPOINT_REST_FOLDERS , id ) ,
1555+ apiToken : this . authToken ,
1556+ customFetch : this . customFetch ,
1557+ } )
1558+
1559+ return validateFolder ( response . data )
1560+ }
1561+
1562+ /**
1563+ * Creates a new folder.
1564+ *
1565+ * @param args - Folder creation parameters including name and workspace ID.
1566+ * @param requestId - Optional custom identifier for the request.
1567+ * @returns A promise that resolves to the created folder.
1568+ */
1569+ async addFolder ( args : AddFolderArgs , requestId ?: string ) : Promise < Folder > {
1570+ const response = await request < Folder > ( {
1571+ httpMethod : 'POST' ,
1572+ baseUri : this . syncApiBase ,
1573+ relativePath : ENDPOINT_REST_FOLDERS ,
1574+ apiToken : this . authToken ,
1575+ customFetch : this . customFetch ,
1576+ payload : args ,
1577+ requestId : requestId ,
1578+ } )
1579+
1580+ return validateFolder ( response . data )
1581+ }
1582+
1583+ /**
1584+ * Updates an existing folder by its ID.
1585+ *
1586+ * @param id - The unique identifier of the folder to update.
1587+ * @param args - Update parameters such as name or default order.
1588+ * @param requestId - Optional custom identifier for the request.
1589+ * @returns A promise that resolves to the updated folder.
1590+ */
1591+ async updateFolder ( id : string , args : UpdateFolderArgs , requestId ?: string ) : Promise < Folder > {
1592+ z . string ( ) . parse ( id )
1593+ const response = await request < Folder > ( {
1594+ httpMethod : 'POST' ,
1595+ baseUri : this . syncApiBase ,
1596+ relativePath : generatePath ( ENDPOINT_REST_FOLDERS , id ) ,
1597+ apiToken : this . authToken ,
1598+ customFetch : this . customFetch ,
1599+ payload : args ,
1600+ requestId : requestId ,
1601+ } )
1602+
1603+ return validateFolder ( response . data )
1604+ }
1605+
1606+ /**
1607+ * Deletes a folder by its ID.
1608+ *
1609+ * @param id - The unique identifier of the folder to delete.
1610+ * @param requestId - Optional custom identifier for the request.
1611+ * @returns A promise that resolves to `true` if successful.
1612+ */
1613+ async deleteFolder ( id : string , requestId ?: string ) : Promise < boolean > {
1614+ z . string ( ) . parse ( id )
1615+ const response = await request ( {
1616+ httpMethod : 'DELETE' ,
1617+ baseUri : this . syncApiBase ,
1618+ relativePath : generatePath ( ENDPOINT_REST_FOLDERS , id ) ,
1619+ apiToken : this . authToken ,
1620+ customFetch : this . customFetch ,
1621+ requestId : requestId ,
1622+ } )
1623+ return isSuccess ( response )
1624+ }
1625+
15091626 /* Workspace methods */
15101627
15111628 /**
0 commit comments