Initializing the SDK
You must initialize the SDK before your app can consume its methods. To initialize, set the required configurations through the ZCRMSDKConfigs object and pass it to the init() method in the ZCRMSDKClient object as follows.
ZCRMSDKClient.getInstance(applicationContext).init( configs: ZCRMSDKConfigs, initCallback: ZCRMSDKClient.Companion.ZCRMInitCallback )
If the user is not logged in, a login screen will be prompted during the SDK initialization. Based on the result of the login, the appropriate callback method will be triggered.
Only after the successful initialization of the SDK, further methods can be invoked as intended.
SDK Configuration object
There are two methods for configuring the app client details. Based on the app's type, you can use the appropriate method.
For the app types ZCRM, BIGIN and SOLUTIONS, set the app client details as string values, and pass it to the getBuilder() method (builder pattern) using the ZCRMSDKConfigs object as shown below.
ZCRMSDKConfigs.getBuilder( clientID: "<OAuth client id of the app client registered in Zoho>", clientSecret: "<OAuth client secret of the app client registered in Zoho>", oauthScopes: "<required_oauthscopes>" ).build()
- clientID and clientSecret : Configure the OAuth client ID and secret of the app registered in Zoho.
- oauthScopes : The OAuth scopes of the Zoho CRM API that the app would use.
For the app types ZVCRM and ZCRMCP, besides the above mentioned client details, the portal ID and portal name should be configured using the following method.
ZCRMSDKConfigs.getBuilder( clientID: "<OAuth client id of the app client registered in Zoho>", clientSecret: "<OAuth client secret of the app client registered in Zoho>", oauthScopes: "<required_oauthscopes>", portalId: "<portal_ID>", portalName: "<portal_name>" ).build()
- portalName: Specify the client's portal name.
- portalId : Specify the client's portal ID.
The ZCRMSDKConfigs class also has the following methods to set the configuration properties.
- setApiBaseURL() - The URL to be used when making an API call. It denotes the user's domain.
- setApiVersion() - The version to be used when calling the API.
- setUserAgent() - Unique identification for the server to find where the API request is from.
- setAppType() - The appropriate app type of the SDK. Use ZCRM if your app is for Zoho CRM users or use ZCRMCP if your app is for Zoho CRM Portal users.
- setLoggingPreferences(minLogLevel: Level, printStackTrace: Boolean) - The logging preferences of the warnings, errors, information, and debug. The default value is Level.WARNING.
To get the detailed trace of the logs, set the printStackTracevalue as 'true'. The default value is 'false'. - setHttpRequestMode() - The HTTP request mode. The values can be SYNC or ASYNC. The default value is ASYNC.
- setCacheValidityTimeInHours() - The cache invalidating duration in hours. After this time period, the respective cache will be deleted and fetched again from the server. The default value is 6 hours and this is applicable only if cache is enabled. The cache is available only for the meta APIs (org, portal, current user and module fields).
- setConnectTimeOutInSec() - The connection time out(in seconds) of the HTTP request sent from the SDK. The default value is 10 seconds.
- setReadTimeOutInSec() - The read time out(in seconds) of the HTTP request sent from the SDK, i.e. if no data comes from the server within this period, the connection is terminated. The default read time out is 60 seconds.
- setWriteTimeOutInSec() - The write time out(in seconds) of the HTTP request sent from the SDK, i.e. if there is a failure in writing anything within this period, the connection is terminated. The default write time out is 10 seconds.
Utility Functions
The ZCRMSDKClient class also provides certain utility functions that you can use appropriately in your client app logic.
- isUserSignedIn() - Returns the boolean 'true' when the signed in successfully. Else, returns 'false'.
- getCurrentUser() - Passes the currently logged-in user's object in the callback from the database.
- getCurrentUserFromServer() - Passes the currently logged-in user's object in the callback from the server.
- changeMinLogLevel() - Changes the logging level of the messages using the predefined level constants such as ALL, CONFIG, FINE, FINER, FINEST, INFO, OFF, SEVERE, and WARNING.
- enableDBCaching() - Enables the caching of meta data API responses in the local SQLite instance of the app. Any entity that comes under the Setup screen of Zoho CRM (like company, users, modules, layouts and so on) is considered meta data.
- clearAllCache(completionTask: CompletionTask) - Clears all data cached from the app.
- disableDBCaching(completionTask: CompletionTask) - Disables the caching of API responses.
Logging Out
To log users out from Zoho CRM on your app, use the following code snippet.
ZCRMSDKClient.getInstance(applicationContext).logout( logoutCallback: ZCRMSDKClient.Companion.ZCRMLogoutCallback )