Choose where you’d like to start

Get folders from Zoho Mail

Note: This task is applicable to all Zoho services, except Zoho Creator.

Overview

The zoho.mail.getFolders task fetches the list of all the folders from Zoho Mail. This task is based on a Zoho Mail API.

Syntax

<response>=zoho.mail.getFolders(<connection>);

where:

Params Data typeDescription

<response> 

KEY-VALUE

The details including the type, name, ID, and ID of the parent folder of all the folders that will be fetched from Zoho Mail.

<connection> 

 

TEXT

is the link name of the Zoho Mail connection

Note:

  • In view of stopping new authtoken generation, a Zoho OAuth connection with appropriate scopes is mandatory for new integration tasks (created after the deadline specified in the post) to work as expected. Existing integration tasks will continue to work with or without the connections parameter unless the authtoken is manually deleted from accounts.
  • The scope required for this task as mentioned by Zoho Mail API is: folders 
  • Refer to this post for the list of Zoho services that support the connections page.
  • Learn more about connections

Example

The following script retrieves all the folders from Zoho Mail:

response = zoho.mail.getFolders("mail_oauth_connection");

where:

response
The KEY-VALUE response that represents the details of all the folders fetched from Zoho Mail.
"mail_oauth_connection"
The TEXT that represents the link name of the Zoho Mail connection.

Response Format

Success Response

The success response returned will be in the the following format:

   {
   "ID":"6012326000000008019",
   "TYPE":"Inbox",
   "NAME":"Inbox"
   "CHILDREN": [
   {
   "ID": "094480000000011003",
   "TYPE": "Inbox",
   "NAME": "folder1"
   }
   ]
   },
   {
   "PID":"6729326000000008013",
   "ID":"6729326000000008015",
   "TYPE":"Drafts",
   "NAME":"Drafts"
   },
   {
   "PID":"6729326000000008015",
   "ID":"6729326000000008017",
   "TYPE":"Templates",
   "NAME":"Templates"
   },
   {
   "PID":"6729326000000008017",
   "ID":"6729326000000008019",
   "TYPE":"Sent",
   "NAME":"Sent"
   },
   {
   "PID":"6729326000000008019",
   "ID":"6729326000000008021",
   "TYPE":"Spam",
   "NAME":"Spam"
   },
   {
   "PID":"6729326000000008023",
   "ID":"6729326000000008025",
   "TYPE":"Outbox",
   "NAME":"Outbox"
   },
   {
   "PID":"6729326000000548069",
   "ID":"6729326000000548027",
   "TYPE":"Inbox",
   "NAME":"ZMGroup"
   },
   {
   "PID":"6729326000000548027",
   "ID":"6729326000000548015",
   "TYPE":"Inbox",
   "NAME":"ZMNewsLetter"
   },
   {
   "PID":"6729326000000548015",
   "ID":"6729326000000548003",
   "TYPE":"Inbox",
   "NAME":"ZMNotification"
   }
   

To fetch the IDs of the folders from the success response obtained, execute the following snippet:

 for each var in <response_variable>
 {
 info var.get("ID");
 }
   

To fetch the IDs of all the subfolders from the success response obtained, execute the following snippet:

 for each folder in <response_variable>
 {

 //Fetch the list of subfolders of the folder in the current iteration
 subfolders_list = folder.get("CHILDREN");
 
 // Check if the subfolders list is not empty
 if(subfolders_list!= null)
​ {
 
 //Iterate through the list of subfolders and fetch their IDs
 for each child_folder in subfolders_list
 {
 info child_folder.get("ID") ;
 }
 
 }
 }
   

To fetch the subfolders IDs of the specified folder from the success response obtained, execute the following snippet:

 for each folder in <response_variable>
 {
 //Fetch the ID of the current folder in the iteration
 folder_id = folder.get("ID") ;
  
 //Check if the current ID is the required ID
 if(folder_id == <required_folder_id>)
 {
 
 //Fetch the list of subfolders of the current folder in the iteration
 subfolders_list = folder.get("CHILDREN");

 //Iterate through the list of subfolders and fetch their IDs
 for each child_folder in subfolders_list
 {
 info child_folder.get("ID") ;
 }
 }
 }

Related Links

Get Started Now

Execute