Voorbeelden

    Versie 1.0 van de Zoho CRM API's is in de End-of-Life-fase. Deze zal op 31 december 2018 worden afgeschreven. Maak kennis met de nieuwe en verbeterde API 2.0.

    Voorbeelden

     1. Records ophalen uit de 'Leads’-module

     Programmeertaal

    • JAVA

     Vereiste

     Codefragment

    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.*;

    public class GetRecords
    {
        public static void main(String a[])
        {   
            try   
            {      
               String authtoken = "AUTHTOKEN";
               String targetURL = "https://crm.zoho.com/crm/private/xml/Leads/getRecords";
               PostMethod post = new PostMethod(targetURL);
               post.setParameter("authtoken",authtoken);
               post.setParameter("scope","crmapi");
               HttpClient httpclient = new HttpClient();
               httpclient.executeMethod(post);
               String postResp = post.getResponseBodyAsString();
               System.out.println("The Response from the server : "+postResp);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }   
        }
    }

     2. Records ophalen uit de 'Leads’-module

     Programmeertaal

    • PHP

     Vereiste

    • LAMP of WAMP

     Codefragment

    <?php

                  header("Content-type: application/xml");
                  $token="AUTHTOKEN";
                  $url = "https://crm.zoho.com/crm/private/xml/Leads/getRecords";
                  $param= "authtoken=".$token."&scope=crmapi";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL, $url);
                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                  curl_setopt($ch, CURLOPT_POST, 1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
                  $result = curl_exec($ch);
                  curl_close($ch);
                  echo $result;
                  return $result;

    ?>

     3. Records ophalen uit de 'Leads’-module

     Programmeertaal

    • Python

     Vereiste

    • Python 2.7.3

     Codefragment

    import urllib
    import urllib2
    module_name = 'Leads'
    authtoken = 'Your authtoken'
    params = {'authtoken':authtoken,'scope':'crmapi'}
    final_URL = "https://crm.zoho.com/crm/private/xml/"+module_name+"/getRecords"
    data = urllib.urlencode(params)
    request = urllib2.Request(final_URL,data)
    response = urllib2.urlopen(request)
    xml_response = response.read()
    print xml_response

     4. API-voorbeeld in C#

     Programmeertaal

    • C#

     Vereiste

    • C#

     Codefragment

    using System;
    using System.Net;
    using System.IO;
    using System.Web;
    using System.Text;
    using System.Net.Security;
    public class ZohoCRMAPI
    {
    public static string zohocrmurl = "https://crm.zoho.com/crm/private/xml/";
    public static void Main (string[] args)
    {
    string result = APIMethod("Leads","getRecords","508020000000332001");//Change the id,method name, and module name here
    Console.Write(result);
    }
    public static String APIMethod(string modulename,string methodname,string recordId)
    {
    string uri = zohocrmurl + modulename + "/"+methodname+"?";
    /* Append your parameters here */
    string postContent = "scope=crmapi";
    postContent = postContent + "&authtoken=0ac32dc177c4918eca902fd290a92f4a";//Give your authtoken
    if (methodname.Equals("insertRecords") || methodname.Equals("updateRecords"))
    {
    postContent = postContent + "&xmlData="+ HttpUtility.UrlEncode("Your CompanyHannahSmithtesting@testing.com");
    }
    if (methodname.Equals("updateRecords") || methodname.Equals("deleteRecords") || methodname.Equals("getRecordById"))
    {
    postContent = postContent + "&id="+recordId;
    }
    string result = AccessCRM(uri, postContent);
    return result;
    }
    public static string AccessCRM(string url, string postcontent)
    {
    WebRequest request = WebRequest.Create(url);
    request.Method = "POST";
    byte[] byteArray = Encoding.UTF8.GetBytes(postcontent);
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = byteArray.Length;
    Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();
    WebResponse response = request.GetResponse();
    dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();
    reader.Close();
    dataStream.Close();
    response.Close();
    return responseFromServer;
    }
    }

     5. Producten toevoegen aan factuur

    API-methode: insertRecords

    XML-indeling:
    https://crm.zoho.com/crm/private/xml/Invoices/insertRecords?authtoken=Auth Token&scope=crmapi

    XML-gegevens:

    <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>

     6. Deal aanmaken met een bestaand account

    API-methode: insertRecords

    XML-indeling:
    https://crm.zoho.com/crm/private/xml/Leads/insertRecords?authtoken=Auth Token&scope=crmapi

    XML-gegevens:

    <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>

     7. Datumvelden invoegen

    API-methode: insertRecords

    XML-indeling:
    https://crm.zoho.com/crm/private/xml/Accounts/insertRecords?authtoken=Auth Token&scope=crmapi

    XML-gegevens:

    <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>
    </row>
    </Accounts>

    Opmerking:

    De datumweergave dient als volgt te zijn: mm/dd/jjjj. De weergave van datum & tijd is als volgt ingedeeld: jjjjj-mm-dd uu:mm:ss.
     

     8. Producten toevoegen aan factuur

    API-methode: insertRecords

    XML-indeling:
    https://crm.zoho.com/crm/private/xml/Leads/insertRecords?
    authtoken=Auth Token&scope=crmapi

    XML-gegevens:

    <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>

     9. Verificatietoken genereren met PHP

    <?php
    $username = "testUsername";
    $password = "testPassword";
    $param = "SCOPE=ZohoCRM/crmapi&EMAIL_ID=".$username."&PASSWORD=".$password;
    $ch = curl_init("https://accounts.zoho.com/apiauthtoken/nb/create");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
    $result = curl_exec($ch);
    /*Dit gedeelte van de onderstaande code scheidt het verificatietoken van het resultaat.
    Verwijder dit gedeelte als u enkel het resultaat nodig hebt*/
    $anArray = explode("\n",$result);
    $authToken = explode("=",$anArray['2']);
    $cmp = strcmp($authToken['0'],"AUTHTOKEN");
    echo $anArray['2'].""; if ($cmp == 0)
    {
    echo "Created Authtoken is : ".$authToken['1'];
    return $authToken['1'];
    }
    curl_close($ch);
    ?>

     10. Prijs van een product bewerken met Python

    import urllib
    import urllib2
    # U moet de ID van de prijslijst en de product-ID hebben wanneer u deze API gebruikt.
    authtoken = 'Your authtoken'
    pricebook_id = '508020142132343432'
    product_id = '508020014316189251'
    list_price = '900'
    params = {'authtoken':authtoken,'scope':'crmapi','id':pricebook_id,'xmlData':''+product_id+''
    +list_price+'','relatedModule':'Products'}
    final_URL = "https://crm.zoho.com/crm/private/xml/PriceBooks/updateRelatedRecords"
    data = urllib.urlencode(params)
    request = urllib2.Request(final_URL,data)
    response = urllib2.urlopen(request)
    xml_response = response.read()
    print xml_response

    Share this post : FacebookTwitter

    Still can't find what you're looking for?

    Write to us: support@zohocrm.com