uploadPhoto Method

  1. Purpose
  2. Request URL
  3. Request Parameters
  4. Java Code to Upload Photo for a Candidate or Contact
  5. Sample Response
  6. PHP Code to Upload a Photo
     

Purpose

You can use this method to upload photos for Candidates or Contacts.

Request URL

XML Format:

For Candidates:
https://recruit.zoho.com/recruit/private/xml/Candidates/uploadPhoto?authtoken=Auth Token&scope=recruitapi&id=Record Id&content=File Input Stream&version=2

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

Request Parameters

ParameterData TypeDescription
authtoken*StringEncrypted alphanumeric string to authenticate your Zoho credentials.
scope*StringSpecify the value as recruitapi.
id*StringSpecify the unique ID of the record.
content*FileInputStreamPass the FileInputStream of the photo.
version*IntegerUse version=2: This will fetch responses based on the latest API implementation.

* - 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 for a Candidate or Contact

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

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

  1. Your Auth Token
  2. The ID of the Record
  3. The uploadPhoto Request URL in the format mentioned above
  4. 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 UploadFile 
{
      public static void main(String a[])
      {
            try
            {
                  String auth_token = "USER AUTH TOKEN"; 
                  String auth_scope = "recruitapi";
                  String targetURL = "https://recruit.zoho.com/recruit/private/xml/Candidates/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();
                  targetURL = targetURL + "?authtoken="+ auth_token +"&scope="+ auth_scope+"&version=2";
                  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="/recruit/private/xml/Candidates/uploadPhoto">
<status>
<code>200</code>
</status>
<success>
<code>4800</code>
<message>Photo uploaded successfully</message>
</success>
</response>

PHP Code to Upload Photo for a Candidate or Contact (for PHP versions 5.5 or higher)

<?php
$recordId="RECORD ID";
$ch=curl_init();
$cFile = new CURLFile('/home/path/to/my/photo.png','image/png',")

curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_VERBOSE,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_URL,"https://recruit.zoho.com/recruit/private/xml/Candidates/uploadPhoto?authtoken=<Your Authtoken>&scope=recruitapi&version=2");
curl_setopt($ch,CURLOPT_POST,true);
$post=array("id"=>$recordId,"content"=>$cFile);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$response=curl_exec($ch);
echo $response;
?>