-
-
Save jeznag/ae53d4f0f08557319431b2028cd58f43 to your computer and use it in GitHub Desktop.
creating folders in zoho workdrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sms_record = zoho.crm.getRecordById("twiliosmsextension0__Sent_SMS",sms_message_id); | |
mms_content = sms_record.get("twiliosmsextension0__MMS_content"); | |
/* | |
<img src='https://api.twilio.com/2010-04-01/Accounts/ACa93e777ade0d1cf3f8d9b1ca19445597/Messages/MMc3cd1a805a768bcd5f29d80b857c073d/Media/MEb7be2748c215eb9b6b58a486c7f521c1' /> | |
*/ | |
webhook_contents = sms_record.get("twiliosmsextension0__Twilio_Webhook_Contents").toMap(); | |
webhook_data = webhook_contents.get("webhook_data"); | |
properties = webhook_data.toList("&"); | |
for each property in properties | |
{ | |
if(property.startsWith("MediaContentType0")) | |
{ | |
parts = property.toList("="); | |
type = parts.get(1); | |
type_parts = type.toList("%2F"); | |
file_extension = "." + type_parts.get(1); | |
} | |
} | |
info webhook_data; | |
mms_url = mms_content.replaceAll("<img src='","").replaceAll("' />",""); | |
filename = mms_url.replaceAll(".*/Media/","") + file_extension; | |
keys = sms_record.keys(); | |
for each key in keys | |
{ | |
if(key.contains("Name")) | |
{ | |
value = sms_record.get(key); | |
if(value != null && value.toString().contains("{")) | |
{ | |
module_name = key.replaceAll("Name","") + "s"; | |
record_id = value.get("id"); | |
} | |
} | |
} | |
if(module_name != null) | |
{ | |
info "module_name" + module_name; | |
record = zoho.crm.getRecordById(module_name,record_id); | |
workdrive_folder_id = record.get("zohoworkdriveforcrm__Workdrive_Folder_ID"); | |
if(workdrive_folder_id == null) | |
{ | |
mp = map(); | |
mp.put("Accept","application/vnd.api+json"); | |
response = invokeUrl | |
[ | |
url: "https://workdrive.zoho.com/api/v1/users/me" | |
type: GET | |
connection: "workdrive" | |
headers : mp | |
]; | |
zuid = response.get("data").get("id"); | |
info "zuid" + zuid; | |
mp = Map(); | |
mp.put("Accept","application/vnd.api+json"); | |
//Code to get TeamId | |
teamlist = invokeurl | |
[ | |
url :"https://workdrive.zoho.com/api/v1/users/" + zuid + "/teams" | |
type :get | |
headers:mp | |
connection:"workdrive" | |
]; | |
info "teamlist" + teamlist; | |
teamid = teamlist.get("data").getJSON("id"); | |
// Code to get CurrentUserInfo | |
response = invokeurl | |
[ | |
url :"https://workdrive.zoho.com//api/v1/teams/" + teamid + "/currentuser" | |
type :GET | |
headers:mp | |
connection:"workdrive" | |
]; | |
currentuserid = response.get("data").get("id"); | |
info "currentuserid" + currentuserid; | |
//code to get MyFolderId | |
response = invokeurl | |
[ | |
url :"https://workdrive.zoho.com/api/v1/users/" + currentuserid + "/privatespace" | |
type :GET | |
headers:mp | |
connection:"workdrive" | |
]; | |
privatespacelist = response.getJSON("data"); | |
for each space in privatespacelist | |
{ | |
if(space.getJSON("type").equals("privatespace")) | |
{ | |
privatespaceid = space.getJSON("id"); | |
} | |
} | |
info "privatespaceid" + privatespaceid; | |
new_folder_name = "wdattachments" + record_id; | |
new_folder_resp = zoho.workdrive.createFolder(new_folder_name,privatespaceid,"workdrive"); | |
workdrive_folder_id = new_folder_resp.get("data").get("id"); | |
update_resp = zoho.crm.updateRecord(module_name, record_id, { | |
"zohoworkdriveforcrm__Workdrive_Folder_ID": workdrive_folder_id | |
}); | |
info update_resp; | |
} | |
mms_image_file = invokeurl | |
[ | |
url :mms_url | |
type :GET | |
]; | |
upload_resp = zoho.workdrive.uploadFile(mms_image_file,workdrive_folder_id,filename,false,"workdrive"); | |
info upload_resp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment