Kaizen Java SDK Version 5.0

Kaizen Java SDK Version 5.0

Hello, everyone! Welcome to another Kaizen week. In this post, we will discuss how third-party applications can integrate with Zoho CRM using Java SDK 5.0.

Use case 

Zylker is a real-estate app which can integrate with any CRM vendor and uses that data for it's use-cases. Zylker uses Java for the backend server code. Now they want to integrate with Zoho CRM.  How will they do it? Those users could be in different Zoho data centers like Europe (.eu), USA(.com), India(.in), Australia(.com.au) etc. With Zoho CRM's Java SDK 5.0, which consumes Zoho CRM v5 APIs, we can to do authorization and establish this integration. Zylker will write one common code and it should be usable for any CRM orgs across all DCs. 

Java SDK Project dependency

Include the Java dependency using either Maven or Gradle. The maven dependency is as below:

<repositories>
<repository>
<id>zohocrmsdk-5-0</id>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.zoho.crm</groupId>
<artifactId>zohocrmsdk-5-0</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>


If you are not using Maven or Gradle, please include the Zoho CRM Java SDK JAR and dependant JARs directly into the Java build path.

Setting up the OAuth client 

Create a Server-based Application in the corresponding API console page (https://www.zohoapis.{com/in/eu/com.au}). Enable "Multi-DC" under Settings of the app. Choose "Use the same OAuth credentials for all data centers". With this, you can use the same client ID, client secret, and redirect URI to authorize any Zoho account in any data center. Please refer to our previous posts to know more about domains and environments [Part -1] and [Part - 2].

Integrating the client with your application

In Zylker's web UI, there will be an option to integrate with Zoho CRM. The integration can be initiated from a link or a button containing the authorization URL, along with the corresponding client ID, state, redirect URI, and OAuth scopes. Once the user clicks on this link/button and completes the OAuth authorization process on Zoho, they will be redirected to the specified redirect URI with HTTP parameters location, code, accounts server, and state. These parameters can be utilized within the Java code logic of the redirect URI to begin using the Zoho CRM Java SDK.
The codes used in this post are hosted here for reference. We will focus on two distinct steps as mentioned below, for Zylker integration with Zoho CRM using Java SDK.
     1.  Authorize with Zoho CRM
     2. Fetching data from Zoho CRM

1. Authorize with Zoho CRM 

The aim of this step is to connect with the user's Zoho CRM and store the token details such as refresh token, access token and expiry time in the preferred datastore like MySQL, pgSQL etc. Once the user lands on the redirect URI after the OAuth2.0 authorization, we can extract the email of the logged-in user from zylker.com cookies. We also obtain the grant token and location from the redirect_uri of the authorization request. We pass these three values to the below integrateZohoCRM() function. This function takes care of creating a token for the connected Zoho CRM account and persisting it in the preferred datastore.


public static Boolean integrateZohoCRM(String location, String grant_token, String user_email) 
{
Boolean integrationStatus = Boolean.FALSE;
try {
Environment environment = DataCenter.get(location);
OAuthToken userToken = new OAuthToken.Builder()
                .clientID(OAuthClientDetails.CLIENT_ID)
                .clientSecret(OAuthClientDetails.CLIENT_SECRET)
                .grantToken(grant_token)
                .redirectURL(OAuthClientDetails.REDIRECT_URL)
                                 .userSignature(new UserSignature(user_email)) //email of the user who is trying to integrate with Zoho CRM          
                                 .build();
new Initializer.Builder().environment(environment).token(userToken).initialize(); 
integrationStatus = Boolean.TRUE;
    } catch (SDKException e) {
e.printStackTrace();
    } catch (Exception e) {
e.printStackTrace();
    }
return integrationStatus;
}

Refer here for the exact code section.

OAuthToken.Builder() creates a new instance of the builder for the OAuthToken class. It allows you to conveniently set up the necessary details for creating an OAuth token for authentication purposes. On passing the client ID, client secret, grant token, redirect URL, and user signature to the OAuthToken.Builder() method, we get the userToken object. One more important thing to note is that we have set the user signature as .userSignature(new UserSignature(user_email)) . This means that we are referring to the token uniquely by the email id of the logged-in Zylker user. The same signature should be used for any further operation to be done in Zoho CRM on behalf of this user.
Now that we have the OAuthToken object, we can send it to the Initializer class (as shown below) to create the refresh/access tokens and persist it.


 new Initializer.Builder().environment(environment).token(userToken).initialize(); 


As we haven't mentioned anything about where to do the persistence, by default the token details are persisted in a file named 'sdk_tokens.txt' using File Persistence. The content of the file would look like the following:


"id","user_name","client_id","client_secret","refresh_token","access_token","grant_token","expiry_time","redirect_url","api_domain" //Do not clear this default format, or else you will need  to generate a grant token again  in order to run the program.
"1","patricia@gmail.com","1000.xxxxx","xxxxxx","1000.xxxxxx.xxxx","1000.xxxxxxxxx.xxxxxxx","1000.xxxxxxxxx.xxxxxxx","1697370902510","https://www.zoho.com","https://www.zohoapis.com"



Apart from File Persistence, tokens can be persisted using Database persistence or Custom persistence.

Note

When Zoho introduces a new DC in future, it will be enough to update the project with the latest version of Zoho CRM Java SDK 5.0 and no further code change will be required. 

2. Fetching data from ZohoCRM

Once the integration is done, we can create OAuthToken with the user's email as UserSignature and call Zoho CRM Java SDK function. This will fetch the data specific to the user. The following fetchCRMData() function is a sample to fetch data from Zoho CRM.


public static void fetchCRMData(String email) throws Exception {
    OAuthToken userToken1 = new OAuthToken.Builder()
        .userSignature(new UserSignature(email))
        .build();
    new Initializer.Builder().token(userToken1).initialize();
    RecordOperations ro = new RecordOperations();
    ParameterMap paramInstance = new ParameterMap();
    List < String > fieldNames = new ArrayList < > (Arrays.asList("Company", "Email"));

    paramInstance.add(RecordOperations.GetRecordsParam.FIELDS, String.join(",", fieldNames));

    @SuppressWarnings("rawtypes")

    APIResponse response = ro.getRecords("Leads", paramInstance, null);

    .

    .

    .

}
 

Refer here for the exact code section.


In this example, we use the SDK's RecordOperations()  for retrieving records from the Leads module. This is done in the following steps:
  •  A new instance of RecordOperations is being created and assigned to the variable ro. This object handles operations related to records in Zoho CRM.  
  • ParameterMap instance is used to specify request parameters for the API calls. We can fetch the Company and the Email fields from the Leads module by passing them as the FIELDS parameter. 
  • We use the getRecords() method to make the API request via SDK, which fetches the respective CRM data.


We hope you found this post useful and interesting.  Stay tuned for more exciting posts.

Previous Kaizen Post : #107 Field Trackers in Zoho CRM

For more topics on Kaizen, please refer to our Kaizen collection here.







    Access your files securely from anywhere


            Zoho Developer Community




                                      Zoho Desk Resources

                                      • Desk Community Learning Series


                                      • Digest


                                      • Functions


                                      • Meetups


                                      • Kbase


                                      • Resources


                                      • Glossary


                                      • Desk Marketplace


                                      • MVP Corner


                                      • Word of the Day



                                          Zoho Marketing Automation


                                                  Manage your brands on social media



                                                        Zoho TeamInbox Resources

                                                          Zoho DataPrep Resources



                                                            Zoho CRM Plus Resources

                                                              Zoho Books Resources


                                                                Zoho Subscriptions Resources

                                                                  Zoho Projects Resources


                                                                    Zoho Sprints Resources


                                                                      Qntrl Resources


                                                                        Zoho Creator Resources



                                                                            Zoho CRM Resources

                                                                            • CRM Community Learning Series

                                                                              CRM Community Learning Series


                                                                            • Kaizen

                                                                              Kaizen

                                                                            • Functions

                                                                              Functions

                                                                            • Meetups

                                                                              Meetups

                                                                            • Kbase

                                                                              Kbase

                                                                            • Resources

                                                                              Resources

                                                                            • Digest

                                                                              Digest

                                                                            • CRM Marketplace

                                                                              CRM Marketplace

                                                                            • MVP Corner

                                                                              MVP Corner





                                                                                Design. Discuss. Deliver.

                                                                                Create visually engaging stories with Zoho Show.

                                                                                Get Started Now


                                                                                  Zoho Show Resources


                                                                                    Zoho Writer Writer

                                                                                    Get Started. Write Away!

                                                                                    Writer is a powerful online word processor, designed for collaborative work.

                                                                                      Zoho CRM コンテンツ






                                                                                        Nederlandse Hulpbronnen


                                                                                            ご検討中の方





                                                                                                  • Recent Topics

                                                                                                  • Account

                                                                                                    I need to know how the maximum contact records available in my subscription. Also pleas advise the process to increase Contact Records. Also I need someone to contact me, I may need to add users, but need to workout a package that would fit my budge
                                                                                                  • Moving contacts from one folder to different folder

                                                                                                    I set up two folders. Uploaded CSVs and build my fields according to what I needed. My boss wanted more fields and changed the categories wants different fields added and contacts in one folder moved to the other due to reclassification. How can I do
                                                                                                  • Custom Extension, create a trigger button in custom module to launch the app, or any workaround

                                                                                                    Hello Have created a custom extension , publish as private, all working But I'm facing an issue For my test I create a button in accounts or Contacts module to launch the app. But how I can handle to create same button in a custom module (not created
                                                                                                  • How do I filter contacts by account parameters?

                                                                                                    Need to filter a contact view according to account parameter, eg account type. Without this filter users are overwhelmed with irrelevant contacts. Workaround is to create a custom 'Contact Type' field but this unbearable duplicity as the information already
                                                                                                  • Getter error message Number of statement execution limit exceed Line:(216)

                                                                                                    Hi, this script is giving me error message "Number of statement execution limit exceed Line:(216)". Please advise htmlpage Pay_Period_Details(PayPeriodID,AgentID,ShowPrint,start_range,end_range) displayname = "Pay Period Details" content <%{ /* Get The current Pay Period Record */ Int_Pay_Period_ID = PayPeriodID.toLong(); Current_Pay_Period_Record = Pay_Period[ID == Int_Pay_Period_ID]; Previous_Pay_Period_ID = thisapp.Application.GetPreviousPayPeriodID(Current_Pay_Period_Record.ID); /* Checking Agent
                                                                                                  • API Casing needs consistency in names

                                                                                                    The JSON for an account record looks like this: {"Name": "Name of the Account", "id": "id of the account", "Address": "address of the account" "Owner":{ "name": "Name of Owner", "id": "id of owner", } } It makes no sense that "name" is capitalized in
                                                                                                  • Useful enhancements to Mail Merge in Zoho CRM

                                                                                                    Dear Customers, We hope you're well! We're here with a set of highly anticipated enhancements to the Mail Merge feature in Zoho CRM. Let's go! Mail Merge in Zoho CRM integrates with Zoho Writer to simplify the process of customizing and sharing documents
                                                                                                  • How can I create individual records from a subform

                                                                                                    Hi, I am collecting subform data into a Lead record and I need to create individual records for each row associated to the account when it is converted. How can I do this?
                                                                                                  • How Can I Easily Access and Manage My GEPCO Online Bill Using Zoho Sheets?

                                                                                                    Hello everyone, I'm looking for an efficient way to access and manage my GEPCO online bills. I've heard that Zoho Sheets can be a powerful tool for organizing and tracking bills, but I'm not sure how to set it up for this specific purpose. Does anyone
                                                                                                  • Prevent carriage returns / line breaks in multi line fields

                                                                                                    I'm trying to connect Zoho Sheets with Zoho Creator however because some people are using carriage returns in multi-line fields the rows are not being created correctly : The values in A4 and A6 are part of a multi line field that looks to have been split
                                                                                                  • How do you handle existing customers/contacts?

                                                                                                    Hi, We just integrated MA 2.0 with our CRM and we chose to only import our existing customers contacts. In MA they are all "Raw leads" by default and we would like to mass update these to a stage called "already customers" but the last default stage "Sales
                                                                                                  • Newspaper template

                                                                                                    Is there a template that looks like a newspaper or magazine?
                                                                                                  • New in Writer: Enhanced Content Generation and Formatting features

                                                                                                    We are excited to unveil these features that can enhance your content creation and formatting experience. These additions are carefully tailored to boost your productivity and unlock your full content creation potential. Get the scoop on all the fresh
                                                                                                  • Webhook when estimate is refused is not firing

                                                                                                    Hello, I use a workflow through make that sends estimate with zoho books (I paid books and sign). -Those estimates when accepted are firing the webhook that I create in zoho sign (photo 1) -However when refused they are not firing the webhook that I created
                                                                                                  • Transfer contact to a lead.

                                                                                                    Is there a way to transfer a contact from CRM to a lead without having to re enter everything.
                                                                                                  • Internal recruiting

                                                                                                    Does Zoho Recruit offer any solutions or features for internal recruiting?
                                                                                                  • Report to see committed stock vs quantities on order with suppliers

                                                                                                    Hello Zoho Community, I am looking for a report in Zoho Books / Inventory that will show the committed stock from sales orders, and show what quantities of the same part are on order from purchase orders. I have found the committed stock details report,
                                                                                                  • Form to update a CRM contact field

                                                                                                    Hello I need an help as I am going crazy. I need to create a form where there is a dropdown field with the contacts of Zoho crm (if possible filtered on the base of a field) and where other fields will be be automatically fetched with zoho crm data as
                                                                                                  • Add and Remove Agents from Departments and Groups in Zoho One

                                                                                                    Hi Zoho Flow Team, We hope you're doing well. Currently, Zoho Flow provides an action to add an agent to a group in zoho one, but there is no action to remove an agent from a group or a department. Another action that we find missing is the option to
                                                                                                  • Zoho Recruit - Blueprint and ZIA

                                                                                                    If I activate the Blueprint for Jobs in Zoho Recruit, Zia disappears for matching canddiates, why is that?
                                                                                                  • Where is the customization and extendibility of zoho inventory?

                                                                                                    After delving into zoho one subscription to test out systems we need for our business, I'm really disappointed after working in Zoho Inventory. Its features and customizability are extremely lacking compared to the other tools like CRM. In our case we
                                                                                                  • Announcing new features in Trident for Windows (v.1.20.4.0)

                                                                                                    Hello Community, Trident for Windows is here with some new features to elevate your work experience. Let's take a quick look at what's new. Export emails. You can now export emails in the .eml file format as compressed zipped files to create a secure
                                                                                                  • In focus: Customizing agent details in Radar

                                                                                                    Managing agent performance just got smarter! Imagine having all the key details about your agents right at your fingertips. That's exactly what the Agent Details feature in Radar offers. Whether it's their pictures, names, statuses, or ticket metrics
                                                                                                  • Bounced Emails

                                                                                                    Hello, Is there any chance we could have an alert for bounced emails in Recruit. This functionality is available in Zoho CRM. It would be really useful to be able to see at a glance who's messages have bounced back.
                                                                                                  • Requiring Proxy

                                                                                                    We are trying to get support from a company that uses Zoho assist. When we download the helper it is questing that we put in a proxy. What info do we need for the proxy / or to not need a proxy? I have tried a hot spot and allowing the program through
                                                                                                  • Creating a code for Task to event creation

                                                                                                    I am looking to automate an event creation to do the following: When a task is created for a user, create an event at 530PM simply called TASKS. This will serve as a reminder that we have at least one task that needs to be addressed. We miss the task
                                                                                                  • Kiosk Studio wrap-up | How our community used kiosks in 2024

                                                                                                    Hello, everyone! Happy new year! The end of 2024 has been busy, and 2025 promises to be bigger and better. As we ring in the new year, let's rewind and look at Kiosk Studio, our no-code customization tool. The past 300 days have seen the CRM community
                                                                                                  • Automate pushing Zoho CRM backups into Zoho WorkDrive

                                                                                                    Through our Zoho One subscription we have both Zoho CRM and Zoho WorkDrive. We have regular backups setup in Zoho CRM. Once the backup is created, we are notified. Since we want to keep these backups for more than 7 days, we manually download them. They
                                                                                                  • Books does not allow 19% tax rate for invoice - Please help!

                                                                                                    Hi there, I need to do an import of invoices into Zoho Books. The process worked smoothly before we migrated to the Books Germany Edition in December 2024. It does import 13 out of 14 invoices from my csv-file. For the one it does not import I get the
                                                                                                  • Restriction in assigning signer fields for the "Approver" role in APIs and internal integrations

                                                                                                    Hi, Zoho Sign's intended design is offering two actions to the recipient - Needs to sign (if you wish your recipient to add information to the document; signature, for instance) or Approver (someone who has to approve the content of the document and must
                                                                                                  • Create deal from estimate

                                                                                                    Hello, I have integrated CRM and books. I created an estimate on CRM but I would like to allocate that estimate to a deal with the contact. How can I do this please?
                                                                                                  • Want to upload images to custom image fields using zoho crm api v2.

                                                                                                    Hi i want to upload image to my custom image field from third party application using zoho crm api v2 . Please tell me how i can do this? Thanks
                                                                                                  • This domain is not allowed to add. Please contact support-as@zohocorp.com for further details

                                                                                                    I am trying to setup the free version of Zoho Mail. When I tried to add my domain, theselfreunion.com I got the error message that is the subject of this Topic. I've read your other community forum topics, and this is NOT a free domain. So what is the
                                                                                                  • Its 2022, can our customers log into CRM on their mobiles? Zoho Response: Maybe Later

                                                                                                    I am a long time Zoho CRM user. I have just started using the client portal feature. On the plus side I have found it very fast and very easy (for someone used to the CRM config) to set up a subset of module views that make a potentially extremely useful
                                                                                                  • Change Invoice Prices for an Effective Date

                                                                                                    Hi, It would be a really good feature to be able to change the prices on invoices/recurring invoices from an effective date in the event of price increases. For instance, I am in the process of increasing prices that will be effective from a specific
                                                                                                  • Related list Mobile Device

                                                                                                    Hello, We use an the Zoho creator application to make reports linked to Accounts. On the computer: it's easy to go the Account and see all the created reports in the related list below On iPad/Phone ZOHO CRM APP: we cannot see the reports on those accounts
                                                                                                  • How can I visualize the events of a pipeline records?

                                                                                                    Hi I need a list of events, including the date and address of the event related to the pipeline record. Can I do that? I know that for every pipeline record I can create events associated (Tasks, events, calls). But what I need it is an easy way to get
                                                                                                  • Unlocking New Horizons: A Year in Review

                                                                                                    As we bid farewell to 2024, let's celebrate and revisit the key highlights of the year. From adding a new edition to cross-platform enhancements, here’s a roundup of all the feature updates designed to simplify accounting, optimize financial management,
                                                                                                  • Creating smart filters manually

                                                                                                    Hi Team, One of my colleagues accidentally deleted the Notification folder in Zoho Mail. Now all the emails are directing to spam instead of inbox. Is there any way to create the smart filter manually?. With Regards, Logeswar V
                                                                                                  • How to send binary data in invokeurl task?

                                                                                                    Hello, I am using Adobe's Protect PDF API. Source: https://developer.adobe.com/document-services/docs/overview/pdf-services-api/ Everything works fine in Postman. But for some reason after encrypting the file, it is empty after password protecting the
                                                                                                  • Next Page