Adding Attachment to Mail using Send Mail API V2.1in Zoho CRM
I am trying to create a custom function where it sends a template email using the Send Mail API for version 2.1. In the structure, I would like to add an attachment which is available inside the record.
In API 2.1, one can add in attachment by providing the attachment id which I got via using Get Attachment list invoke url method to gain the specific file id. However, it resulted an error as below:
- {"data":[{"code":"INVALID_DATA","details":{"api_name":"id","json_path":"$.data[0].attachments[0].id"},"message":"There is no file exists with the given id","status":"error"}]}
the method i was trying was :
//getting list of attachment
getAttachments = invokeurl
[
url :"https://www.zohoapis.com/crm/v2.1/Contacts/" + ContactID + "/Attachments"
type :GET
connection:"zcrm"
];
attachment_id = getAttachments.get("data").get(0).get("$file_id");
//inputting inside email
Attach = List();
attach = Map();
attach.put("id",attachment_id.toString());
Attach.add(attach);
mergedatalist = List();
mergedata = Map();
mergedata.put("from",frm);
//sender
mergedata.put("to",toward);
//recipient
mergedata.put("org_email",false);
mergedata.put("attachments",Attach);
//attachment id
mergedata.put("template",temp);
//template id
mergedatalist.add(mergedata);
data = Map();
data.put("data",mergedatalist);
//send email
sendingmail = invokeurl
[
url :"https://www.zohoapis.com/crm/v2.1/Contacts/" + ContactID + "/actions/send_mail"
type :POST
parameters:data.toString()
connection:"zcrm"
];
info sendingmail;