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







                            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 #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
                                                            • Kaizen #152 - Client Script Support for the new Canvas Record Forms

                                                              Hello everyone! Have you ever wanted to trigger actions on click of a canvas button, icon, or text mandatory forms in Create/Edit and Clone Pages? Have you ever wanted to control how elements behave on the new Canvas Record Forms? This can be achieved
                                                            • Kaizen #142: How to Navigate to Another Page in Zoho CRM using Client Script

                                                              Hello everyone! Welcome back to another exciting Kaizen post. In this post, let us see how you can you navigate to different Pages using Client Script. In this Kaizen post, Need to Navigate to different Pages Client Script ZDKs related to navigation A.
                                                            • Kaizen #210 - Answering your Questions | Event Management System using ZDK CLI

                                                              Hello Everyone, Welcome back to yet another post in the Kaizen Series! As you already may know, for the Kaizen #200 milestone, we asked for your feedback and many of you suggested topics for us to discuss. We have been writing on these topics over the


                                                            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

                                                                                                              • This domain is not allowed to add. Please contact support-as@zohocorp.com for further details

                                                                                                                I am trying to setup the free version of Zoho Mail. When I tried to add my domain, theselfreunion.com I got the error message that is the subject of this Topic. I've read your other community forum topics, and this is NOT a free domain. So what is the
                                                                                                              • Print Labels

                                                                                                                How can I configure my address to print my labels like this: Name Mailing Address Mailing City, Mailing State Mailing Zip Country Instead of: Name Mailing Address Mailing City Mailing State Mailing Zip Country Thanks!!!!
                                                                                                              • Mailing labels - Improperly formatted

                                                                                                                All I'm trying to do is print one, properly formatted, mailing label. I'm in the Contacts module. In the default "list view" for mailing labels I selected a single client, hit the "more actions" drop down and selected print mailing label. Unfortunately,
                                                                                                              • Printing mailing labels

                                                                                                                The ability to print mailing labels would seem to be an important, basic, function of a good CRM. I find it very surprising that this has still not been addressed adequately by Zoho. When trying to use the existing "mailing label" included: 1. the data
                                                                                                              • Pageless mode needed to modernise Writer

                                                                                                                When we switched from GSuite to Zoho, one of the easiest apps I found to give up, was Docs. In many ways, Writer has always been more powerful than Docs, especially in terms of workflows/fillable forms/etc. However, I went back into Docs because I notice
                                                                                                              • Zoho Projects - Visual improvement to parent and sub-task relationship

                                                                                                                Hi Projects Team, My feature request is to improve sub-task visibility. Please see screenshot below. I really think parent child relationships could be visually improved. Even if the first letter of the parent task was inline with other same level tasks
                                                                                                              • AI Interview Insights: Turn Recorded Interviews into Quick Transcripts & Summaries

                                                                                                                Evaluating interviews shouldn’t require replaying long recordings or taking manual notes. With AI Interview Insights, you can now review complete transcripts and AI-generated summaries of your One-way (Recorded) interviews right inside Zoho Recruit. This
                                                                                                              • API method to get activity feed in Recruit

                                                                                                                Hi community, I'm trying to figure out - is there any API method tto get information about datetime when Recruit/Candidates record tag where added?
                                                                                                              • Printing Mailing labels

                                                                                                                Is there any way to adjust the size of the printing labels? or product would I use to print labels from Zoho? Thanks, Josef Krieger Moderation Update (14th April 2025): We have another post discussing the same topic with votes and feedback from users.
                                                                                                              • Default to Current Date

                                                                                                                I'm importing data from a excel spread sheet that does not have date column and I'd like the date column in the Zoho Database to default to the current date. Any way I can do this?
                                                                                                              • "Spreadsheet Mode" for Fast Bulk Edits

                                                                                                                One of the challenges with using Zoho Inventory is when bulk edits need to be done via the UI, and each value that needs to be changed is different. A very common use case here is price changes. Often, a price increase will need to be implemented, and
                                                                                                              • Different Company Name for billing & shipping address

                                                                                                                We are using Zoho Books & Inventory for our Logistics and started to realize soon, that Zoho is not offering a dedicated field for a shipping address company name .. when we are creating carrier shipping labels, the Billing Address company name gets always
                                                                                                              • What's New in Zoho Inventory | Q2 2025

                                                                                                                Hello Customers, The second quarter have been exciting months for Zoho Inventory! We’ve introduced impactful new features and enhancements to help you manage inventory operations with even greater precision and control. While we have many more exciting
                                                                                                              • Make Packages from multiple sales order of a single customer

                                                                                                                Our customers sends orders to us very frequently, some times what customer wants is to ship items from 5 to 6 sales orders in a single shipment. it will be very nice if, zoho can implement this function, in which we can select items from other sales orders of the customer.
                                                                                                              • Update CRM Price Books to include volume discounts as per Zoho Books/Inventory

                                                                                                                Once again, Zoho has 3 great products that all store information in different ways (which is not helpful when you attempt to integrate the 3 products - one of the best features of Zoho). Zoho CRM Price Books are basic at best. Zoho Books/Inventory Price
                                                                                                              • Print a price list or price book

                                                                                                                Hi Community. Am I right in concluding that Zoho has no functionality to print a price list from either Zoho CRM, Zoho Inventory or Zoho Books? I won't get stuck on the fact that Zoho doesn't sync price books between Zoho CRM and Books/Inventory (more
                                                                                                              • Start Workflow from Deluge Script

                                                                                                                I have developed a customized process from our CRM that leverages a deluge script to create a statement of work document. Once the document has been created via the merge and store function, I would like the ability to start a workdrive review & approve
                                                                                                              • Show Custom Button in Portal Listview Canvas

                                                                                                                I have created a custom button that shows in a list view of deals (internally I can see it). I have permissions to allow this button on the portal. But it is not displaying in the canvas list? Before I do too much leg work, is this function allowed?
                                                                                                              • Zoho Survey Enhancements

                                                                                                                We love Survey. We use it a ton. It needs some enhancements. Maybe some of these are already on the roadmap? API - this is crucial. We have some complex surveys that take place and need to update records, trigger other functions/automations, etc. I would
                                                                                                              • Work Order Assignment for Engineers Handling Their Own Requests

                                                                                                                I’m setting up FSM for a business where there are multiple engineers, but each engineer handles their own process end-to-end receiving the service request, creating the work order, and completing the field service job. I noticed that I must create an
                                                                                                              • Zoho Sites "pages" management page

                                                                                                                I have 80 plus pages on zoho sites. When I go to the "pages" link to view and edit pages, They are not in any kind of order, so I spend lots of time searching for pages when I need to edit or create new. How can I change the view order of all my pages
                                                                                                              • AI feature in Zoho Desk suggesting answers based on past ticket threads

                                                                                                                Hi I would like to suggest something that would be very useful : instead of suggesting answers based on the Knowledge Base, I think it would be great if Zia could analyze the history of all customer and agents threads, to suggest answers in new tickets.
                                                                                                              • Advanced Customization of the Help Center using JavaScript

                                                                                                                Hello everyone, The Help Center in Zoho Desk can be customized by using HTML and CSS to provide structure and enhance the page's appearance—but what if you want to add interactive and dynamic elements? You can add these effects with JavaScript, a programming
                                                                                                              • Using a CRM Client Script Button to create a Books Invoice

                                                                                                                Hello, I need help handling error messages returned to my client script from a function. The scenario I have setup a client script button which is available from each Deal. This CS executes a crm function, which in turn creates an invoice based on the
                                                                                                              • Using IMAP configuration for shared email inboxes

                                                                                                                Our customer service team utilizes shared email boxes to allow multiple people to view and handle incoming customer requests. For example, the customer sends an email to info@xxxx.com and multiple people can view it and handle the request. How can I configure
                                                                                                              • Introducing Zoho POS for the Kingdom of Saudi Arabia

                                                                                                                Hey everyone, We are excited to kick-start December with a completely personalized edition of POS for retail businesses in Saudi Arabia to help run your operations with ease. It offers four different subscription plans—Free, Standard, Professional, and
                                                                                                              • Whatsapp Connection Status still "Pending" after migration

                                                                                                                Hello, I migrated my WhatsApp API to Zoho from another provider a day ago. So far the connection status is still “Pending”. There is a problem? How long does it usually take?
                                                                                                              • Unveiling Zoho Sites 2.0 - A new dimension in website building

                                                                                                                Dear Zoho Sites Users, We are thrilled to announce the launch of Zoho Sites 2.0 today! This refresh represents a significant step forward in the capabilities of Zoho Sites and is crucial for creating a lasting and positive impact on our customers' businesses.
                                                                                                              • Subform edits don't appear in parent record timeline?

                                                                                                                Is it possible to have subform edits (like add row/delete row) appear in the Timeline for parent records? A user can edit a record, only edit the subform, and it doesn't appear in the timeline. Is there a workaround or way that we can show when a user
                                                                                                              • Script Editor not an option

                                                                                                                I am trying to apply a script to a sheet and Script Editor is not an option. I don't want to go outside Sheets to do this (like Creator) if it can be done inside Sheets.
                                                                                                              • Zoho CRM - Writing Assistant Tone

                                                                                                                Hi Zoho CRM Team, Text in my emails often gets underlined in yellow because I tend to use a more informal tone with my client's, like using "I'm" instead of "I am". Is there some way for me to tell the system that this is my preferred writing tone, so
                                                                                                              • Not able to link email text.

                                                                                                                Kindly check Zoho Sites. I am unable to turn a text into a email link. The save button does not work. Kindly try yourself to see it not responding to save.
                                                                                                              • Adding Multiple Files to a Zoho Vault Entry

                                                                                                                There is a old blog post talking about adding multiple file attachments to one Zoho Vault Secret: https://www.zoho.com/blog/vault/introducing-new-features-in-zoho-vault-powerful-password-sharing-wider-storing.html Is that still possible, I can see how
                                                                                                              • Migrate data from old to new account

                                                                                                                Hy, Have one Old Zoho Notebook Account with Data , want to migrate that whole Data to New Zoho Notebook Account which is in Zoho One . Is that possible ? If Yes then how?
                                                                                                              • Zoho Analytics Regex Support

                                                                                                                When can we expect full regex support in Zoho Analytics SQL such as REGEXP_REPLACE? Sometimes I need to clean the data and using regex functions is the easiest way to achieve this.
                                                                                                              • RTL Support for Webforms in Zoho CRM

                                                                                                                Dear Zoho CRM Support Team, We are writing to request an enhancement to the webform builder functionality within Zoho CRM. Currently, to create a webform in a right-to-left (RTL) language, the entire CRM instance must be set to RTL, which can be inconvenient
                                                                                                              • Add Custom Reports To Dashboard or Home Tab

                                                                                                                Hi there, I think it would be great to be able to add our custom reports to the Home Tab or Dashboards. Thanks! Chad
                                                                                                              • MCP > Creator connection failing with Claude

                                                                                                                I'm trying to get claude to access any of my Zoho Creator apps and it keeps failing. I have enabled all tools for creator and ensured in claude settings that everything is authorised. Here is what claude says : Unfortunately, the error messages I'm receiving
                                                                                                              • Pricing Strategies: #1 Nuances in Pricing

                                                                                                                When Clara first opened her digital printing shop, pricing was simple. She sold handmade greeting cards, planners, business cards, and other physical items at fixed label prices, individually and in bulk. One SKU, one price, one bill, and that's all it
                                                                                                              • [Free Webinar] Learning Table Series – Education Management in Zoho Creator

                                                                                                                Hello Everyone! We’re excited to invite you to another edition of Learning Table Series, where we showcase how Zoho Creator empowers industries with innovative and automated solutions. About the Learning Table Series The Learning Table Series is a free,
                                                                                                              • Next Page