Workdrive API: Issues with Convert to Zoho Format
Hi all,
Looking for some guidance, I am trying to use https://workdrive.zoho.com/apidocs/v1/filesfolders/importtonative to take an xlsx or xls file and convert it to zSheet, to then call the zSheet contents in a later Flow Function. Before I even get there, if anyone knows a better way to just write inline the full contents of the Excel file stored in Workdrive using Deluge , we can just stop here… Just trying to parse the contents against a key and return true/false based on the contents.
That being said, I can’t seem to find one (outside of Office Integrator, which I will probably move onto shortly). I keep getting { id: 'R010' , title: 'Invalid resource type to import' } when trying to convert either of the attachments.
Here is the code sample I am working with. Totally open to feedback/ideas/suggestions. More broadly, I just want to better understand the "https://www.zohoapis.com/workdrive/api/v1/files/{resource_id}/importfile" endpoint, so I know what files can be converted to zSheet and which cannot.
map Workdrive_ConvertExcelToZSheetmap(string resource_Id, string destinationFolderId)
{
//resource_Id = "oi8kx199dce0e461245d8a1a9bc8e7cb3981f";
//destinationFolderId = "4vznv947aa55bdaf64f0da1983fa8e37c1d38";
responseMap = Map();
responseMap.put("Status","error");
responseMap.put("SheetResourceId","");
responseMap.put("ErrorMessage","");
try
{
// First, download the file to get its name for the converted copy
dlHeaders = Map();
dlHeaders.put("Accept","application/vnd.api+json");
excelFile = invokeurl
[
url :"https://workdrive.zoho.com/api/v1/download/" + resource_Id
type :GET
headers:dlHeaders
connection:"workdrivetoflow"
];
if(excelFile.isFile() == false)
{
responseMap.put("ErrorMessage","Failed to download file. resource_Id may be invalid: " + resource_Id);
return responseMap;
}
originalFileName = excelFile.getFileName();
info "fn_ConvertExcelToZSheet - File: " + originalFileName;
// Build name for the converted Zoho Sheet file
if(originalFileName.contains("."))
{
excelBaseName = originalFileName.left(originalFileName.lastIndexOf("."));
}
else
{
excelBaseName = originalFileName;
}
convertedName = excelBaseName + "_temp_zsheet";
// Call WorkDrive importfile API
// POST /api/v1/files/{destination_folder_id}/importfile
importHeader = Map();
importHeader.put("Accept","application/vnd.api+json");
importHeader.put("Content-Type","application/vnd.api+json");
attParams = Map();
attParams.put("resource_id",resource_Id);
attParams.put("name",convertedName);
dataParams = Map();
dataParams.put("attributes",attParams);
dataParams.put("type","files");
importBody = Map();
importBody.put("data",dataParams);
importResponse = invokeurl
[
url :"https://workdrive.zoho.com/api/v1/files/" + destinationFolderId + "/importfile"
type :POST
parameters:importBody.toString()
headers:importHeader
connection:"workdrivetoflow"
];
info "fn_ConvertExcelToZSheet - importfile response: " + importResponse;
// Extract the new Zoho Sheet resource_id from the response
// Response structure: {"data": {"id": "xxx", "type": "files", "attributes": {...}}}
sheetResourceId = "";
if(importResponse.containKey("data"))
{
importData = importResponse.get("data");
if(importData.containKey("id"))
{
sheetResourceId = importData.get("id");
}
if((sheetResourceId null || sheetResourceId.trim() "") && importData.containKey("attributes"))
{
importAttrs = importData.get("attributes");
if(importAttrs.containKey("resource_id"))
{
sheetResourceId = importAttrs.get("resource_id");
}
}
}
if(sheetResourceId null || sheetResourceId.trim() "")
{
responseMap.put("ErrorMessage","importfile conversion failed. Response: " + importResponse.toString());
return responseMap;
}
responseMap.put("SheetResourceId",sheetResourceId);
responseMap.put("Status","success");
info "fn_ConvertExcelToZSheet - New Zoho Sheet ID: " + sheetResourceId;
}
catch (e)
{
responseMap.put("ErrorMessage","Unhandled exception: " + e.toString());
}
return responseMap;
}
aac067 test 2.xlsaac067 test.xlsx