Upload an Attachment
Purpose
To attach a file to a record. You must include the attachment in the request with content type as multipart/form data.
Request URL
https://www.zohoapis.com/crm/v2/{module_api_name}/{record_id}/Attachments
module_api_name - The API name of the module
record_id - The unique ID of the record
Modules supported in Get List of Attachments are supported here.
Request Method
POST
Scope
scope=ZohoCRM.modules.all
(or)
scope=ZohoCRM.modules.{module_name}.{operation_type}
(and)
scope=ZohoCRM.modules.attachments.all
| Possible module names | Possible operation types |
|---|---|
| leads, accounts, contacts, deals, campaigns, tasks, cases, events, calls, solutions, products, vendors, pricebooks, quotes, salesorders, purchaseorders, invoices, custom, and notes | ALL - Full access to attachments WRITE - Edit attachment data CREATE - Create attachment data |
Parameters
| Parameter Name | Data Type | Description |
|---|---|---|
| file (mandatory) | Text | Choose the attachment you want to upload. |
Sample Request: To upload a "text" file as an attachment
curl "https://www.zohoapis.com/crm/v2/Leads/1000000231009/Attachments"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-F "file=@attachment1.txt" Sample request: To upload a "link" as an attachment
curl "https://www.zohoapis.com/crm/v2/Leads/1386586000003152001/Attachments"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-F "attachmentUrl=https://www.zohocorp.com" Sample Response
{
"data": [
{
"code": "SUCCESS",
"details": {
"id": "1000000231009"
},
"message": "attachment uploaded successfully",
"status": "success"
}
]
} Sample Request
ZCRMRecord record = ZCRMRecord.getInstance("Products",23857634545l);//module api name with record id
APIResponse response = record.uploadAttachment("FilePath");
ZCRMAttachment uploadAttachment = (ZCRMAttachment) response.getData();
String requestStatus =response.getStatus(); Sample Response
{
"data": [
{
"code": "SUCCESS",
"details": {
"id": "1000000231009"
},
"message": "attachment uploaded successfully",
"status": "success"
}
]
} Sample Request
try{
$record=ZCRMRecord::getInstance(“Leads”,”410405000001111007”);
$responseIns=$record->uploadAttachment($filePath); // $filePath - absolute path of the attachment to be uploaded.
echo "HTTP Status Code:".$responseIns->getHttpStatusCode();
echo "Status:".$responseIns->getStatus();
echo "Message:".$responseIns->getMessage();
echo "Code:".$responseIns->getCode();
echo "Details:".$responseIns->getDetails()['id'];
}catch(ZCRMException $e)
{
echo $e->getCode();
echo $e->getMessage();
echo $e->getExceptionCode();
} Sample Response
{
"data": [
{
"code": "SUCCESS",
"details": {
"id": "1000000231009"
},
"message": "attachment uploaded successfully",
"status": "success"
}
]
} Sample Request
def upload_attachment(self):
try:
record = ZCRMRecord.get_instance('Leads', 3719520000000326007)
resp = record.upload_attachment('/Users/Downloads/pic1.png')
print(resp.data.id)
except ZCRMException as ex:
print(ex.status_code)
print(ex.error_message)
print(ex.error_code)
print(ex.error_details)
print(ex.error_content) Sample Response
{
"data": [
{
"code": "SUCCESS",
"details": {
"id": "1000000231009"
},
"message": "attachment uploaded successfully",
"status": "success"
}
]
} Sample Request
ZCRMRecord recordIns = ZCRMRecord.GetInstance("Leads", 3372164000000614001);//module api name with record id
APIResponse response = recordIns.UploadAttachment("/Users/Bob/Desktop/testreport/report-dec-18.htm");
ZCRMAttachment uploadAttachment = (ZCRMAttachment)response.Data; Sample Response
{
"data": [
{
"code": "SUCCESS",
"details": {
"id": "1000000231009"
},
"message": "attachment uploaded successfully",
"status": "success"
}
]
}