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

                                                                                                                • Arranging Ticket Templates

                                                                                                                  Is there any way to arrange our ticket templates? It doesn't look very organised when it's just arranged according to when they were created. We want the list to look more organised, by arranging/grouping them by topics, or even just by alphabetical
                                                                                                                • What they mean with "Portal"?

                                                                                                                  I just downloaded this app to take my personal notes on digital art studio because it seemed to me the most comfortable app to do it, I use it very often, what do they mean by “no activity on your portal”? I have about 1 year of work here and I don't
                                                                                                                • favorites no longer listed

                                                                                                                  Hello, I can no longer navigate to my Favorites from the pulldown at the top of my grid view (see attached screenshot). I wasn't able to find it anywhere! Please help me display my Favorites. Thank you!
                                                                                                                • Notecards Disappeared

                                                                                                                  Got a new phone. Downloaded and signed in Zoho Notebook. Not finding the Note cards. Just Empty Note books. Frustrating.
                                                                                                                • Table Errors

                                                                                                                  Hello, I'm new to Zoho Notebook and using it on several Mac/Apple devices. My question is regarding tables: Why do they become broken, and how to fix the error without retyping all my data? (Please see the screenshot attached.)
                                                                                                                • Online Calculator with Zoho Forms?

                                                                                                                  I'd like to build a custom calculator on my website. Zoho Forms seems to offer all the fields for basic calculations performed live without pressing any "Calculate" buttons. Unfortunately, there is still that "Submit" button at the bottom. There is nothing
                                                                                                                • Zoho Tables instead of Zoho Creator Spreadsheet reports <3

                                                                                                                  That would make my day for sure. Zoho Creator is create, but miss data entering as AirTable/Spreadsheet can. Seeing Zoho putting effort in this makes me think maybe one day we could see a similar interface for Zoho Creator spreadsheet reports. B.
                                                                                                                • Notebook Stack

                                                                                                                  Hi Everyone I Hope you´re fine, I´m sorry if this idea was posted before (I made a search but I haven´t find anything related). So, Having the possibility of stacking notebooks would be an interesting way to order notebooks that correspond to the same
                                                                                                                • Writing on sketch cards is bugged when zoomed in

                                                                                                                  When zoomed in, it writes a noticeable distance above or to the side of where you're actually trying to write. The further you're zoomed in, the more noticeable it is. Zooming is also entirely absent on the desktop version.
                                                                                                                • Swipe between notes on iPhone

                                                                                                                  It'd be convenient if I could move from one note to the next in a notebook simply by swiping left to right.
                                                                                                                • Sales IQ chat is not working in signed android apk

                                                                                                                  I have integrated ZOHO sales IQ support chat and i have followed each step and its working fine in my development build but when i create signed APK for it. Chat does not work in it and showing awaiting for detail. I previously asked the same query but
                                                                                                                • COQL order by COUNT not working

                                                                                                                  Dear community, I am trying to get a list of deal amounts per planner working on it and sorted to get see who has the least amount of deals. For some reason, I am unable to use sort by in combination with a COUNT. My original code was: query = "select
                                                                                                                • I want to duplicate a report and name it something else

                                                                                                                  Hi, I have created a report, and now want to reproduce it and call it something else. so that I will end up with TWO separate reports with different titles. Please tell me how do I copy / reproduce a report please
                                                                                                                • Zoho CRM: Sales Rep Professional Certification Program on Coursera

                                                                                                                  We are happy to share that we have published the Zoho Sales Representative Professional Certificate in partnership with Coursera, a leading platform for online learning and career development that offers access to courses and degrees from leading universities
                                                                                                                • OS X Notebook quits immediately upon launch

                                                                                                                  NoteBook for OS X (Sequoia, but also under Sonoma) always quits immediately upon launch (so I cannot use the "Attach user log" option). I've restarted my MacBook but the problem persists. If it helps, attached is a diagnostic report from Library>Log
                                                                                                                • Can External users upload files or images to WorkDrive?

                                                                                                                  I want to know if it is possible for someone externally through a link and PW be able to upload files and images onto WorkDrive?
                                                                                                                • Multi-line fields character limits

                                                                                                                  Is there a way to set the character limit higher on multi-line fields so that we are not losing information pasted into the field? When the text is entered or pasted, there is no error to say that the text is too large. After saving and going back to view most of the text is gone.   Also, when viewing the resume, the text is not wrapped in the multi line fields and can t be read without scrolling across the page.
                                                                                                                • Taz bot not working — What should I do to resolve this issue?

                                                                                                                  I am experiencing issues with the Taz bot in Zoho Cliq—not receiving responses or it does not seem to work as expected. Could you please explain why the Taz bot might not be functioning and what steps I should take to resolve this issue? Thank you!
                                                                                                                • OneNote Migration

                                                                                                                  I am trying to migrate two notebooks from OneNote. For five days now I have had no notification that migration has completed and the migration page show 50% complete - one notebook completed one not finished. It just stays like this. I am unable to cancel
                                                                                                                • Set various time slot reminders for task and event

                                                                                                                  Hi I would like known if there is possibility to set various time reminders for a task or event like we have the possibility to do in google calendar or google task. For example I'am creating an event or task and I want to be alerted before 30min and
                                                                                                                • Zoho Calendar not functioning---cannot edit, add attendees, etc.

                                                                                                                  Hello, My calendar is acting strange. I'm using Chrome as my browser and pop ups are not blocked (the calendar worked fine yesterday). When creating an event, I'm not able to "edit" the event and add attendees, etc. The link is non-responsive. I cannot
                                                                                                                • Spilt Axis for stacked column and line graph

                                                                                                                  Each month around this time I prepare a business review deck. One of the biggest annoyances I have with Zoho, also happens to be something that most other platforms have provided for a long time now, and that is being able to create a chart with stacked
                                                                                                                • Pin a note on top

                                                                                                                  Dear Zoho Notebook Team, Please highly consider adding ability to pin a note on top and arrange pinned notes. I have a lot of notes that I want to pin important ones on top and this feature is missing badly. Thank you.
                                                                                                                • Windows 11 app ver 2.2.8

                                                                                                                  I have been trialing Zoho Notes syncing between my PC and iphone. No problems with iphone but the Windows 64 bit app ver 2.2.8 was very buggy and would lock up completely, needing a Control Alt Delete etc to close it down. It seemed to be connected to
                                                                                                                • Deluge Script: Onboarding → Access Form

                                                                                                                  Hello everyone, Edit: Sorry, I think I put this topic in the wrong section. I’ve recently run into an issue that’s been giving me a bit of a headache for the past few weeks. Context: This is my first time using Deluge to create a script, but it’s not
                                                                                                                • Windows Device Authentication

                                                                                                                  We have recently started using ManageEngine, and my boss saw a device management feature in the Zoho One directory. We thought it would either help give us more intergration into Zoho one through bringing ManageEngine services through Zoho one. Or, it
                                                                                                                • How can I change spell check language?

                                                                                                                  I cannot find the way to change spell check language. My "display language" is English, and I want to have the same one for Spell Check, but it is Russian!!! How can I change it? In one of your explanations you mentioned that I have to choose it from
                                                                                                                • Mail is so slow - doesn't even work!

                                                                                                                  Mail has been getting slower and slower - and today it's not even pulling up emails in either Inbox or Unread. This is beyond frustrating since email is a big part of business. Sent a request through the useless help portal - no response. Called the useless
                                                                                                                • User marked as SPAMMER. Mail Fetch has also been disabled for any active POP accounts.

                                                                                                                  I am the administrator for joelles.com One of our accounts has been blocked saying this: User marked as SPAMMER. Mail Fetch has also been disabled for any active POP accounts. I cannot change the disabled account in the control panel as it says that it
                                                                                                                • Is there a way to sync Tags between CRM and Campaigns/Marketing Hub?

                                                                                                                  I wonder if there is a way to synch the tags between CRM and Marketing-Hub / Campaigns?
                                                                                                                • how to see if a specific contact opened an email in zoho campaign?

                                                                                                                  how to see if a specific contact opened an email in zoho campaign?
                                                                                                                • Revenue Management: #8 Revenue Recognition in Educational & Training Institutions

                                                                                                                  Educational Institutions and training centres typically collect course fees at the time of enrolment, sometimes for a one-day workshop and sometimes for a year-long certification course. You might also charge separately for course materials or evaluation.
                                                                                                                • Maximum file limit in zoho people LMS

                                                                                                                  Dear Team, I am having approximately 4.9 GB of material, including PPTs and videos for uploading in zoho people LMS course. May I know what is the maximum limit limit for the course files Thanking you, With regards, Logeswar V Executive _ Operations
                                                                                                                • Dynamically prefill ticket fields

                                                                                                                  Hello, I am using Zoho Desk to collect tickets of our clients about orders they placed on our website. I would like to be able to prefill two tickets fields dynamically, in this case a readonly field for the order id, and a hidden field for the seller
                                                                                                                • Optimize your Knowledge Base for better visibility by allowing search engine crawling and indexing

                                                                                                                  All you need to know about no-follow and no-index in KB. What are article crawlability and indexability? Crawlability and indexability are vital for making an article visible and accessible to search engines. When a search engine crawls an article, it
                                                                                                                • Has anyone created a public ASAP Guide that I can check out?

                                                                                                                  I am thinking of adding an ASAP guide to my web application, but I have noticed that the ASAP widget itself can be really slow to load sometimes. Has anyone created a public ASAP Guide that I can check to see how performant it is? I don't want to spend
                                                                                                                • What’s New in Zoho Analytics – September 2025

                                                                                                                  Hello Users!! In this month’s update, we’re raising the bar across multiple touchpoints, from how you bring in data, plan and track projects to how you design and brand your dashboards. We’ve added the all-new Gantt chart for project visualization, expanded
                                                                                                                • Zoho MCP has no tools for Creator or 3rd Party Apps?

                                                                                                                  I don't see a Zoho MCP community forum so putting this here. Two big problems I see: 1) Although Zoho advertises "over 950 3rd party apps" as available through their MCP, when I go to "Add Tools" there are ZERO 3rd party apps available to choose from.
                                                                                                                • Zoho Forms - Zoho Drive connection - Shared Drives not supported

                                                                                                                  Hello i am stuck with Google Drive Connection There is no supported shared drives Connection is not support shared drives boolean Query Parameters - supportsAllDrives=true&supportsTeamDrives=true to activate fetch files from the shared drives. Ahat need
                                                                                                                • Can't create package until Bill created?

                                                                                                                  I can't understand why we cannot create a package until a Bill is created? We are having to created draft Bills to create a package when the item is received, but we may not have received a Bill from the supplier. Also, Bill # is required, but we normally
                                                                                                                • Next Page