POST - To upload attachments

Purpose

This API is used to upload the attachment before using the file in an email. You can upload the attachments in two methods:

  1. MULTIPART_FORM_DATA= form-data(key=attach, value=file)
  2. REQUEST BODY

Refer here to check the API for sending an email with attachments. 

Request URL 

https://mail.zoho.com/api/accounts/<accountId>/messages/attachments

MULTIPART_FORM_DATA

The following request parameters should be used when you need to upload multiple attachments:

ParameterTypeDescription
 uploadType*string
  • To upload multiple attachments multipart value is mandatory.
  • Allowed value: multipart
  • Default value: null
isInlineboolean
  • The value for this key parameter should be True if you want to attach an inline image. 
  • Allowed values: true | false
  • Default value: false

- Mandatory parameters

REQUEST BODY

The following request parameters should be used when you need to upload an attachment in the request body

ParameterTypeDescription
fileName*string

Name of the file that is to be attached to the email.

isInlineboolean
  • The value for this key parameter should be True if you want to attach an inline image. 
  • Allowed values: true | false
  • Default value: false

- Mandatory parameters

Note:

  • Only the name of the file has to be passed in the Request URL, and not the file path.
  • The binary file is mandatory and has to be sent in the Request Body.

Failure Response Codes

Please refer Response Codes.

Sample Request

CopiedCloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost request = new HttpPost(REQUEST_URL);
String FILE_PATH="C:/MyPictures/OurVacation.png";
File file = new File(FILE_PATH);
HttpEntity entity = new FileEntity(file);
request.setEntity(entity);
request.setHeader("Content-Type", "application/octet-stream");
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
    InputStream instream = entity.getContent();
    try {

    } finally {
        instream.close();
    }
}

MULTIPART_FORM_DATA Sample Response: Parameter isInline is true

Copied{
   "status": {
       "code": 200,
       "description": "success"
   },
   "data": [
       {
           "attachmentSize": "9465",
           "storeName": "52882865",
           "attachmentName": "1642399004735000_125628183.jpeg",
           "attachmentPath": "/compose/1642399004735000_125628183.jpeg",
           "url": "/zm/ImageSignature?fileName=1642399004735000_125628183.jpeg&accountId=5883000000005001&storeName=52882865&frm=c"
       },
       {
           "attachmentSize": "347581",
           "storeName": "52882865",
           "attachmentName": "1642399004794000_125628183.jpg",
           "attachmentPath": "/compose/1642399004794000_125628183.jpg",
           "url": "/zm/ImageSignature?fileName=1642399004794000_125628183.jpg&accountId=5883000000005001&storeName=52882865&frm=c"
       },
       {
           "attachmentSize": "347581",
           "storeName": "52882865",
           "attachmentName": "1642399004839000_125628183.jpg",
           "attachmentPath": "/compose/1642399004839000_125628183.jpg",
           "url": "/zm/ImageSignature?fileName=1642399004839000_125628183.jpg&accountId=5883000000005001&storeName=52882865&frm=c"
       }
   ]
}

MULTIPART_FORM_DATA Sample Response: Parameter isInline is false

Copied{
    "status": {
        "code": 200,
        "description": "success"
    },
    "data": [
        {
            "attachmentSize": "9465",
            "storeName": "52882865",
            "attachmentName": "bt.jpeg",
            "attachmentPath": "/Mail/7db8a3aa5d5c12681bb51-bt.jpeg"
        },
        {
            "attachmentSize": "347581",
            "storeName": "52882865",
            "attachmentName": "4-ai-enlarged-photo-4x-full(1).jpg",
            "attachmentPath": "/Mail/5ea951795d5c126825b7a-4-ai-enlarged-photo-4x-full(1).jpg"
        },
        {
            "attachmentSize": "347581",
            "storeName": "52882865",
            "attachmentName": "4-ai-enlarged-photo-4x-full(1)(1).jpg",
            "attachmentPath": "/Mail/70b575dc5d5c12682ad84-4-ai-enlarged-photo-4x-full(1)(1).jpg"
        }
    ]
}

REQUEST BODY Sample Response: Parameter isInline is true

Copied{
   "status": {
       "code": 200,
       "description": "success"
   },
   "data": {
       "storeName": "53862395",
       "attachmentName": "1661333346116000_1282150461.jpeg",
       "attachmentPath": "/compose/1661333346116000_1282150461.jpeg",
       "url": "/zm/ImageSignature?fileName=1661333346116000_1282150461.jpeg&accountId=29254000000005001&storeName=53862395&frm=c"
   }
}

REQUEST BODY Sample Response: Parameter isInline is false

Copied{
    "status": {
        "code": 200,
        "description": "success"
    },
    "data": {
        "storeName": "53862395",
        "attachmentName": "bt.jpeg",
        "attachmentPath": "/Mail/4f7e6dfd5e6f952bccf41-bt.jpeg"
    }
}