What?
This is an article to document how to get your team folder ID, retrieve information about it, and upload to it via the API.

Why?
The documentation is there but making sense of it, is somewhat difficult, at least for me.

How?
So when I was trying this, I would get either "URL rule not configured" or an unhelpful blank response.

Getting the folder ID
This applies to if you click on "My Folders" and then checking the URL
https://workdrive.zoho.com/home/{dunno_id}/privatespace/folders/{folder_id}

Getting the teamfolder ID:
Access the folder in workdrive and check the URL:
https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{team_folder_id}/folders/files
or
https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{team_folder_id}/folders/{team_subfolder_id}

Getting the team folder information
Use the team_folder_ID or if it is a subfolder, then use the team_subfolder_id Ensure the scope for your connection includes WorkDrive.teamfolders.READ and note that header has to be added otherwise you get a blank response:
m_Header = Map();
m_Header.put("Accept","application/vnd.api+json");
v_Endpoint = "https://www.zohoapis.com/workdrive/api/v1/teamfolders/{team_folder_id}/folders";
r_TeamFolderInfo = invokeurl
[
	url :v_Endpoint
	type :GET
	headers:m_Header
	connection:"my_workdrive_connection"
];
info r_TeamFolderInfo;

The one to rule them all
// ======================
// get folder information
// https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{team_folder_id}/folders/files
m_Header = Map();
m_Header.put("Accept","application/vnd.api+json");
v_Endpoint = "https://www.zohoapis.com/workdrive/api/v1/teamfolders/{team_folder_id}/folders";
r_TeamFolderInfo = invokeurl
[
	url :v_Endpoint
	type :GET
	headers:m_Header
	connection:"my_workdrive_connection"
];
//info r_TeamFolderInfo;
//
// ======================
// get list of subfolders by name (creates a timestamped duplicate if exists so need to check if it exists first)
// https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{parent_id}/folders/files
m_SubfolderNames = Map();
r_Subfolders = invokeurl
[
	url :"https://www.zohoapis.com/workdrive/api/v1/teamfolders/{parent_id}/folders?page%5Blimit%5D=50&page%5Boffset%5D=0"
	type :GET
	headers:m_Header
	connection:"my_workdrive_connection"
];
if(!isNull(r_Subfolders.get("data")))
{
	for each  m_Subfolder in r_Subfolders.get("data")
	{
		if(!isNull(m_Subfolder.get("attributes")))
		{
			m_SubfolderNames.put(m_Subfolder.get("attributes").get("name"), m_Subfolder.get("id"));
		}
	}
}
// info r_Subfolders;
// info m_SubfolderNames;
//
// ======================
// create sub folder
v_ParentFolderID = "{parent_id}";
v_WorkdriveFolderID = "";
v_WorkingFolderName = zoho.currentdate.toString("yyyy");
if(!m_SubfolderNames.keys().contains(v_WorkingFolderName))
{
	m_Attr = Map();
	m_Attr.put("name", v_WorkingFolderName);
	m_Attr.put("parent_id", v_ParentFolderID);
	//
	m_Params = Map();
	m_Params.put("attributes", m_Attr);
	m_Params.put("type", "files");
	//
	m_Data = Map();
	m_Data.put("data", m_Params);
	r_WorkdriveFolder = invokeurl
	[
		url :"https://www.zohoapis.com/workdrive/api/v1/files"
		type :POST
		parameters:m_Data.toString()
		headers:m_Header
		connection:"my_workdrive_connection"
	];
	if(!isNull(r_WorkdriveFolder.get("id")))
	{
		v_WorkdriveFolderID = r_WorkdriveFolder.get("id");
		//
		// ======================
		// share folder to members woh can access it (read-only)
		//
		// list of recipients
		l_WorkdriveRecipients = {"me@mycompany.com","payroll@mycompany.com"};
		//
	        for each v_RecipientEmail in l_WorkdriveRecipients
                {
			m_Header = Map();
			m_Header.put("Accept","application/vnd.api+json");
			m_Attributes = Map();
			m_Attributes.put("resource_id",v_WorkdriveFolderID);
			m_Attributes.put("shared_type","workspace");
			m_Attributes.put("email_id",v_RecipientEmail);
		// role id 34 is view only on the file (see below for further permissions)
			m_Attributes.put("role_id",34);
			m_Data = Map();
			m_Data.put("attributes", m_Attributes);
			m_Data.put("type", "members");
			m_Params = Map();
			m_Params.put("data",m_Data);
			//
			r_WorkdriveMembers = invokeurl
			[
				url :"https://www.zohoapis.eu/workdrive/api/v1/members"
				type :POST
				parameters:m_Params.toString()
				headers:m_Header
				connection:"my_workdrive_connection"
			];
			info "Workdrive Member Added: " + v_RecipientEmail;		
                }
	}
	info r_WorkdriveFolder;
}
else 
{
	v_WorkdriveFolderID = m_SubfolderNames.get(v_WorkingFolderName);
}
// ======================
// upload the file to this folder
if(v_WorkdriveFolderID != "")
{
	v_PermaLink = "";
	//
	// generate a test CSV
	v_NewLineChar = hextoText("0A");
	l_Csv_File = {"Header1,Header2","Row1_Data1,Row1_Data2","Row2_Data1,Row2_Data2"};
	v_UploadFilename = " Test Upload " + zoho.currenttime.toString("yyyy-MM-dd-HH-mm") + ".csv";
	f_UploadCsvFile = l_Csv_File.toString(v_NewLineChar).toFile(v_UploadFilename);
	//
	// upload the file
	r_UploadResponse = zoho.workdrive.uploadFile(f_UploadCsvFile,v_WorkdriveFolderID,v_UploadFilename,FALSE,"my_workdrive_connection");
	if(!isNull(r_UploadResponse.get("data")))
	{
		// looping but only have 1 upload so getting permalink for this upload
		for each m_ThisData in r_UploadResponse.get("data")
		{
			if(!isNull(m_ThisData.get("attributes")))
			{
				if(!isNull(m_ThisData.get("attributes").get("Permalink")))
				{
					v_PermaLink = m_ThisData.get("attributes").get("Permalink");
				}
			}
		}
	}		
}
// ====================================
// send an email with the permalink
v_Subject = "Data for Export w/c: " + zoho.currentdate.toStartOfWeek().toString("yyyy-MM-dd");
v_Message = "To he who shall not be named,<br /><br /><b>Re: " + v_Subject + "</b><br /><br />Please find attached the CSV export file containing the Data.  ";
// 
if(!isBlank(v_PermaLink))
{
	v_Message = v_Message + "<br/>The export file has been uploaded to the workdrive.  The direct link to the file is <a href=\"" + v_PermaLink + "\">" + v_UploadFilename + "</a>. <br/>";
}
// 
v_Message = v_Message + "This file is ready for importing into the system.<br /><br />Kind Regards,<br /><br />The Development Team.";
//
// list of recipients
l_RecipientsEmails = {"me@mycompany.com","payroll@mycompany.com"};
//
// send email
sendmail
[
	from :zoho.adminuserid
	to :l_RecipientsEmails
	subject :v_Subject
	message :v_Message
]



Additional Note(s):
Allowed role IDs for files:
34 - View
5 - Edit
4 - Share
6 - View and comment
33 - View and fill

Allowed role IDs for folders:
6 - View
5 - Edit
3 - Organize
7 - Upload


Error(s) Encountered:
When updating members to a workdrive, I was getting errors such as
  • 2945 Invalid JSON
  • 2945 Invalid JSON
	for each v_RecipientEmail in l_WorkdriveRecipients
        {
			m_Header = Map();
			m_Header.put("Accept","application/vnd.api+json");
			m_Attributes = Map();
			m_Attributes.put("resource_id",v_WorkdriveFolderID);
			m_Attributes.put("shared_type","workspace");
			m_Attributes.put("email_id",v_RecipientEmail);
			m_Attributes.put("role_id",34);
			m_Data = Map();
			m_Data.put("attributes", m_Attributes);
			m_Data.put("type", "members");
			m_Params = Map();
			m_Params.put("data",m_Data);
			//
			r_WorkdriveMembers = invokeurl
			[
				url :"https://www.zohoapis.eu/workdrive/api/v1/members"
				type :POST
				parameters:m_Params.toString()
				headers:m_Header
				connection:"ab_workdrive"
			];
			info "Workdrive Member Added: " + v_RecipientEmail;		
        }


Source(s):