Kaizen #45 - Handling Attachments API in Java and Java SDK (Part 2/2)

Kaizen #45 - Handling Attachments API in Java and Java SDK (Part 2/2)

Hello everyone!

Welcome back to yet another post in the Kaizen series. In our last post, we started our discussion about handling the attachments in Java and Java SDK where we discussed listing the attachments and uploading the attachments to a record in Zoho CRM.

This week, we will discuss the other two operations in attachments API.
1. Download an attachment 
2. Delete an attachment.


1. Download an Attachment
To download a file attached to a record.

Request method: GET
Request URL:  {{api-domain}}/crm/v2/{module_api_name}/{record_id}/Attachments/{attachment_id}

Sample URL: {{api-domain}}/crm/v2/Leads/3719520000000659047/attachments/3719520000000992004

Java SDK Code
The Java SDK employs downloadAttachment() method for the operation which primarily requires the record_id(3719520000000659047) and the attachment_id(3719520000000992004) for its successful execution. The attachment_id can be fetched from List Attachments API

public void downloadAttachment() throws Exception{
  ZCRMRecord record=ZCRMRecord.getInstance("Leads",3719520000000659047L);
  FileAPIResponse responseIn=record.downloadAttachment(3719520000000992004L);
       String filepath="/Users/srivathsan-8829/Documents";
        File file=new File(filepath+responseIn.getFileName()); 
        System.out.println( "HTTP Status Code:"+responseIn.getStatusCode());
        System.out.println( "File Name:"+responseIn.getFileName());
        InputStream fin = responseIn.getFileAsStream();
        int i=0;    
        while((i=fin.read())!=-1){    
         System.out.print((char)i);    
        }    
    }

Java Code
public void downloadAttachments() throws Exception
 {
  CloseableHttpClient httpclient = HttpClients.createDefault();
     HttpGet httpget = new HttpGet("{{api-domain}}/crm/v2/Leads/3719520000000659047/attachments/3719520000000991001");
     httpget.addHeader("Authorization", "Zoho-oauthtoken 1000.9XXXX.6XXXX");
     System.out.println("Request Type: "+httpget.getMethod());
     HttpResponse httpresponse = httpclient.execute(httpget);
     Scanner sc = new Scanner(httpresponse.getEntity().getContent());
     System.out.println(httpresponse.getStatusLine());
     while(sc.hasNext()) {
          System.out.println(sc.nextLine());
     }
}

Sample Response:


2. Delete an Attachment
To delete a file attached to a record.

Request method: DELETE
Request URL:  {{api-domain}}/crm/v2/{module_api_name}/{record_id}/Attachments/{attachment_id}

Sample URL:  {{api-domain}}/crm/v2/Leads/3719520000000659047/attachments/3719520000000981001

Java SDK Code
Similar to download attachment operation, delete attachment requires the record_id and the attachment_id as the pre-requisites. The operation is performed with the assistance from deleteAttachment() method. The attachment_id can be fetched from List Attachments API

public void deleteAttachment() throws Exception{
  ZCRMRecord record=ZCRMRecord.getInstance("Leads",3719520000000659047L);
  APIResponse responseIn=record.deleteAttachment(3719520000000981001L);
  System.out.println( "Status:"+ responseIn.getMessage());
        System.out.println( "Message:"+ responseIn.getStatus());
        System.out.println("http code"+ responseIn.getStatusCode());
        System.out.println( " Code:"+responseIn.getResponseJSON().toString());
 }

Java Code
public void deleteAttachments() throws Exception
 {
  CloseableHttpClient httpclient = HttpClients.createDefault();
     HttpDelete httpdelete = new HttpDelete("{{api-domain}}/crm/v2/Leads/3719520000000659047/attachments/3719520000000981001");
     httpdelete.addHeader("Authorization", "Zoho-oauthtoken 1000.9XXXX.6XXXX");
     System.out.println("Request Type: "+httpdelete.getMethod());
     HttpResponse httpresponse = httpclient.execute(httpdelete);
     Scanner sc = new Scanner(httpresponse.getEntity().getContent());
     System.out.println(httpresponse.getStatusLine());
     while(sc.hasNext()) {
          System.out.println(sc.nextLine());
     }
 }

Sample Response
{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "id": "3719520000000981001"
            },
            "message": "record deleted",
            "status": "success"
        }
    ]
}

With this post, we conclude our discussion about handling the attachments API with Java SDK and Java. We hope you found this post useful. Let us know your thoughts in the comment section or reach us out at support@zohocrm.com.

Cheers!









    Access your files securely from anywhere

        All-in-one knowledge management and training platform for your employees and customers.







                              Zoho Developer Community




                                                    • Desk Community Learning Series


                                                    • Digest


                                                    • Functions


                                                    • Meetups


                                                    • Kbase


                                                    • Resources


                                                    • Glossary


                                                    • Desk Marketplace


                                                    • MVP Corner


                                                    • Word of the Day


                                                    • Ask the Experts



                                                              • Sticky Posts

                                                              • Kaizen #198: Using Client Script for Custom Validation in Blueprint

                                                                Nearing 200th Kaizen Post – 1 More to the Big Two-Oh-Oh! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                              • Kaizen #226: Using ZRC in Client Script

                                                                Hello everyone! Welcome to another week of Kaizen. In today's post, lets see what is ZRC (Zoho Request Client) and how we can use ZRC methods in Client Script to get inputs from a Salesperson and update the Lead status with a single button click. In this
                                                              • Kaizen #222 - Client Script Support for Notes Related List

                                                                Hello everyone! Welcome to another week of Kaizen. The final Kaizen post of the year 2025 is here! With the new Client Script support for the Notes Related List, you can validate, enrich, and manage notes across modules. In this post, we’ll explore how
                                                              • Kaizen #217 - Actions APIs : Tasks

                                                                Welcome to another week of Kaizen! In last week's post we discussed Email Notifications APIs which act as the link between your Workflow automations and you. We have discussed how Zylker Cloud Services uses Email Notifications API in their custom dashboard.
                                                              • Kaizen #216 - Actions APIs : Email Notifications

                                                                Welcome to another week of Kaizen! For the last three weeks, we have been discussing Zylker's workflows. We successfully updated a dormant workflow, built a new one from the ground up and more. But our work is not finished—these automated processes are


                                                              Manage your brands on social media



                                                                    Zoho TeamInbox Resources



                                                                        Zoho CRM Plus Resources

                                                                          Zoho Books Resources


                                                                            Zoho Subscriptions Resources

                                                                              Zoho Projects Resources


                                                                                Zoho Sprints Resources


                                                                                  Qntrl Resources


                                                                                    Zoho Creator Resources



                                                                                        Zoho CRM Resources

                                                                                        • CRM Community Learning Series

                                                                                          CRM Community Learning Series


                                                                                        • Kaizen

                                                                                          Kaizen

                                                                                        • Functions

                                                                                          Functions

                                                                                        • Meetups

                                                                                          Meetups

                                                                                        • Kbase

                                                                                          Kbase

                                                                                        • Resources

                                                                                          Resources

                                                                                        • Digest

                                                                                          Digest

                                                                                        • CRM Marketplace

                                                                                          CRM Marketplace

                                                                                        • MVP Corner

                                                                                          MVP Corner









                                                                                            Design. Discuss. Deliver.

                                                                                            Create visually engaging stories with Zoho Show.

                                                                                            Get Started Now


                                                                                              Zoho Show Resources

                                                                                                Zoho Writer

                                                                                                Get Started. Write Away!

                                                                                                Writer is a powerful online word processor, designed for collaborative work.

                                                                                                  Zoho CRM コンテンツ




                                                                                                    Nederlandse Hulpbronnen


                                                                                                        ご検討中の方




                                                                                                                • Recent Topics

                                                                                                                • Trigger workflow base on email clic

                                                                                                                  Searching the help and forum, I see that there were workflow trigger rules based on email. But now, I can't find this type of trigger when I create a custom workflow. What I'm looking for would be to automate the sending of an email for a new prospect,
                                                                                                                • Bigin Form Acknowledgement

                                                                                                                  How to troubleshoot and find out why form acknowledgement is not sending emails after form submission?
                                                                                                                • Zoho Mail POP & IMAP Server Details

                                                                                                                  Hello all! We have been receiving a number of requests regarding the errors while configuring or using Zoho Mail account in POP/ IMAP clients. The server details vary based on your account type and the Datacenter in which your account is setup. Ensure
                                                                                                                • Ever since the new Android App udpates notifications are not working

                                                                                                                  notifications are not working for the app is its closed I followed the tutuorial to the notificaction fixed and everythig seems to be right but notifications are not workig
                                                                                                                • Zoho Analytics & Zoho Desk - but not all desks

                                                                                                                  I have several desks in our company and one of those is used by our HR department. I want to bring through the data to the shared Zoho Analytics workspace - except for the HR desk. Can this be excluded at data import stage ?
                                                                                                                • Incoming Emails Not Showing Up in Zoho Inbox

                                                                                                                  Hi - I have my Zoho email account set up to forward a copy of all incoming emails to a secondary Gmail address, whilst retaining the original email in the Zoho inbox. However, all my incoming emails are currently not showing up in my Zoho inbox, so I'm
                                                                                                                • SHEET - Send email when a cell changes

                                                                                                                  I would like to create a custom function for Zoho Sheet that triggers when a paticular cell changes to a specific value. This would result in sending an email to a recipient (this would be an address that remains the same and included in the script). Example: = IF(N4= "Drafted", <>EmailFunction) 1)     Cell N4 changes to "Drafted" 2)    Email is sent to recipient            or alternatively 3)    Post to chat channel I have found the Custom function editor in Sheet. I am not bad at scripting, but
                                                                                                                • 【開催報告】 福岡 ユーザー交流会 2025/8/8(金)

                                                                                                                  皆さま、こんにちは。コミュニティチームの中野です。 8/8(金)に、福岡 ユーザー交流会を開催しました。 本投稿では、その様子をお届けします。当日の登壇資料などもこちらに共有しますので、参加できなかった皆さまもご参照ください。 今年初の開催となる福岡 ユーザー交流会では、CreativeStudio樂合同会社 前田さんによるZoho CRM / Sign / Survey の事例セッションのほか、 Zoho社員セッションでは、Zoho Forms の活用法を解説。 さらに、「見込み客・顧客データの管理/活用方法」をテーマに参加者同士でZoho
                                                                                                                • Error: Invalid login: 535 Authentication Failed

                                                                                                                  I have used zoho with nodemailer. const transporter = nodemailer.createTransport({ host: 'smtp.zoho.com', port: 465, secure: true, auth: { user: 'example@example.com', pass: 'password' } }); While sending the mail, it shows the following error: Error:
                                                                                                                • Zoho Renewal

                                                                                                                  Hello, If I am not going for zoho email renewal. will i get back my free zoho account? and if yes then is it possible to get back my all free user. how many user get back 10 or 25?
                                                                                                                • Not reciving emails

                                                                                                                  Apparently i cannot recive emails on my adress contact@sportperformance.ro I can send, but do not recive. The mail i'm trying to send from mybother adress gets sent and doesn't bounce back... but still doesn't get in my inbox. Please advise
                                                                                                                • Not receiving MailChimp verification e-mail

                                                                                                                  It seems that their verification e-mails are blocked. I can receive their other e-mails, but not their verification of domain ownership e-mail. I've checked and double checked how I typed the e-mail, using different e-mails (my personal e-mail can receive it), white listing the domain and all that is left is for the IP's to be white listed, but I don't have that power.  If a staff member could take a look at this -> http://mailchimp.com/about/ips/ And perhaps white list them for me, that would be
                                                                                                                • Creating my 2nd email account

                                                                                                                  After creating my first email address, I decided to get another email address. I would like to use this new address as the primary address too. I don't know how to set it up there doesn't seem to be an option for that
                                                                                                                • Cannot - create more email account - Unusual activity detected from this IP. Please try again after some time

                                                                                                                  Hello, I come across the error message in Control Panel. Unusual activity detected from this IP. Please try again after some time and i cannot create any more users We are an IT company and we provide service for another company Please unlock us.
                                                                                                                • "Unable to send message;Reason:553 Relaying disallowed. Invalid Domain"

                                                                                                                  Good day. When I try to send mail through ZOHO mail I get the following error : "Unable to send message;Reason:553 Relaying disallowed. Invalid Domain" I need help with this. My zohomail is : @eclipseweb.site Thank you,
                                                                                                                • Transfert de domaine pour création des comptes emails

                                                                                                                  Bonjour , je ne parviens point à créer des mails avec le domaine 'raeses.org' suite à la souscription du domaine auprès d'un autre hébergeur, dont j'ai fait la demande du code de transfert qui est le suivant : J2[U8-l0]p8[ En somme, attente de l'activation
                                                                                                                • Help! Unable to send message;Reason:554 5.1.8 Email Outgoing Blocked.

                                                                                                                  Kindly help me resolved this issue that i am facing here.
                                                                                                                • How are people handling estimates with Zoho inventory?

                                                                                                                  We are often using Zoho Books for estimates that then get converted to invoices within Books. We would like the sales team to migrate entirely to Zoho Inventory and no longer need to use Zoho Books so that they are only on one system. How are people managing
                                                                                                                • Relative Date Searches

                                                                                                                  Currently in the search options, it has "date", "from date" and "to date". I think it would be great if there were options like "date greater than x days ago" and "date less than x days ago". I realise that as a once off you can just use the existing
                                                                                                                • Ask the Experts 23: Customize, utilize, and personalize with Zoho Desk

                                                                                                                  Hello everyone! It's time for the next round of Ask the Experts (ATE). This month is all about giving Zoho Desk a complete makeover and making it truly yours. Rebrand Zoho Desk with your organization’s details, customize ticket settings based on your
                                                                                                                • Please review and re-enable outgoing emails for my domain

                                                                                                                  Hello Zoho Support, I have recently purchased a new domain and set up email hosting with Zoho. However, my account shows "Outgoing Email Blocked". I am a genuine user and not sending bulk/spam emails. Please review and re-enable outgoing emails for my
                                                                                                                • Payroll without tax integrations (i.e. payroll for international)

                                                                                                                  It seems as though Zoho waits to develop integrations with local tax authorities before offering Zoho Payroll to Zoho customers in a country. Please reconsider this approach. We are happy Zoho Books customers, but unhappy that we have to run payroll in
                                                                                                                • goingout e mail block

                                                                                                                  info@ozanrade.com.tr
                                                                                                                • Incoming mails blocked

                                                                                                                  Zoho User ID : 60005368884 My mail Id is marketing#axisformingtechnology.com .I am getting following message "Your Incoming has been blocked and the emails will not be fetched in your Zoho account and POP Accounts. Click here to get unblocked." Please
                                                                                                                • Configuring Email Notifications with Tautulli for Plex

                                                                                                                  Hi I'm new to Zoho. I am from Canada and I have a I use a web based application called Tautulli for Plex that monitors my Plex media server. It also sends a newsletter to my followers. To set this up they require a "From" email address., a smtp server
                                                                                                                • How to Set Up Zoho Mail Without Cloudflare on My Website

                                                                                                                  I'm having some trouble with Cloudflare here in Pakistan. I want to configure Zoho Mail for my domain, but I'm not sure how to set it up without going through Cloudflare. My website, https://getcrunchyrollapk.com/ , is currently using CF, but I'd like
                                                                                                                • Spam is Being Forwarded

                                                                                                                  I am filtering a certain sender directly to the Trash folder. Those messages are still being forwarded. Is this supposed to happen?
                                                                                                                • IMAP Block

                                                                                                                  My two accounts have been blocked and I am not able to unblocked them myself. Please respond to email, I am traveling and this is urgent.
                                                                                                                • "DKIM not configured"

                                                                                                                  Hello. I have been attempting get the DKIM verified but Toolkit keeps sending the message that it is not configured, but both Namecheap and Zoho show it as configured properly. What am I missing?
                                                                                                                • Zoho mail with custom domain not receiving email

                                                                                                                  i registered zoho mail with my own domain. I can login and access the mail app. I tried to send email from an outlook email account and an icloud email account. Both emails were not received. My plan is free. I also tried to send email from this zoho
                                                                                                                • A Sales Ebook to help Sales representatives increase Sales.

                                                                                                                  I worked in sales for twenty years with the same company. I was an outdoor sales representative selling health insurance. My first Year I made it into the company's President's club. I wrote an Ebook sharing how I was able to achieve success in sales
                                                                                                                • Waterfall Chart

                                                                                                                  Hello, I would like to create a waterfall chart on Zoho analytics which shows the movement in changes of budget throughout a few months, on a weekly basis. Should look something like the picture below. Does anyone know how to?
                                                                                                                • Issue with Importing Notes against Leads

                                                                                                                  Hi, I am attempting to import some Notes into Zoho CRM which need to be assigned to various Leads. I have created a csv file which I am testing that contains just one record. This csv file contains the following columns: Note Id Parent Id       (I have
                                                                                                                • Option to Hide Project Overview for Client Profiles

                                                                                                                  In Zoho Projects, the Project Overview section is currently visible to client profiles by default. While user profiles already have the option to restrict or hide access to the project overview, the same flexibility isn’t available for client profiles.
                                                                                                                • Creator Add Records through API - Workflows not triggered ?

                                                                                                                  Hi Everyone, I am trying to add records to my Creator application through a third party app that I am developing. Currently, I am testing this through Postman. The records I need to add have a lot of workflows to run to populate dropdowns, fields, use
                                                                                                                • Important Update: Changes to Google Translate Support in Zoho SalesIQ

                                                                                                                  We’re updating our default chat translation options across all Zoho SalesIQ data centres to offer a more secure, in-house solution for your translation needs. What’s changing? We will be offering Zoho Translate (our in-house tool) as the default translation
                                                                                                                • Zoho CRM Community Digest - July 2025 | Part 1

                                                                                                                  Hey everyone, The start of July 2025 marked a special milestone: 200 posts in our Kaizen series! For those new here, Kaizen is a go-to series for Zoho CRM developers, where we regularly share best practices, tips, and expert insights to help you build
                                                                                                                • What’s New in Zoho Expense (April – July 2025)

                                                                                                                  Hello users, We're happy to bring you the latest updates and enhancements we've made to Zoho Expense over the past three months, which include introducing the Trip Expense Summary report in Analytics, extending Chatbot support to more editions, rolling
                                                                                                                • Weekly Tips: Insert frequently used phrases in a jiffy using Hotkeys

                                                                                                                  You often find yourself using similar phrases in an email —like confirming appointments or providing standard information. Constantly switching between the mouse and keyboard interrupts your flow and slows you down.Instead of typing the same phrases over
                                                                                                                • Undo Command in Notebook

                                                                                                                  It would be handy to have an Undo in the row of icons at the bottom of the notes.
                                                                                                                • Next Page