For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at https://ascentbusiness.co.uk/zoho-services/uk-zoho-support.  For larger projects, talk to our experts and receive dedicated support from our hands-on project consultants at https://ascentbusiness.co.uk/zoho-services/zoho-crm-implementation.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at https://ascentbusiness.co.uk.

Zoho Workdrive: Getting Team Folder ID

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
copyraw
https://workdrive.zoho.com/home/{dunno_id}/privatespace/folders/{folder_id}
  1.  https://workdrive.zoho.com/home/{dunno_id}/privatespace/folders/{folder_id} 

Getting the teamfolder ID:
Access the folder in workdrive and check the URL:
copyraw
https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{team_folder_id}/folders/files
  1.  https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{team_folder_id}/folders/files 
or
copyraw
https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{team_folder_id}/folders/{team_subfolder_id}
  1.  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:
copyraw
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;
  1.  m_Header = Map()
  2.  m_Header.put("Accept","application/vnd.api+json")
  3.  v_Endpoint = "https://www.zohoapis.com/workdrive/api/v1/teamfolders/{team_folder_id}/folders"
  4.  r_TeamFolderInfo = invokeUrl 
  5.  [ 
  6.      url :v_Endpoint 
  7.      type :GET 
  8.      headers:m_Header 
  9.      connection:"my_workdrive_connection" 
  10.  ]
  11.  info r_TeamFolderInfo; 

The one to rule them all
copyraw
// ======================
// 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_RecipientsEmails = {"This email address is being protected from spambots. You need JavaScript enabled to view it.","This email address is being protected from spambots. You need JavaScript enabled to view it."};
		//
		m_Header = Map();
		m_Header.put("Accept","application/vnd.api+json");
		m_Params = Map();
		m_Params.put("resource_id",v_WorkdriveFolderID);
		m_Params.put("shared_type","workspace");
		m_Params.put("email_id",l_RecipientsEmails);
		// role id 34 is view only on the file (see below for further permissions)
		m_Params.put("role_id",6);
		r_WorkdriveMembers = invokeurl
		[
			url :"https://www.zohoapis.com/workdrive/api/v1/members"
			type :POST
			parameters:m_Params.toString()
			headers:m_Header
			connection:"my_workdrive_connection"
		];
		info "Workdrive Members Added: " + r_WorkdriveMembers;
	}
	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 = {"This email address is being protected from spambots. You need JavaScript enabled to view it.","This email address is being protected from spambots. You need JavaScript enabled to view it."};
//
// send email
sendmail
[
	from :zoho.adminuserid
	to :l_RecipientsEmails
	subject :v_Subject
	message :v_Message
]
  1.  // ====================== 
  2.  // get folder information 
  3.  // https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{team_folder_id}/folders/files 
  4.  m_Header = Map()
  5.  m_Header.put("Accept","application/vnd.api+json")
  6.  v_Endpoint = "https://www.zohoapis.com/workdrive/api/v1/teamfolders/{team_folder_id}/folders"
  7.  r_TeamFolderInfo = invokeUrl 
  8.  [ 
  9.      url :v_Endpoint 
  10.      type :GET 
  11.      headers:m_Header 
  12.      connection:"my_workdrive_connection" 
  13.  ]
  14.  //info r_TeamFolderInfo; 
  15.  // 
  16.  // ====================== 
  17.  // get list of subfolders by name (creates a timestamped duplicate if exists so need to check if it exists first) 
  18.  // https://workdrive.zoho.com/home/{dunno_id}/teams/{dunno_id}/ws/{parent_id}/folders/files 
  19.  m_SubfolderNames = Map()
  20.  r_Subfolders = invokeUrl 
  21.  [ 
  22.      url :"https://www.zohoapis.com/workdrive/api/v1/teamfolders/{parent_id}/folders?page%5Blimit%5D=50&page%5Boffset%5D=0" 
  23.      type :GET 
  24.      headers:m_Header 
  25.      connection:"my_workdrive_connection" 
  26.  ]
  27.  if(!isNull(r_Subfolders.get("data"))) 
  28.  { 
  29.      for each  m_Subfolder in r_Subfolders.get("data") 
  30.      { 
  31.          if(!isNull(m_Subfolder.get("attributes"))) 
  32.          { 
  33.              m_SubfolderNames.put(m_Subfolder.get("attributes").get("name"), m_Subfolder.get("id"))
  34.          } 
  35.      } 
  36.  } 
  37.  // info r_Subfolders; 
  38.  // info m_SubfolderNames; 
  39.  // 
  40.  // ====================== 
  41.  // create sub folder 
  42.  v_ParentFolderID = "{parent_id}"
  43.  v_WorkdriveFolderID = ""
  44.  v_WorkingFolderName = zoho.currentdate.toString("yyyy")
  45.  if(!m_SubfolderNames.keys().contains(v_WorkingFolderName)) 
  46.  { 
  47.      m_Attr = Map()
  48.      m_Attr.put("name", v_WorkingFolderName)
  49.      m_Attr.put("parent_id", v_ParentFolderID)
  50.      // 
  51.      m_Params = Map()
  52.      m_Params.put("attributes", m_Attr)
  53.      m_Params.put("type", "files")
  54.      // 
  55.      m_Data = Map()
  56.      m_Data.put("data", m_Params)
  57.      r_WorkdriveFolder = invokeUrl 
  58.      [ 
  59.          url :"https://www.zohoapis.com/workdrive/api/v1/files" 
  60.          type :POST 
  61.          parameters:m_Data.toString() 
  62.          headers:m_Header 
  63.          connection:"my_workdrive_connection" 
  64.      ]
  65.      if(!isNull(r_WorkdriveFolder.get("id"))) 
  66.      { 
  67.          v_WorkdriveFolderID = r_WorkdriveFolder.get("id")
  68.          // 
  69.          // ====================== 
  70.          // share folder to members woh can access it (read-only) 
  71.          // 
  72.          // list of recipients 
  73.          l_RecipientsEmails = {"This email address is being protected from spambots. You need JavaScript enabled to view it.","This email address is being protected from spambots. You need JavaScript enabled to view it."}
  74.          // 
  75.          m_Header = Map()
  76.          m_Header.put("Accept","application/vnd.api+json")
  77.          m_Params = Map()
  78.          m_Params.put("resource_id",v_WorkdriveFolderID)
  79.          m_Params.put("shared_type","workspace")
  80.          m_Params.put("email_id",l_RecipientsEmails)
  81.          // role id 34 is view only on the file (see below for further permissions) 
  82.          m_Params.put("role_id",6)
  83.          r_WorkdriveMembers = invokeUrl 
  84.          [ 
  85.              url :"https://www.zohoapis.com/workdrive/api/v1/members" 
  86.              type :POST 
  87.              parameters:m_Params.toString() 
  88.              headers:m_Header 
  89.              connection:"my_workdrive_connection" 
  90.          ]
  91.          info "Workdrive Members Added: " + r_WorkdriveMembers; 
  92.      } 
  93.      info r_WorkdriveFolder; 
  94.  } 
  95.  else 
  96.  { 
  97.      v_WorkdriveFolderID = m_SubfolderNames.get(v_WorkingFolderName)
  98.  } 
  99.  // ====================== 
  100.  // upload the file to this folder 
  101.  if(v_WorkdriveFolderID != "") 
  102.  { 
  103.      v_PermaLink = ""
  104.      // 
  105.      // generate a test CSV 
  106.      v_NewLineChar = hextoText("0A")
  107.      l_Csv_File = {"Header1,Header2","Row1_Data1,Row1_Data2","Row2_Data1,Row2_Data2"}
  108.      v_UploadFilename = " Test Upload " + zoho.currenttime.toString("yyyy-MM-dd-HH-mm") + ".csv"
  109.      f_UploadCsvFile = l_Csv_File.toString(v_NewLineChar).toFile(v_UploadFilename)
  110.      // 
  111.      // upload the file 
  112.      r_UploadResponse = zoho.workdrive.uploadFile(f_UploadCsvFile,v_WorkdriveFolderID,v_UploadFilename,FALSE,"my_workdrive_connection")
  113.      if(!isNull(r_UploadResponse.get("data"))) 
  114.      { 
  115.          // looping but only have 1 upload so getting permalink for this upload 
  116.          for each m_ThisData in r_UploadResponse.get("data") 
  117.          { 
  118.              if(!isNull(m_ThisData.get("attributes"))) 
  119.              { 
  120.                  if(!isNull(m_ThisData.get("attributes").get("Permalink"))) 
  121.                  { 
  122.                      v_PermaLink = m_ThisData.get("attributes").get("Permalink")
  123.                  } 
  124.              } 
  125.          } 
  126.      } 
  127.  } 
  128.  // ==================================== 
  129.  // send an email with the permalink 
  130.  v_Subject = "Data for Export w/c: " + zoho.currentdate.toStartOfWeek().toString("yyyy-MM-dd")
  131.  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.  "
  132.  // 
  133.  if(!isBlank(v_PermaLink)) 
  134.  { 
  135.      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/>"
  136.  } 
  137.  // 
  138.  v_Message = v_Message + "This file is ready for importing into the system.<br /><br />Kind Regards,<br /><br />The Development Team."
  139.  // 
  140.  // list of recipients 
  141.  l_RecipientsEmails = {"This email address is being protected from spambots. You need JavaScript enabled to view it.","This email address is being protected from spambots. You need JavaScript enabled to view it."}
  142.  // 
  143.  // send email 
  144.  sendmail 
  145.  [ 
  146.      from :zoho.adminuserid 
  147.      to :l_RecipientsEmails 
  148.      subject :v_Subject 
  149.      message :v_Message 
  150.  ] 


Additional Note(s):
copyraw
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
  1.  Allowed role IDs for files: 
  2.  34 - View 
  3.  5 - Edit 
  4.  4 - Share 
  5.  6 - View and comment 
  6.  33 - View and fill 
  7.   
  8.  Allowed role IDs for folders: 
  9.  6 - View 
  10.  5 - Edit 
  11.  3 - Organize 
  12.  7 - Upload 


Source(s):

Category: Zoho :: Article: 883

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.