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

                                                                                                                • Data Capture for Historical Activity (Especially One Lead Downloading Variois reports without Overwriting the info)

                                                                                                                  Is there a better way in Zoho CRM to capture and archive a lead’s historical activity—specifically whenever they download reports—so that the data is stored without being overwritten?”
                                                                                                                • Client Script - Updating Field Value in Detail Page of a Lead

                                                                                                                  Hello, I'm trying to use Client Script To enrich some data of the Lead when one of my User fill the "City" field in the detail page of the Lead. This is my Script: log (value); var response = ZDK.Apps.CRM.Functions.execute("getInfoCitta", { "nomeCitta":
                                                                                                                • Auto shapes in Zoho sheet.

                                                                                                                  Does Zoho sheet supports inserting auto shapes (rectangle, circle...). I did not see any option to do so.  If its not supported currently, is there any plans on bring in this features. Any timelines ?
                                                                                                                • How to get the call recording external ID via desk API

                                                                                                                  I have enabled phonbridge integration with Zoom Call. I am trying to access the call recording in Zoom by calling Zoom API. I have built a Desk workflow to trigger on a new call, to call a custom function. when calling the API, the response doesn't contain
                                                                                                                • Can't View Project Names in Mobile App

                                                                                                                  I can't view project names on PO's in the app, nor can I add that as a viewable PDF field in inventory on the computer. I've attached screenshots showing that in the mobile version whether you are on the PO, editing the PO, or viewing the PO line items,
                                                                                                                • Notebook

                                                                                                                  I have purchased the monthly pro subscription of Notebook. But it does not support my XP-Pen to write something in it. So it is not useful to me. Hence I am requesting you to help me to discontinue this subscription.
                                                                                                                • Domain Mapping & Image Publishing Issues on Zoho Sites

                                                                                                                  Hello, I am facing two issues with my Zoho Sites account: 1. Images not visible after publishing. 2. Domain mapping error: "Domain already exists". I am a paid customer. Please connect me with Live Chat Support or Zoho Assist so I can show my issue
                                                                                                                • Prevent duplicate with custom fields?

                                                                                                                  I was wondering something about custom field/custom modules in Zoho Desk. For some reason you can make a custom field mandatory but not unique? For example, if I create a custom module to manage equipment and renewal and make a field serial number no
                                                                                                                • How to Automate Monthly PDF Reports with Filters in Zoho Creator

                                                                                                                  Hi everyone, I’m trying to build an automated monthly reporting process in Zoho Creator and would appreciate suggestions or best practices from anyone who has done something similar. What I’m trying to do: I have a form called New_Customer with fields
                                                                                                                • Feedback: Streamlining Note Management in Zoho Notebook

                                                                                                                  Dear Team/Support, I would like to share some feedback regarding the note management system that could help improve usability and accessibility for users like myself. Notebook 1 (screenshot attached): Currently, the system does not allow selecting and
                                                                                                                • showing Limit exceeded

                                                                                                                  Good afternoon...trust you're good. I've been having issues working with but it's not responding. it's showing Limit exceeded, sorry it seems like too many people are working on the sheet right now please try again later. meanwhile no one is working on
                                                                                                                • Upload API

                                                                                                                  I'm trying to use the Upload API to upload some images and attach them to comments (https://desk.zoho.com/DeskAPIDocument#Uploads#Uploads_Uploadfile) - however I can only ever get a 401 or bad request back. I'm using an OAuth token with the Desk.tickets.ALL
                                                                                                                • Losing description after merging tickets

                                                                                                                  Hello, We merge tickets when they are about the same topic from the same client. It happens sometimes. We recently noticed that after the merger only the description from the master ticket is left in a thread. And the slave-ticket description is erased.
                                                                                                                • update linked contacts when update happens in account

                                                                                                                  Hi, I have a custom field called Licence in the Accounts module. When someone buys a licence, I’d like to update a custom field in the related Contacts. How can I achieve this? I noticed that workflows triggered on Accounts only allow me to update fields
                                                                                                                • Problem Management Module

                                                                                                                  I am looking for a Problem Management module within Zoho Desk. I saw in some training videos that this is available, and some even provided an annual price for it. I want an official confirmation on whether this is indeed available. This is not a particularly
                                                                                                                • Unable to explore desk.zoho.com

                                                                                                                  Greetings, I have an account with zoho which already has a survey subscription. I would like to explore desk.zoho.com, but when I visit it while logged in (https://desk.zoho.com/agent?action=CreatePortal) I just get a blank page. I have tried different
                                                                                                                • Offline support for mobile app

                                                                                                                  Accessing your files and folders from your mobile devices is now quicker and simpler, thanks to the power of offline support. Whether on an Android or iOS device, you can use the Offline function to save files and folders, so you can review them even
                                                                                                                • Zoho Desk KB article embedded on another site.

                                                                                                                  We embed KB articles from Zoho Desk on another site (our application). When opening the article in a new tab, there is no issue, but if we choose lightbox, we are getting an error "To protect your security, help.ourdomain.com will not allow Firefox to
                                                                                                                • Does Attari Messaging app have Bot option and APIB

                                                                                                                  Hi, Does Attari also have Bot and API as we use in WhatsApp??
                                                                                                                • How to add application logo

                                                                                                                  I'm creating an application which i do not want it to show my organization logo so i have changed the setting but i cannot find where to upload/select the logo i wish to use for my application. I have seen something online about using Deluge and writing
                                                                                                                • Details & Limitations of the Free Forever Plan

                                                                                                                  I cannot find any comparison/details about the Free Forever Plan. Can you please publish details of what are its limitations?
                                                                                                                • how to differentiate if whatsapp comes from certain landing page?

                                                                                                                  I create a Zobot in SalesIQ to create a Whatsapp bot to capture the lead. I have 2 landing pages, one is SEO optimized and the other want is optimized for leads comes from Google Ads. I want to know from which landing page this lead came through WhatsApp
                                                                                                                • How to record company set up fees?

                                                                                                                  Hi all, We are starting out our company in Australia and would appreciate any help with setting up Books accounts. We paid an accountant to do company registration, TFN, company constitution, etc. I heard these all can be recorded as Incorporation Costs, which is an intangible asset account, and amortised over 5 years. Is this the correct way to do it under the current Australian tax regulations? How and when exactly should I record the initial entry and each year's amortasation in Books? Generally
                                                                                                                • Show Payment terms in Estimates

                                                                                                                  Hi,  we are trying to set up that estimates automatically relates payment terms for the payment terms we introduced on Edit contact (Field Payment terms).  How can it be done? Our aim is to avoid problems on payment terms introduced and do not need to introduce it manually on each client (for the moment we are introducing this information on Terms and Conditions.  Kind Regards, 
                                                                                                                • When dispatched to crew, assigning lead missing

                                                                                                                  Hello, For the past two or three weeks, whenever an officer assigns Service Appointment to a team, the lead person is missing from the assigned service list. Therefore, we have to reschedule the SA and then the lead person becomes visible in the assigned
                                                                                                                • I want to transfer the project created in this account to another account

                                                                                                                  Dear Sir I want to transfer the project created in one account to another account
                                                                                                                • Custom Bulk Select Button

                                                                                                                  Zoho CRM offers the ability to select multiple records and invoke a Custom Button This functionality is missing from Recruit Currently we can only add buttons in the detail page and list But we cannot select Multiple Records and invoke a function with
                                                                                                                • Power of Automation :: Smart Ticket Management Between Zoho Desk and Projects

                                                                                                                  Hello Everyone, A custom function is a software code that can be used to automate a process and this allows you to automate a notification, call a webhook, or perform logic immediately after a workflow rule is triggered. This feature helps to automate
                                                                                                                • BUG - Google Business Buttons - Add a button to GBP Post

                                                                                                                  I am experiencing an issue with the "Add a button" feature when creating posts for my Google Business Profile (GBP) through Zoho Social. When I schedule or publish a GBP post and include a call-to-action button with a specific URL, the post itself publishes
                                                                                                                • Do you have software like Windows software?

                                                                                                                  We want swadeshi software
                                                                                                                • Trying to export a report to Excel via a deluge script

                                                                                                                  I have this code from other posts but it gives me an error of improper statement, due to missing ; at end of line or incomplete expression. Tried lots of variations to no avail. openUrl(https://creatorapp.zoho.com/<username>/<app name>/XLSX/#Report:<reportname>,"same
                                                                                                                • Need help to create a attach file api

                                                                                                                  https://www.zoho.com/crm/developer/docs/api/v8/upload-attachment.html Please help me to create it... It's not working for while. Do you have some example?
                                                                                                                • Export view via deluge.

                                                                                                                  Hi, Is it possible to export a view (as a spreadsheet) via deluge? I would like to be able to export a view as a spreadsheet when a user clicks a button. Thanks     
                                                                                                                • Possible to generate/download Quote PDF using REST API?

                                                                                                                  See title. Is there any way after a quote has been created to export to a PDF using a specified template and then download it? Seems like something that should be doable. Is this not supported in the API v2.0?
                                                                                                                • Bug in allowing the user to buy out of stock items

                                                                                                                  Hi i want to allow the user to buy out of stock items, according to the commerce documentation if i disable Restrict "Out of stock" purchases it will, but it doesnt work, so i want to know if it had any relation with zoho inventory, and if theres any
                                                                                                                • Replace Lookup fields ID value with their actual name and adding inormation from subforms

                                                                                                                  Hi everyone,  I wanted to see if someone smarter than me has managed to find any solutions to two problems we have. I will explain both below.  To start we are syncing data from Zoho CRM to Zoho Analytics and I will use the Sales Order module when giving
                                                                                                                • Can a Zoho Sites page be embedded into another website (outside Zoho)

                                                                                                                  Hi All, We have a request from a client - they'd like to take one of our information pages created in Zoho Sites and embed it into their own website? I was told through an email with Zoho that this was possible >>Thank you for your patience regarding
                                                                                                                • Bug in allowing the user to buy out of stock items

                                                                                                                  Hi i want to allow the user to buy out of stock items, according to the commerce documentation if i disable Restrict "Out of stock" purchases it will, but it doesnt work, so i want to know if it had any relation with zoho inventory, and if theres any
                                                                                                                • Transition Criteria Appearing on Blueprint Transitions

                                                                                                                  On Monday, Sept. 8th, the Transition criteria started appearing on our Blueprints when users hover over a Transition button. See image. We contacted Zoho support because it's confusing our users (there's really no reason for them to see it), but we haven't
                                                                                                                • Zoho CRM Sales Targets for Individual Salespeople

                                                                                                                  Our organistion has salespeople that are allocated to different regions and have different annual sales targets as a result. I am building an CRM analytics dashboard for the sales team, which will display a target meter for the logged in salesperson.
                                                                                                                • Next Page