Configuration
Before you get started with creating your Java application, you need to register your client and authenticate the app with Zoho.
Mandatory Keys | Optional Keys |
---|---|
user | logger |
environment | store |
token | SDKConfig |
requestProxy | |
resourcePath |
Follow the below steps to configure the SDK.
Create an instance of the Logger Class to log exception and API information.
/* * Create an instance of Logger Class that takes two parameters * level -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed. * filePath -> Absolute file path, where messages need to be logged. */ Logger logger = new Logger.Builder() .level(Levels.INFO) .filePath("/Users/user_name/Documents/java_sdk_log.log") .build();
Create an instance of UserSignature that identifies the current user.
//Create an UserSignature instance that takes user Email as parameter UserSignature user = new UserSignature("abc@zoho.com");
Configure the API environment which decides the domain and the URL to make API calls.
/* * Configure the environment * which is of the pattern Domain.Environment * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter * Available Environments: PRODUCTION, DEVELOPER, SANDBOX */ Environment environment = USDataCenter.PRODUCTION;
Create an instance of OAuthToken with the information that you get after registering your Zoho client.
/* * Create a Token instance that requires the following * clientId -> OAuth client id. * clientSecret -> OAuth client secret. * refreshToken -> REFRESH token. * accessToken -> Access token. * grantToken -> GRANT token. * id -> User unique id. * redirectURL -> OAuth redirect URL. */ //Create a Token instance // if refresh token is available // The SDK throws an exception, if the given id is invalid. Token token = new OAuthToken.Builder() .id("id") .build(); // if grant token is available Token token = new OAuthToken.Builder() .clientID("clientId") .clientSecret("clientSecret") .grantToken("grantToken") .redirectURL("redirectURL") .build(); // if ID (obtained from persistence) is available Token token = new OAuthToken.Builder() .clientID("clientId") .clientSecret("clientSecret") .refreshToken("refreshToken") .redirectURL("redirectURL") .build(); // if access token is available Token token = new OAuthToken.Builder() .accessToken("accessToken") .build();
Create an instance of TokenStore to persist tokens used for authenticating all the requests.
/* * Create an instance of DBStore that requires the following * host -> DataBase host name. Default value "localhost" * databaseName -> DataBase name. Default value "zohooauth" * userName -> DataBase user name. Default value "root" * password -> DataBase password. Default value "" * portNumber -> DataBase port number. Default value "3306" * tabletName -> DataBase table name. Default value "oauthtoken" */ //TokenStore tokenstore = new DBStore.Builder().build(); TokenStore tokenstore = new DBStore.Builder() .host("hostName") .databaseName("databaseName") .tableName("tableName") .userName("userName") .password("password") .portNumber("portNumber") .build(); //TokenStore tokenstore = new FileStore("/Users/user_name/Documents/java_sdk_token.txt"); //TokenStore tokenStore = new CustomStore();
Create an instance of SDKConfig containing the SDK configuration.
/* * By default, the SDK creates the SDKConfig instance * autoRefreshFields (default - false) * if true - all the modules' fields will be auto-refreshed in the background, every hour. * if false - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler(com.zoho.crm.api.util.ModuleFieldsHandler) * * pickListValidation (default - true) * A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list. * true - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error. * false - the SDK does not validate the input and makes the API request with the user’s input to the pick list */ SDKConfig sdkConfig = new SDKConfig.Builder() .autoRefreshFields(false) .pickListValidation(true) .build();
Set the absolute directory path to store user specific files containing module fields information in resourcePath.
String resourcePath = "/Users/user_name/Documents/javasdk-application";
Create an instance of RequestProxy containing the proxy properties of the user.
/* * Create an instance of RequestProxy * host -> proxyHost * port -> proxyPort * user -> proxyUser * password -> password * userDomain -> userDomain */ RequestProxy requestProxy = new RequestProxy.Builder() .host("host") .port(proxyPort) .user("userName") .password("password") .userDomain("userDomain") .build();
Initialize the SDK and make API calls.