Latest

Connecting ZOHO CRM API using Java


===================================================================
Connecting ZOHO CRM  using Java



Copy and paste the following code into Test.java (overwrite the existing code):
import java.io.*;
import java.util.*; import java.net.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; 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; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Test { public static void main(String a[]) { try { // To Fetch Authentication Token String ticket = getAuthenticationToken("ZohoCRM", "ZOHO USERNAME", "ZOHO PASSWORD"); System.out.println(ticket);
//TO FETCH ACCOUNTS Records String targetURL = "https://crm.zoho.com/crm/private/xml/Accounts/getRecords"; PostMethod post = new PostMethod(targetURL); post.setParameter("authtoken", ticket); post.setParameter("scope", "crmapi"); post.setParameter("newFormat", "2"); post.setParameter("selectColumns", "All"); HttpClient httpclient = new HttpClient(); long t1 = System.currentTimeMillis(); int result = httpclient.executeMethod(post); System.out.println("HTTP Response status code: " + result); System.out.println("Time taken to execute :"+ (System.currentTimeMillis() - t1)); // Get response as a string ---------------- String postResp = post.getResponseBodyAsString(); System.out.println("postResp=======>" + postResp); } catch (Exception e) { System.out.println(e.getMessage()); } } /** * @param string * @param username * @param password * @return */ private static String getAuthenticationToken(String name, String username, String password) { String strTicket = ""; String url = "https://accounts.zoho.com/apiauthtoken/nb/create?SCOPE=ZohoCRM/crmapi&EMAIL_ID=" + username + "&PASSWORD=" + password + ""; URL u; try { u = new URL(url); 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("AUTHTOKEN")) { strTicket = strLine.substring(10); } } in.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return strTicket; } }


Note the the above code fetched Accounts records only. To fetch data from other CRM modules change the name in the targetURL. The other CRM modules are :

  1. Accounts
  2. Contacts
  3. Potentials
  4. Leads
  5. Campaigns
  6. Tasks
  7. Cases
  8. Solutions
  9. Products
  10. PriceBooks
  11. Quotes
  12. Vendors
  13. PurchaseOrders
  14. SalesOrders
  15. Invoices
  16. Notes
  17. Calls


 According to the  ZOHO CRM edition the access to CRM modules will be differ.


2 comments:

  1. ZOHO CRM is must for every kind of business nowadays.

    ReplyDelete
  2. This is an absolutely impressive admittance. Today coming from Bing whilst browsing an indistinguishable material. I really had upwards what you were mandatory to go over. Maintain the truly surprising work!

    Engaging Boosted CRM as your Zoho solution provider, you are not exactly getting exceptional service or years of know-how. You get their devotion and drive to hand over & support your solution on date and on-cost.

    ReplyDelete