Create the first Java Application

Create the first Java Application

Let us quickly walk through the sequence of steps to use Java SDK.


      1. Register a Zoho client as described in the page link.

      2. Create the File hierarchy in your eclipse project as shown below:

      

      3. Create a folder named "resources" under "{yourproject}/Java Resources/src", as shown in the file hierarchy and place the following properties files into 

it.oauth_configuration.properties



zcrm_configuration.properties




Create oauthtoken.properties file as shown in the file hierarchy to store all the token values.This is created under a folder named "path_to_tokens". When the authentication process is complete, the tokens are generated and placed in the properties file automatically as shown here.



      4. Implement Oauth persistence through ZohoOAuthFilePersistence by providing the relative path of the oauth_tokens.properties file, discussed in the previous step with oauth_configuration.properties.

      5. Get the access token and refresh token by executing the InitOauth.java created under the package com.zoho.crmsdk.oauth_configuration. Use the following java code in your InitOauth.java.
(Please paste the grant token value that is obtained during the authentication process, in the string literal mentioned.)

Refer here to generate the grant token.

  1. package com.zoho.crmsdk.oauth_configuration;

  2. import com.zoho.crm.library.setup.restclient.ZCRMRestClient;
  3. import com.zoho.oauth.client.ZohoOAuthClient;
  4. import com.zoho.oauth.contract.ZohoOAuthTokens;

  5. public class InitOauth {
  6.     public static void main(String[] args) throws Exception {
  7.         generateToken();
  8.     }
  9.     public static void generateToken() throws Exception {
  10.         ZCRMRestClient.initialize();
  11.         ZohoOAuthClient cli = ZohoOAuthClient.getInstance();
  12.         String grantToken = "1000.d995c249da11cb5fa3b3c2fc40bd6ba2.e0fb62255485e425fca800e7030d60e7";
  13.         ZohoOAuthTokens tokens = cli.generateAccessToken(grantToken);
  14.         System.out.println(">>>> grantToken" + grantToken + " >>>> accessToken : " + tokens.getAccessToken()+" >>>>> ref token :"+tokens.getRefreshToken());
  15.     }
  16. }

Now it is the high time to create your java resource file that contains the application logic. The following simple java program:
  1. Sets the mobile number of a particular lead in your Zoho CRM's Leads record.
  2. Retrieves the mobile number from the lead record and generates API response in the console.
To do this,
  1. Create a package called com.zoho.crmsdk.api.record under src folder of your project.
  2. Add a file called setMobilenumber.java into it.
  3. Copy the following source code into the above java file.

  1. package com.zoho.crmsdk.api.record;
  2. import java.util.List;

  3. import com.zoho.crm.library.api.response.APIResponse;
  4. import com.zoho.crm.library.common.CommonUtil;
  5. import com.zoho.crm.library.crud.ZCRMField;
  6. import com.zoho.crm.library.crud.ZCRMModule;
  7. import com.zoho.crm.library.crud.ZCRMRecord;
  8. import com.zoho.crm.library.setup.restclient.ZCRMRestClient;

  9. public class setMobilenumber{

  10.      public static void main(String[] args) throws Exception {
  11.         // TODO Auto-generated method stub
  12.         ZCRMRestClient.initialize();
  13.         System.out.println("======== set Mobile Number ========");
  14.         ZCRMRecord record = ZCRMRecord.getInstance("Leads", 2883756000000459006l);
  15.         record.setFieldValue("Mobile", "9894049545");
  16.         record.update();
  17.         System.out.println("======== Get Mobile Number ========");
  18.             record.getFieldValue("Mobile");
  19.         APIResponse response= record.update();
  20.     response.getData();
  21.         }
  22. }

Upon execution, the following response is generated in the Java IDE's console. The Status_Code 200 shows the successful execution of your application. Refer the table to know the set of status codes and their respective descriptions for generating responses.


API Response





    • Related Articles

    • Register your application - Java SDK

      All the Zoho CRM APIs are authenticated with OAuth2 standards, so it is mandatory to register and authenticate your client app with Zoho. To register: Go to the site: accounts.zoho.com/developerconsole Click Add Client ID.  Enter the Client ...
    • Java SDK - Overview

      Java SDK offers a way to create client java applications that can be integrated with Zoho CRM. This SDK makes the access and use of necessary CRM APIs with ease. In other words, it serves as a wrapper for the REST APIs, making it easier to use the ...
    • Release Notes - Java SDK

      ZCRMSDK -VERSION 1.0.6  Downloadable JAR file  You can download the jar file for the version1.0.6 of Java SDKs at the end of this page.  Install command - Maven:(in pom.xml)  <repositories>        <repository>              ...
    • Responses & Exceptions - Java SDK

      APIResponse, BulkAPIResponse and FileAPIResponse are the wrapper objects for Zoho CRM APIs’ responses. All API calling methods would return one of these three objects. A method-seeking entity would return APIResponse object, whereas a method-seeking ...
    • Persistence - Java SDK

      Persistent classes in an application implement the entities of the business problem. In Java SDK, two default persistence classes with their implementations are provided. On the other hand, if a developer wants his specific implementation, he can ...