ZohoCRM.modules.all (or) ZohoCRM.modules.{module_name}.{operation_type} (and) ZohoCRM.modules.attachments.all |
public void getAllAttachmentsDetails() throws Exception { ZCRMRecord record=ZCRMRecord.getInstance("Leads",3719520000000659047L); int page=1; int per_page=200; BulkAPIResponse responseIn=record.getAllAttachmentsDetails(page, per_page,null); List <ZCRMAttachment> attchments=(List<ZCRMAttachment>)responseIn.getData(); if(attchments!=null) { for(ZCRMAttachment attchmentIns : attchments) { System.out.println(attchmentIns.getId()); System.out.println(attchmentIns.getFileName()); System.out.println(attchmentIns.getFileType()); System.out.println(attchmentIns.getSize()); ZCRMRecord parentRecord1=attchmentIns.getParentRecord(); System.out.println(parentRecord1.getEntityId()); ZCRMUser createdBy1=attchmentIns.getCreatedBy(); System.out.println(createdBy1.getId()); System.out.println(createdBy1.getFullName()); ZCRMUser modifiedBy1=attchmentIns.getModifiedBy(); System.out.println(modifiedBy1.getId()); System.out.println(modifiedBy1.getFullName()); ZCRMUser owner1=attchmentIns.getOwner(); System.out.println(owner1.getId()); System.out.println(owner1.getFullName()); System.out.println(attchmentIns.getCreatedTime()); System.out.println(attchmentIns.getModifiedTime()); } } } |
public void getAllAttachmentDetails() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpget = new HttpGet("{{api-domain}}/crm/v2/Leads/3719520000000659047/attachments"); httpget.addHeader("Authorization", "Zoho-oauthtoken 1000.9XXX.6XXX"); 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()); } } |
{ "data": [ { "Owner": { "name": "Patricia Boyle", "id": "3719520000000191015", "email": "patricia.boyle@zohocorp.com" }, "Modified_Time": "2020-08-12T10:28:07+05:30", "File_Name": "testimg.jpg", "Created_Time": "2020-08-12T10:28:07+05:30", "Size": "120335", "Parent_Id": { "name": "Johnson Charles", "id": "3719520000000659047" }, "$editable": true, "$file_id": "8urshba63343dcc7b41418d74eeca1d4c323e", "$type": "Attachment", "$se_module": "Leads", "Modified_By": { "name": "Patricia Boyle", "id": "3719520000000191015", "email": "patricia.boyle@zohocorp.com" }, "$state": "save", "id": "3719520000000981001", "Created_By": { "name": "Patricia Boyle", "id": "3719520000000191015", "email": "patricia.boyle@zohocorp.com" }, "$link_url": null } ], "info": { "per_page": 200, "count": 2, "page": 1, "more_records": false } } |
public void uploadAttachment() throws Exception{ ZCRMRecord record=ZCRMRecord.getInstance("Leads",3719520000000659047L); APIResponse responseIn=record.uploadAttachment("/Users/srivathsan-8829/Downloads/record.txt"); 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
Uploading an attachment to a record in Java without Java SDK can be a tedious task. As shown below, the request needs to be multipart request.
public void uploadAttachments() throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); File file = new File("/Users/srivathsan-8829/Downloads/record.txt"); FileBody filebody = new FileBody(file, ContentType.DEFAULT_BINARY); MultipartEntityBuilder entitybuilder = MultipartEntityBuilder.create(); entitybuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); HttpEntity mutiPartHttpEntity = entitybuilder.build(); RequestBuilder reqbuilder = RequestBuilder.post("{{api-domain}}/crm/v2/Leads/3719520000000659047/attachments"); reqbuilder.setEntity(mutiPartHttpEntity); reqbuilder.addHeader("Authorization", "Zoho-oauthtoken 1000.9XXX.6XXX"); HttpUriRequest multipartRequest = reqbuilder.build(); HttpResponse httpresponse = httpclient.execute(multipartRequest); System.out.println(EntityUtils.toString(httpresponse.getEntity())); System.out.println(httpresponse.getStatusLine()); } |
{ "data": [ { "code": "SUCCESS", "details": { "Modified_Time": "2020-08-12T10:28:07+05:30", "Modified_By": { "name": "Patricia Boyle", "id": "3719520000000191015" }, "Created_Time": "2020-08-12T10:28:07+05:30", "id": "3719520000000981001", "Created_By": { "name": "Patricia Boyle", "id": "3719520000000191015" } }, "message": "attachment uploaded successfully", "status": "success" } ] } |
Writer is a powerful online word processor, designed for collaborative work.