Issue Uploading Attachment with Zoho Mail360 API using Deluge

Issue Uploading Attachment with Zoho Mail360 API using Deluge

Hi everyone,

I'm trying to upload an attachment using the Zoho Mail360 API in a Deluge function, but I'm running into issues.

Here is the documentation I’m referring to:
🔗 Upload Attachment - Mail360 API

According to the docs, the upload is done with a POST request to:

https://mail360.zoho.com/api/accounts/{account_key}/attachments?fileName=<file_name>

with:

  • Content-Type: application/octet-stream

  • OAuth token in the header

  • Binary file content in the body

Here's the Deluge function I implemented based on that:

string Mail360.uploadAttachment(string accountKey, string fileUrl)

{

    // Download the file from the given URL

    fileVariable = invokeurl

    [

        url : fileUrl

        type : GET

    ];

    fileContent = fileVariable.getFileContent();

    fileName = fileVariable.getFileName();


    // Construct the API URL

    url = "https://mail360.zoho.com/api/accounts/" + accountKey + "/attachments?fileName=" + fileName;


    // Get access token

    accessToken = thisapp.Mail360.getAccessToken(thisapp.variables.Mail360.clientId, thisapp.variables.Mail360.clientSecret, thisapp.variables.Mail360.refreshToken);


    // Set headers

    headers = Map();

    headers.put("Authorization", "Bearer " + accessToken);

    headers.put("Content-Type", "application/octet-stream");


    // API request to upload the attachment

    response = invokeurl

    [

        url : url

        type : POST

        parameters : fileContent

        headers : headers

    ];


    return response;

}

However, the API either fails silently or returns an error (sometimes with no clear message). I suspect something might be wrong with how I'm sending the binary data in Deluge.

If anyone has successfully implemented this API in Creator or faced similar issues, I’d really appreciate your guidance. Am I missing something in how the binary file is being sent?

Thanks in advance!