Upload Attachment

Purpose

This API allows you to upload attachments before using the file in an email. There are two methods to upload attachments using: 

  1. MULTIPART_FORM_DATA
  2. Request Body

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

OAuth Scope

Use the scope

ZohoMail.messages.ALL (or) ZohoMail.messages.CREATE

to generate the Authtoken.

ALL - Grants full access to messages.

CREATE - Grants access to upload attachments to messages.

Request URL

Method: POST

https://mail.zoho.com/api/accounts/{accountId}/messages/attachments

Path Parameters

  • accountId* long
    • This key is used to identify the account from which the email has to be sent. It is generated during account addition.
    • This parameter can be fetched from Get All User Accounts API.

Query parameters

Using "Multi_Part_Form_Data"

Use this method when you need to upload multiple attachments.

  • uploadType* string
    • To upload multiple attachments, this multipart value is mandatory. 
    • Allowed value: multipart
    • Default value: null
  • isInline boolean
    • Specifies whether you want to attach an inline image or not.
    • Allowed values:
      • true - Want to attach an inline image.
      • false - Do not want to attach an inline image.
    • Default value: false.
Using Request Body (JSON object)

Use this method when you need to upload a single attachment.

  • fileName* string
    • Provide the name of the file which is to be attached to the email.
  • isInline boolean
    • Specifies whether you want to attach an inline image or not.
    • Allowed values:
      • true - Want to attach an inline image.
      • false - Do not want to attach an inline image.
    • Default value: false.

 

Note: When attachment data is given using the request body:

  • 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.

 

* - Mandatory parameter

Response Codes

Refer here for the response codes and their meaning.

Multi_Part_Form_Data : Sample Request (when "inline" = false)

Copiedcurl --location 'https://mail.zoho.com/api/accounts/123456789/messages/attachments?uploadType=multipart' \
-H 'Authorization: Zoho-oauthtoken 11***************' \
-H 'Cookie: zmuac=NzE0ODE1Mjc0XzI0NjA0NjQ=; _zcsr_tmp=5f0a9ba8-cdf7-4397-9321-3d80680282fa; fc2f5e4ce1=e30668dc42df6294320bb6301d6073f1; zmcsr=5f0a9ba8-cdf7-4397-9321-3d80680282fa' \
--form 'attach=@/Users/rebecca-9961/Documents/rebecca/HA/test/image (1).jpeg'

Multi_Part_Form_Data : Sample Request (when "inline" = true)

Copiedcurl --location 'https://mail.zoho.com/api/accounts/123456789/messages/attachments?uploadType=multipart&isInline=true' \
-H 'Authorization: Zoho-oauthtoken 11***************' \
-H 'Cookie: zmuac=NzE0ODE1Mjc0XzI0NjA0NjQ=; _zcsr_tmp=5f0a9ba8-cdf7-4397-9321-3d80680282fa; fc2f5e4ce1=e30668dc42df6294320bb6301d6073f1; zmcsr=5f0a9ba8-cdf7-4397-9321-3d80680282fa' \
--form 'attach=@/Users/rebecca-9961/Documents/rebecca/HA/test/image (1).jpeg'

Request Body : Sample Request (when "inline" = false)

Copiedcurl --location 'https://mail.zoho.com/api/accounts/123456789/messages/attachments' \
-H 'Authorization: Zoho-oauthtoken 11***************' \
-H 'Content-Type: application/json' \
-H 'Cookie: zmuac=NzE0ODE1Mjc0XzI0NjA0NjQ=; _zcsr_tmp=5f0a9ba8-cdf7-4397-9321-3d80680282fa; fc2f5e4ce1=e30668dc42df6294320bb6301d6073f1; zmcsr=5f0a9ba8-cdf7-4397-9321-3d80680282fa' \
--data-raw '{
  "fileName": "image (1).jpeg",
  "isInline": false
}' \
--data-binary '@/Users/rebecca-9961/Documents/rebecca/HA/test/image (1).jpeg'

Request Body : Sample Request (when "inline" = true)

Copiedcurl --location 'https://mail.zoho.com/api/accounts/123456789/messages/attachments' \
-H 'Authorization: Zoho-oauthtoken 11***************' \
-H 'Content-Type: application/json' \
-H 'Cookie: zmuac=NzE0ODE1Mjc0XzI0NjA0NjQ=; _zcsr_tmp=5f0a9ba8-cdf7-4397-9321-3d80680282fa; fc2f5e4ce1=e30668dc42df6294320bb6301d6073f1; zmcsr=5f0a9ba8-cdf7-4397-9321-3d80680282fa' \
--data-raw '{
  "fileName": "image (1).jpeg",
  "isInline": true
}' \
--data-binary '@/Users/rebecca-9961/Documents/rebecca/HA/test/image (1).jpeg'

Sample Response (when "inline" = false)

Copied{
    "status": {
        "code": 200,
        "description": "success"
    },
    "data": [
        {
            "storeName": "714815274",
            "attachmentName": "image (1).jpeg",
            "attachmentPath": "/Mail/60fb87f7619f7794e5853-image (1).jpeg"
        }
    ]
}

Sample Response (when "inline" = true)

Copied{
    "status": {
        "code": 200,
        "description": "success"
    },
    "data": [
        {
            "storeName": "714815274",
            "attachmentName": "1717400515954013_1814088797.jpeg",
            "attachmentPath": "/compose/1717400515954013_1814088797.jpeg",
            "url": "/zm/ImageSignature?fileName=1717400515954013_1814088797.jpeg&accountId=123456789&storeName=714815274&frm=c"
        }
    ]
}