Examples

Examples

1. Fetch Records from the "Leads" Module

Programming Language
  1. JAVA
Prerequisite
  1. JDK 1.6
  2. commons-httpclient-3.1.jar 
Code Snippet
  1. import org.apache.commons.httpclient.*;
  2. import org.apache.commons.httpclient.methods.*;

  3. public class GetRecords
  4. {
  5.     public static void main(String a[])
  6.     {   
  7.         try   
  8.         {      
  9.            String authtoken = "AUTHTOKEN";
  10.            String targetURL = "https://<APPDOMAIN>/crm/private/xml/Leads/getRecords";
  11.            PostMethod post = new PostMethod(targetURL);
  12.            post.setRequestHeader("Authorization",authtoken);
  13.            post.setParameter("scope","crmapi");
  14.            HttpClient httpclient = new HttpClient();
  15.            httpclient.executeMethod(post);
  16.            String postResp = post.getResponseBodyAsString();
  17.            System.out.println("The Response from the server : "+postResp);
  18.         }
  19.         catch(Exception e)
  20.         {
  21.             e.printStackTrace();
  22.         }   
  23.     }
  24. }
 

2. Fetch Records from the "Leads" Module

Programming Language
  1. PHP
Prerequisite
  1. LAMP or WAMP
Code Snippet
  1. <?php

  2.               header("Content-type: application/xml");
  3.               $token="AUTHTOKEN";
  4.               $url = "https://<APPDOMAIN>/crm/private/xml/Leads/getRecords";
  5.               $param= "authtoken=".$token."&scope=crmapi";
  6.               $ch = curl_init();
  7.               curl_setopt($ch, CURLOPT_URL, $url);
  8.               curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  9.               curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  10.               curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  11.               curl_setopt($ch, CURLOPT_POST, 1);
  12.               curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  13.               $result = curl_exec($ch);
  14.               curl_close($ch);
  15.               echo $result;
  16.               return $result;

  17. ?>
 

3. Fetch Records from the "Leads" Module

Programming Language
  1. Python
Prerequisite
  1. Python 2.7.3
Code Snippet
  1. import urllib
  2. import urllib2
  3. module_name = 'Leads'
  4. authtoken = 'Your authtoken'
  5. params = {'authtoken':authtoken,'scope':'crmapi'}
  6. final_URL = "https://<APPDOMAIN>/crm/private/xml/"+module_name+"/getRecords"
  7. data = urllib.urlencode(params)
  8. request = urllib2.Request(final_URL,data)
  9. response = urllib2.urlopen(request)
  10. xml_response = response.read()
  11. print xml_response
 

4. API Example in C#

Programming Language
  1. C#
Prerequisite
  1. C#
Code Snippet
  1. using System;
  2. using System.Net;
  3. using System.IO;
  4. using System.Web;
  5. using System.Text;
  6. using System.Net.Security;
  7. public class ZohoCRMAPI
  8. {
  9. public static string zohocrmurl = "https://<APPDOMAIN>/crm/private/xml/";
  10. public static void Main (string[] args)
  11. {
  12. string result = APIMethod("Leads","getRecords","508020000000332001");//Change the id,method name, and module name here
  13. Console.Write(result);
  14. }
  15. public static String APIMethod(string modulename,string methodname,string recordId)
  16. {
  17. string uri = zohocrmurl + modulename + "/"+methodname+"?";
  18. /* Append your parameters here */
  19. string postContent = "scope=crmapi";
  20. postContent = postContent + "&authtoken=0ac32dc177c4918eca902fd290a92f4a";//Give your authtoken
  21. if (methodname.Equals("insertRecords") || methodname.Equals("updateRecords"))
  22. {
  23. postContent = postContent + "&xmlData="+ HttpUtility.UrlEncode("Your CompanyHannahSmithtesting@testing.com");
  24. }
  25. if (methodname.Equals("updateRecords") || methodname.Equals("deleteRecords") || methodname.Equals("getRecordById"))
  26. {
  27. postContent = postContent + "&id="+recordId;
  28. }
  29. string result = AccessCRM(uri, postContent);
  30. return result;
  31. }
  32. public static string AccessCRM(string url, string postcontent)
  33. {
  34. WebRequest request = WebRequest.Create(url);
  35. request.Method = "POST";
  36. byte[] byteArray = Encoding.UTF8.GetBytes(postcontent);
  37. request.ContentType = "application/x-www-form-urlencoded";
  38. request.ContentLength = byteArray.Length;
  39. Stream dataStream = request.GetRequestStream();
  40. dataStream.Write(byteArray, 0, byteArray.Length);
  41. dataStream.Close();
  42. WebResponse response = request.GetResponse();
  43. dataStream = response.GetResponseStream();
  44. StreamReader reader = new StreamReader(dataStream);
  45. string responseFromServer = reader.ReadToEnd();
  46. reader.Close();
  47. dataStream.Close();
  48. response.Close();
  49. return responseFromServer;
  50. }
  51. }
 

5. Insert Products into Invoice

API Method: insertRecords

XML Format:
  1. https://<APPDOMAIN>/crm/private/xml/Invoices/insertRecords?authtoken=Auth Token&scope=crmapi

XML Data:
  1. <Invoices>
  2.    <row no="1">
  3.        ...all other invoice attributes...
  4.         <FL val="Product Details">
  5.             <product no="1">
  6.                 <FL val="Product Id">___your_zoho_productId___</FL>
  7.                 <FL val="Product Name">___your_zoho_product_name___</FL>
  8.                 <FL val="Quantity">1</FL>
  9.                 <FL val="List Price">1.00</FL>
  10.                 <FL val="Discount">0</FL>
  11.                 <FL val="Total">1.00</FL>
  12.                 <FL val="Total After Discount">1.00</FL>
  13.                 <FL val="Tax">0</FL>
  14.                 <FL val="Net Total">1.00</FL>
  15.             </product>
  16.        </FL>
  17.       ...any other invoice attributes...
  18.     </row>
  19. </Invoices>
 

6. Creating Potential with an existing Account

API Method: insertRecords
XML Format:
  1. https://<APPDOMAIN>/crm/private/xml/Leads/insertRecords?authtoken=Auth Token&scope=crmapi
XML Data:
  1. <Potentials>
  2. <row no="1">
  3. <FL val="Potential Name">First Potential</FL>
  4. <FL val="Description">description of the potential</FL>
  5. <FL val="Closing Date"> 01/04/2009 </FL>
  6. <FL val=" ACCOUNTID" >Your__Account__ID</FL>
  7. <FL val="Email">test@test.test</FL>
  8. <FL val="Stage">"-data-"</FL>
  9. <FL val="boolean flag">TRUE</FL>
  10. <FL val="product">FREE</FL>
  11. <FL val="Date of Birth"> 01/01/1970</FL>
  12. <FL val="Mailing City">Germany</FL>
  13. </row>
  14. </Potentials>
 

7. Insert Date Fields

API Method: insertRecords
XML Format:
  1. https://<APPDOMAIN>/crm/private/xml/Accounts/insertRecords?authtoken=Auth Token&scope=crmapi
XML Data:
  1. <Accounts>
  2. <row no="1">
  3. <FL val="Account Name">TestUser</FL>
  4. <FL val="Email">test@test.test</FL>
  5. <FL val="boolean flag">TRUE</FL>
  6. <FL val="First contact">01/01/2009</FL>
  7. <FL val="Last Login">05/10/2009</FL>
  8. <FL val="Created Time">2009-05-10 14:45:56</FL>
  9. </row>
  10. </Accounts>

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

8. Insert Products into Invoice

API Method: insertRecords
XML Format:
  1. https://<APPDOMAIN>/crm/private/xml/Leads/insertRecords?authtoken=Auth Token&scope=crmapi
XML Data:
  1. <Invoices>
  2. <row no="1">
  3. ...all other invoice attributes...
  4. <FL val="Product Details">
  5. <product no="1">
  6. <FL val="Product Id">___your_zoho_productId___</FL>
  7. <FL val="Product Name">___your_zoho_product_name___</FL>
  8. <FL val="Quantity">1</FL>
  9. <FL val="List Price">1.00</FL>
  10. <FL val="Discount">0</FL>
  11. <FL val="Total">1.00</FL>
  12. <FL val="Total After Discount">1.00</FL>
  13. <FL val="Tax">0</FL>
  14. <FL val="Net Total">1.00</FL>
  15. </product>
  16. </FL> ...any other invoice attributes...
  17. </row>
  18. </Invoices>
 

9. Generate Authentication Token using PHP

  1. <?php
  2. $username = "testUsername";
  3. $password = "testPassword";
  4. $param = "SCOPE=ZohoCRM/crmapi&EMAIL_ID=".$username."&PASSWORD=".$password;
  5. $ch = curl_init("https://accounts.zoho.com/apiauthtoken/nb/create");
  6. curl_setopt($ch, CURLOPT_POST, true);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  8. curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  9. $result = curl_exec($ch);
  10. /*This part of the code below will separate the Authtoken from the result.
  11. Remove this part if you just need only the result*/
  12. $anArray = explode("\n",$result);
  13. $authToken = explode("=",$anArray['2']);
  14. $cmp = strcmp($authToken['0'],"AUTHTOKEN");
  15. echo $anArray['2'].""; if ($cmp == 0)
  16. {
  17. echo "Created Authtoken is : ".$authToken['1'];
  18. return $authToken['1'];
  19. }
  20. curl_close($ch);
  21. ?>
 

10. To Update List Price of a Product using Python

  1. import urllib
  2. import urllib2
  3. #You should have the price book id and product id, for using this API.
  4. authtoken = 'Your authtoken'
  5. pricebook_id = '508020142132343432'
  6. product_id = '508020014316189251'
  7. list_price = '900'
  8. params = {'authtoken':authtoken,'scope':'crmapi','id':pricebook_id,'xmlData':''+product_id+''
  9. +list_price+'','relatedModule':'Products'}
  10. final_URL = "https://<APPDOMAIN>/crm/private/xml/PriceBooks/updateRelatedRecords"
  11. data = urllib.urlencode(params)
  12. request = urllib2.Request(final_URL,data)
  13. response = urllib2.urlopen(request)
  14. xml_response = response.read()
  15. print xml_response

    Zoho CRM Training Programs

    Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

    Zoho CRM Training
      Redefine the way you work
      with Zoho Workplace

        Zoho DataPrep Personalized Demo

        If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

        Zoho CRM Training

          Create, share, and deliver

          beautiful slides from anywhere.

          Get Started Now


            Zoho Sign now offers specialized one-on-one training for both administrators and developers.

            BOOK A SESSION








                                    You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                        Manage your brands on social media

                                          Zoho Desk Resources

                                          • Desk Community Learning Series


                                          • Digest


                                          • Functions


                                          • Meetups


                                          • Kbase


                                          • Resources


                                          • Glossary


                                          • Desk Marketplace


                                          • MVP Corner


                                          • Word of the Day


                                            Zoho Marketing Automation

                                              Zoho Sheet Resources

                                               

                                                  Zoho Forms Resources


                                                    Secure your business
                                                    communication with Zoho Mail


                                                    Mail on the move with
                                                    Zoho Mail mobile application

                                                      Stay on top of your schedule
                                                      at all times


                                                      Carry your calendar with you
                                                      Anytime, anywhere




                                                            Zoho Sign Resources

                                                              Sign, Paperless!

                                                              Sign and send business documents on the go!

                                                              Get Started Now




                                                                      Zoho TeamInbox Resources



                                                                              Zoho DataPrep Resources



                                                                                Zoho DataPrep Demo

                                                                                Get a personalized demo or POC

                                                                                REGISTER NOW


                                                                                  Design. Discuss. Deliver.

                                                                                  Create visually engaging stories with Zoho Show.

                                                                                  Get Started Now









                                                                                                      • Related Articles

                                                                                                      • Map Manipulations - Put Operation

                                                                                                        This guide will help you with the following: Overview Syntax Examples Overview The put deluge task inserts a specified key-value pair in a pre-defined map variable. Syntax <map_variable>.put(<key>, <value>); This task can be used in the following ...
                                                                                                      • XML Manipulation - executeXpath

                                                                                                        This guide will help you with the following: Overview Syntax Return Type Examples Overview The executeXpath() function takes XML/JSON formatted text and XPath as arguments, and returns the values of the desired node from the text. Return Type TEXT ...
                                                                                                      • Number Functions - 1

                                                                                                        This guide will help you with the following: abs sin asin sinh asinh cos acos cosh acosh tan atan tanh atanh atan2 average ceil exp abs The abs() function takes a number as an argument, and returns the absolute value of that number, i.e., the number ...
                                                                                                      • Date-time functions - 2

                                                                                                        This guide will help you with the functions day days360 edate eomonth getDay getDayOfYear getHour getMinutes getMonth getSeconds getWeekOfYear getYear day The day() function takes a dateTimeValue as an argument, and returns the date value from it. ...
                                                                                                      • Date-time functions - 3

                                                                                                        This guide will help you with the following: 1. hour 2. isDate 3. minutes 4. month 5. now 6. second 7. subDay 8. subHour 9. subMinutes 10. subMonth 11. subSeconds 12. subWeek 13. subYear hour The hour function takes a date-time or time value and ...
                                                                                                        Wherever you are is as good as
                                                                                                        your workplace

                                                                                                          Resources

                                                                                                          Videos

                                                                                                          Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                          eBooks

                                                                                                          Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                          Webinars

                                                                                                          Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                          CRM Tips

                                                                                                          Make the most of Zoho CRM with these useful tips.



                                                                                                            Zoho Show Resources