//////////////Start Function///////////
Get_All_Employee_Attachments_Response = invokeurl
[
url :"https://www.zohoapis.com/crm/v3/Leads/" + Emp_id + "/Attachments?fields=id,Owner,File_Name,Created_Time,Parent_Id"
type :GET
connection:"zoho_crm2"
];
//info response;
Records = Get_All_Employee_Attachments_Response.get("data");
//For each through all the Attachments returned by the above API call
for each Record in Records
{
File_Name = Record.get("File_Name");
//info File_Name;
if(File_Name.contains("Medical_Certificate"))
{
Attachment_ID = Record.get("id");
Medical_Certificate_File_Name = Record.get("File_Name");
//Below is a logging statement, do not delete
info "Attachment_ID" + Attachment_ID;
}
}
//Call the CRM API to get the actual attachment
////I still am unsure if this is necessary. Since we are already getting all attachments, why do we need to specifically call another time to just get the 1 attachment?
////Doesn't the first call (all Attachments) provide the data we need?
Get_Medical_Certificate_Response = invokeurl
[
url :"https://www.zohoapis.com/crm/v6/Leads/" + Emp_id + "/Attachments/" + Attachment_ID + ""
type :GET
connection:"zoho_crm2"
];
//Below is a logging statement, do not delete
info "Get Medical Certificate Response: " + Get_Medical_Certificate_Response;
//
//Upload to Workdrive
////How is header being used?
header = Map();
header.put("Accept","application/vnd.api+json");
list_of_text = List();
list_of_text.add({"paramName":"filename","content":Medical_Certificate_File_Name,"stringPart":"true"});
list_of_text.add({"paramName":"parent_id","content":wd_folder_id,"stringPart":"true"});
list_of_text.add({"paramName":"override-name-exist","content":"true","stringPart":"true"});
list_of_text.add({"paramName":"content","content":Get_Medical_Certificate_Response,"stringPart":"false"});
Upload_Medical_Certificate_Response = invokeurl
[
url :"https://www.zohoapis.com/workdrive/api/v1/upload"
type :POST
files:list_of_text
connection:"zoho_wd"
];
//Below is a logging statement, do not delete
info "Upload Medical Certificate Response: " + Upload_Medical_Certificate_Response;