uploadPhoto methode
Inhoudsopgave
Doel
U kunt deze methode gebruiken voor het uploaden van foto's naar Leads of Contacts.
URL van het verzoek
XML-indeling:
Voor Leads:
https://crm.zoho.com/crm/private/xml/Leads/uploadPhoto?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream
Voor Contacts:
https://crm.zoho.com/crm/private/xml/Contacts/uploadPhoto?authtoken=Auth Token&scope=crmapi&id=Record Id&content=File Input Stream
Parameters van het verzoek
Parameter | Gegevenstype | Beschrijving |
authtoken* | String | Versleutelde alfanumerieke tekenreeks ter verificatie van uw Zoho inloggegevens. |
scope* | String | Voer als waarde crmapi in |
id* | String | Voer de unieke ID van de record in |
content* | FileInputStream | Voer de FileInputStream van de foto in |
* - Verplichte parameter
Opmerking:
- De foto mag niet groter zijn dan 2 MB. Als het bestand groter is dan 2 MB, ontvangt u de volgende foutmelding: ‘File size should not exceed 2 MB’.
Java-code voor het uploaden van een foto naar een lead of contactpersoon
U kunt dit programma uitvoeren in uw Java-omgeving om een foto naar een lead of een contactpersoon te uploaden.
In het programma moet u de volgende waarden invoeren:
- Uw verificatietoken
- De ID van de record
- De URL van het uploadPhoto verzoek met de bovengenoemde indeling
- Het bestandspad, d.w.z. de locatie van de foto
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();
}
}
}
Voorbeeld 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 voor het uploaden van een foto naar een lead of contactpersoon
<?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;
?>