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.
  4. package com.zoho.crmsdk.api.record;
  5. import java.util.List;

  6. import com.zoho.crm.library.api.response.APIResponse;
  7. import com.zoho.crm.library.common.CommonUtil;
  8. import com.zoho.crm.library.crud.ZCRMField;
  9. import com.zoho.crm.library.crud.ZCRMModule;
  10. import com.zoho.crm.library.crud.ZCRMRecord;
  11. import com.zoho.crm.library.setup.restclient.ZCRMRestClient;

  12. public class setMobilenumber{

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

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

    • 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 ...
    • Configuration - Java SDK

      Setting up the configuration is a system engineering process, for establishing and maintaining the consistency of the application's performance, functional and physical attributes with its requirements, design and operational information throughout ...
    • 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 Name, ...
    • Create Your First Widget

      Using the widgets feature, you can directly embed UI components in a CRM and use the data form a third-party application to perform actions as per requirement. Creation of a Widget Once the Zoho CLI is installed, you can create your own widget. Step ...
    • 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 ...