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
* - 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 +"&scope="+ 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===========> : "+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;
?>