Site Home  »  最新百会CRM API  »  示例

示例

Tags:  


1. Fetch Records from the "Contacts" Module

Programming Language

  • JAVA

Prerequisite

  • JDK 1.6
  • commons-codec-1.3.jar, commons-httpclient-3.0.1.jar and commons-logging-1.1.jar files are available in the CLASSPATH

Code Snippet

import java.io.*;
import java.util.*;
import java.net.*;
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 TestAPI
{
    public static void main(String a[])
    {   
        try   
        {
            /*----------------------------Fetch Ticket from your Zoho CRM Account---------------------------- */
            String ticket = getIAMTicket("ZohoCRM","yourusername","yourpassword");
            String apikey = "xxxxxxxxxxxxxxxxx"; //your API key
            /*----------------------------Fetch Ticket from your Zoho CRM Account ---------------------------- */

            String targetURL = "http://crm.zoho.com/crm/private/xml/Contacts/getRecords";
            String paramname = "content";
            PostMethod post = new PostMethod(targetURL);
            post.setParameter("ticket",ticket);
            post.setParameter("apikey",apikey);
            HttpClient httpclient = new HttpClient();
            PrintWriter myout = null;

            /*-------------------------------------- Execute the http request--------------------------------*/
            try
            {
                long t1 = System.currentTimeMillis();
                int result = httpclient.executeMethod(post);
                System.out.println("HTTP Response status code: " + result);
                System.out.println(">> Time taken " + (System.currentTimeMillis() - t1));
            /*-------------------------------------- Execute the http request--------------------------------*/
               
                /* ---------------------------writing the response to a file--------------------*/
                myout = new PrintWriter(new File("response.xml"));
                myout.print(post.getResponseBodyAsString());
               /* ---------------------------writing the response to a file--------------------*/
               
                /*-----------------------Get response as a string ----------------*/
                String postResp = post.getResponseBodyAsString();
                System.out.println("postResp=======>"+postResp);
                /* ---------------------Get response as a string ----------------------------*/
                 if(postResp.equals("Invalid Ticket Id"))
                 {
                     // generate the ticket id  again and call the API
                 }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }   
            finally
            {
                myout.close();
                post.releaseConnection();
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }   
    }
    /*-------------------------Get Ticket ---------------------------------*/
    public static String getIAMTicket(String serviceName, String loginId, String password)
    {
        String strTicket = null;
        try {

            String iamUrl = "http://accounts.zoho.com/login?servicename="+serviceName+"&FROM_AGENT=true&LOGIN_ID="+loginId+"&PASSWORD="+password;
            URL u = new URL(iamUrl);
            HttpURLConnection c = (HttpURLConnection)u.openConnection();
            InputStream in = c.getInputStream();
            InputStreamReader ir=new InputStreamReader(in);
            BufferedReader br =new BufferedReader(ir);

            String strLine  = null;

            while ((strLine = br.readLine()) != null) {
                if(strLine != null && strLine.startsWith("TICKET")) {
                    strTicket = strLine.substring(7);
                }
            }

            in.close();
        }
        catch (Exception e){
            e.printStackTrace();

        }
        return strTicket;
    }
    /* --------------------Get Ticket----------------------------------*/
}
Download: Soruce Code

2. Fetch Records from the "Contacts" Module

Programming Language

  • PHP

Prerequisite

  • LAMP or WAMP

Code Snippet

<?php
$file = fopen("http://crm.zoho.com/crm/private/xml/Leads/getRecords?ticket=ticket&apikey=apikey", "r") or exit("Unable to open file!");
while(!feof($file))
  {
      $theData=fgets($file);
  }
fclose($file);
echo $theData;
?>


3. Insert products into Invoice

API Method: insertRecords

XML Format: http:// crm.zoho.com/crm/private/xml/Leads/insertRecords?apikey=API Key&ticket=Ticket

XML Data:

<Invoices>
   <row no="1">
       ...all other invoice attributes...
        <FL val="Product Details">
            <product no="1">
                <FL val="Product Id">___your_zoho_productId___</FL>
                <FL val="Product Name">___your_zoho_product_name___</FL>
                <FL val="Quantity">1</FL>
                <FL val="List Price">1.00</FL>
                <FL val="Discount">0</FL>
                <FL val="Total">1.00</FL>
                <FL val="Total After Discount">1.00</FL>
                <FL val="Tax">0</FL>
                <FL val="Net Total">1.00</FL>
            </product>
       </FL>

      ...any other invoice attributes...
    </row>
</Invoices>


4. Create multiple Potentials for Account

API Method: insertRecords

XML Format: http:// crm.zoho.com/crm/private/xml/Leads/insertRecords?apikey=API Key&ticket=Ticket

XML Data:

<Accounts>
<row no="1">
<FL val="ACCOUNTID">Your__Account__ID</FL>
<FL val="Email">test@test.test</FL>
<FL val="boolean flag">TRUE</FL>
<FL val="First contact">01/01/2009</FL>
<FL val="Last Login">05/10/2009</FL>
</row>
</Accounts>
<Potentials>
<row no="1">
<FL val="Potential Name">First Potential</FL>
<FL val="Description">description of the potential</FL>
<FL val="Closing Date">01/04/2009</FL>
<FL val="ACCOUNTID">Your__Account__ID</FL>
<FL val="Email">test@test.test</FL>
<FL val="Stage">"-data-"</FL>
<FL val="boolean flag">TRUE</FL>
<FL val="product">FREE</FL>
<FL val="Date of Birth">01/01/1970</FL>
<FL val="Mailing City">Germany</FL>
</row>
</Potentials>


5. Insert Date Fields

API Method: insertRecords

XML Format: http:// crm.zoho.com/crm/private/xml/Leads/insertRecords?apikey=API Key&ticket=Ticket

XML Data:
<Accounts>
<row no="1">
<FL val="Account Name">TestUser</FL>
<FL val="Email">test@test.test</FL>
<FL val="boolean flag">TRUE</FL>
<FL val="First contact">01/01/2009</FL>
<FL val="Last Login">05/10/2009</FL>
<FL val="Created Time">2009-05-10 14:45:56</FL>
</row>
</Accounts>

Note: Date must be in MM/dd/yyyy format. Whereas Date & Time must be in yyyy-MM-dd HH:mm:ss format.

! This page does not exists




 RSS of this page