uploadPhoto Method

uploadPhoto Method

 Purpose

You can use this method to upload photos to Leads or Contacts.

 Request URL

XML Format:

For Leads:
https://crm.zoho.com/crm/private/xml/Leads/uploadPhoto?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream

For Contacts:
https://crm.zoho.com/crm/private/xml/Contacts/uploadPhoto?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream

 Request Parameters

Parameter Data Type Description
authtoken* String Encrypted alphanumeric string to authenticate your Zoho credentials.
scope* String Specify the value as crmapi
id* String Specify unique ID of the record
content* FileInputStream Pass the FileInputStream of the photo

* - Mandatory parameter

Note:

  • The size of each photo should not exceed 2 MB. If the size exceeds 2 MB, you will receive the following error message: "File size should not exceed 2 MB".

 Java Code to Upload Photo to a Lead or Contact

You can run this program in your Java Environment to upload a photo to a lead or a contact.

In the program, you need to specify values for the following:

  • Your Auth Token
  • The ID of the Record
  • The uploadPhoto Request URL in the format mentioned above
  • The File Path i.e the location of the photo
import java.io.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
public class UploadPhoto 
{
      public static void main(String args[])
      {
            try
            {
                  String auth_token = "USER AUTH TOKEN";
                  String auth_scope = "crmapi";
                  String targetURL = "https://crm.zoho.com/crm/private/xml/Leads/uploadPhoto";
                  String recordId = "RECORD ID";
                  String file = "FILE NAME";
                  File f = new File(file);
                  FileInputStream fis = new FileInputStream(f);
                  ByteArrayOutputStream bos = new ByteArrayOutputStream();
                  int c;
                  while ((c = fis.read()) != -1)
                  {
                        bos.write(c);
                  }
                  byte[] fbArray = bos.toByteArray();
                  if(useAuthToken)
                  {
                        targetURL = targetURL + "?authtoken="+ auth_token +"&ampscope="+ auth_scope;
                  }
                  PartSource ps = new ByteArrayPartSource(file,fbArray);
                  PostMethod post =new PostMethod(targetURL);
                  Part[] fields = { new FilePart("content",ps), new StringPart("id", recordId), };
                  post.setRequestEntity(new MultipartRequestEntity(fields,post.getParams()));
                  HttpClient httpclient = new HttpClient();
                  httpclient.executeMethod(post);
                  String postResp = post.getResponseBodyAsString();
                  System.out.println("postResp===========&gt : "+postResp);
            }
            catch(Exception e)
            {
                  e.printStackTrace();
            }
      }
}

 Sample Response

<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/uploadPhoto">
<status>
<code>200</code>
</status>
<success>
<code>4800</code>
<message>Photo uploaded succuessfully</message>
</success>
</response>

 PHP Code to Upload Photo to a Lead or Contact

<?php
$recordId="2000000016885";
$ch=curl_init();
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_VERBOSE,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_URL,"https://crm.zoho.com/crm/private/xml/Leads/uploadPhoto?authtoken=<Your Authtoken>&scope=crmapi");
curl_setopt($ch,CURLOPT_POST,true);
$post=array("id"=>$recordId,"content"=>"@/home/path/to/my/photo.png");
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$response=curl_exec($ch);
echo $response;
?>

    • Related Articles

    • uploadPhoto Method - Comparison

      Purpose To add a photo to a contact or lead. Request URL Version 1.0: https://crm.zoho.com/crm/private/xml/(Leads or Contacts)/uploadPhoto?authtoken=AuthToken&scope=crmapi&id=Record Id&content=File Input Stream Version 2.0: URL: ...
    • deleteRecords Method

      Table of Contents Purpose Request URL Request Parameters Example Purpose You can use this method to delete the selected record (you must specify unique ID of the record) and move to the recycle bin. Note: This method is availablefor all modules. ...
    • downloadPhoto Method

       Purpose You can use this method to download the photos of Leads or Contacts.  Request URL XML Format: For Leads: https://crm.zoho.com/crm/private/xml/Leads/downloadPhoto?authtoken=Auth Token&scope=crmapi&id=RecordID For Contacts: ...
    • searchRecords Method

       Purpose You can use the searchRecords method to get the list of records that meet your search criteria.  Request URL XML Format: https://crm.zoho.com/crm/private/xml/Leads/searchRecords?authtoken=Auth Token&scope=crmapi&criteria=(((Last ...
    • deleteFile Method

      Purpose You can use this method to delete files attached to records. Request URL XML Format: https://crm.zoho.com/crm/private/xml/Leads/deleteFile?authtoken=Auth Token&scope=crmapi&id=Attachment Id JSON Format: ...