Create the first Java Application
Let us quickly walk through the sequence of steps to use Java SDK.
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.
- package com.zoho.crmsdk.oauth_configuration;
- import com.zoho.crm.library.setup.restclient.ZCRMRestClient;
- import com.zoho.oauth.client.ZohoOAuthClient;
- import com.zoho.oauth.contract.ZohoOAuthTokens;
- public class InitOauth {
- public static void main(String[] args) throws Exception {
- generateToken();
- }
- public static void generateToken() throws Exception {
- ZCRMRestClient.initialize();
- ZohoOAuthClient cli = ZohoOAuthClient.getInstance();
- String grantToken = "1000.d995c249da11cb5fa3b3c2fc40bd6ba2.e0fb62255485e425fca800e7030d60e7";
- ZohoOAuthTokens tokens = cli.generateAccessToken(grantToken);
-
System.out.println(">>>> grantToken" + grantToken + "
>>>> accessToken : " + tokens.getAccessToken()+"
>>>>> ref token :"+tokens.getRefreshToken());
- }
- }
Now
it is the high time to create your java resource file that contains the
application logic. The following simple java program:
- Sets the mobile number of a particular lead in your Zoho CRM's Leads record.
- Retrieves the mobile number from the lead record and generates API response in the console.
To do this,
- Create a package called com.zoho.crmsdk.api.record under src folder of your project.
- Add a file called setMobilenumber.java into it.
- Copy the following source code into the above java file.
- package com.zoho.crmsdk.api.record;
- import java.util.List;
- import com.zoho.crm.library.api.response.APIResponse;
- import com.zoho.crm.library.common.CommonUtil;
- import com.zoho.crm.library.crud.ZCRMField;
- import com.zoho.crm.library.crud.ZCRMModule;
- import com.zoho.crm.library.crud.ZCRMRecord;
- import com.zoho.crm.library.setup.restclient.ZCRMRestClient;
- public class setMobilenumber{
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- ZCRMRestClient.initialize();
- System.out.println("======== set Mobile Number ========");
- ZCRMRecord record = ZCRMRecord.getInstance("Leads", 2883756000000459006l);
- record.setFieldValue("Mobile", "9894049545");
- record.update();
- System.out.println("======== Get Mobile Number ========");
- record.getFieldValue("Mobile");
- APIResponse response= record.update();
- response.getData();
- }
- }
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 ...