Zoho Analytics API: Dashboard Export Question
Hi there,
We are working on a bit of code to potentially save PDF copies of analytics dashboards on a schedule. These specific dashboards have entries that are user defined each week, and to make a historical record presently, we need to manually download the dashboards and store them in Workdrive. We’d like to use Flowto automatically do this instead.
I kind of have the code working in a very loose fashion, but we keep coming up with errors and issues with our rest api call creating the pdf consistently. I am wondering if anyone has familiarity with using the analytics API to export dashboards, and therefore any common challenges/limitations of the data that can be included? I have already gathered that some images and embedded objects may not render correctly, but our primary issue is the JobExport is returning a success code, but then the actual file download is a corrupted pdf…
This only seems to occur with certain dashboards, but not others. When we point the code at set tables or queries, it has no trouble and saves a pdf file correctly. Additionally, we have verified that a manual export of the dashboards in question will create and export a PDF without issue, furhter pointing the issue back to our code/api call and not necessarily a glitch in the dashboard config itself.
Thoughts/feedback/suggestions are greatly appreciated.
string testingpdfv2()
{
tabName = "HR/Distribution";
// friendly name
rootFldId = "WorkspaceFolderId";
orgId = "ORGID";
workspaceId = "WSID";
viewId = "VID";
// ---- 1) kick off export job ----
headers = Map();
headers.put("ZANALYTICS-ORGID",orgId);
config = Map();
config.put("responseFormat","pdf");
config.put("dashboardLayout",0);
params = Map();
params.put("CONFIG",config);
if(false) //***** these are presently manually changed to test the code in one function, would eventually be split into separate custom function steps in flow due to timing and delay requirement
{
resp = invokeurl
[
url :"https://analyticsapi.zoho.com/restapi/v2/bulk/workspaces/" + workspaceId + "/views/" + viewId + "/data"
type :GET
parameters:params
headers:headers
connection:"zanalytics"
];
info resp;
jobId = resp.get("data").get("jobId");
}
jobId = "2769441000013664090"; //****presently manually set during testing, but would normally be returned and assigned to a Flow variable and passed as an argument
jobstatus = invokeurl
[
url :"https://analyticsapi.zoho.com/restapi/v2/bulk/workspaces/" + workspaceId + "/exportjobs/" + jobId
type :GET
headers:headers
connection:"zanalytics"
];
info jobstatus;
if(true) //***** these are presently manually changed to test the code in one function, would eventually be split into separate custom function steps in flow due to timing and delay requirement
{
fileResp = invokeurl
[
url :"https://analyticsapi.zoho.com/restapi/v2/bulk/workspaces/" + workspaceId + "/exportjobs/" + jobId + "/data"
type :GET
headers:headers
response : FILE
connection:"zanalytics"
];
info fileResp;
// ---- 4) upload to WorkDrive ----
uploadInfo = zoho.workdrive.uploadFile(fileResp,rootFldId,"Dashboard_" + zoho.currentdate.toString("yyyyMMdd") + ".pdf","true","flowtozdrive");
info uploadInfo;
}
return jobId;
}