Integrating with Zoho using Python allows seamless automation of marketing, sales, and customer service processes. By leveraging the Zoho API, Python scripts can interact with Zoho's CRM, automate email campaigns, sync data between platforms, and analyze customer interactions for targeted engagement. This integration empowers businesses to streamline workflows, personalize communication, and drive growth efficiently.
This library has been tested with python 2 and 3.
Installation
Install the library using pip:
pip install flask requests
The purpose of creating the Zoho project using Python and Flask, along with essential libraries, is to facilitate OAuth2 authentication on behalf of users and efficiently complete tasks within designated timeframes, acquiring a token in the process. This project automates marketing activities on Zoho, leveraging user-triggered behavior. Zoho serves as an inbound marketing tool and sales platform, enabling seamless customer attraction and lead conversion. The project workflow involves initially setting up a developer account on Zoho, followed by creating an app within it. Upon app creation, essential credentials such as Client_id, Client_secret, and Redirect_uri are generated for further integration and authentication purposes.
Implementation
scope = "ZohoCRM.modules.ALL"
client_id = "<YOUR_ZOHO_CLIENT_ID>"
redirect_URI = "<YOUR_ZOHO_REDIRECT_URI>"
url = f"https://accounts.zoho.com/oauth/v2/auth?scope={scope}&\
client_id={client_id}&response_type=code&\
redirect_uri={redirect_URI}"
To start OAuth access, direct Zoho users to your authorization URL. They must be logged into Zoho to authorize your app. Once authorized, they'll be redirected to the designated redirect_uri with a code query parameter appended to the URL. This code is then used, along with your client_id, client_secret, and scope, to obtain an access token from Zoho. With this access token, your app gains the necessary permissions to interact with Zoho's API.
code = request.args.get("code")
client_id = "<YOUR_ZOHO_CLIENT_ID>"
client_secret = "<YOUR_ZOHO_CLIENT_SECRET>"
redirect_URI = "<YOUR_ZOHO_REDIRECT_URI>"
response = requests.post("https://accounts.zoho.com/oauth/v2/token?code={}&\
redirect_uri={redirect_URI}&client_id={client_id}&client_secret={client_secret}&\
grant_type=authorization_code", headers=headers, data=data)
access_token = response.json().get("access_token")
refresh_token = response.json().get("refresh_token")
Getting access token
After getting access_token, we can easily fetch user_info:
if access_token:
headers = {'Authorization': f'Zoho-oauthtoken {access_token}'}
response = requests.get("https://www.zohoapis.com/crm/v2/Leads",headers=headers)
To obtain access to account details, follow these steps:
- Navigate to the API URL, such as http://localhost:8000/api.
- Use Postman or the browser search bar to hit an API, triggering the generation of a code.
- This action automatically triggers an authorization API, which generates the code.
- The generated code is then used to obtain an access_token via OAuth2 authentication.
- Utilize the access_token to retrieve various account details, including account data, opportunities, contacts, and more.
- With all necessary credentials, save the integrated user's details securely in the database for future reference.
Client requirements are as follows:
- OAuth2 Authorization: Upon user login to the website, ensure that neither third-party apps nor the website server can access the user's password.
- Use Access Token: Employ access tokens to enhance authentication security, allowing users to access content securely on the website post-authentication.
Benefits:
- Seamless Authentication: Users can authenticate to partner applications using their Zoho login credentials, enhancing user experience and convenience.
- Enhanced Security: Zoho issues refresh tokens, allowing users to obtain new access tokens without sharing their password credentials. This ensures that sensitive information is not stored or shared with third-party websites or databases, enhancing security.
- Automated Token Refresh: With refresh tokens, users can automatically obtain new access tokens, eliminating the need for them to log in to Zoho again. This improves workflow efficiency and reduces user friction.
- Expiry Mechanism: Automatically generated tokens have a predefined expiry duration, typically 60 days, enhancing security by ensuring that access remains valid for a limited period, mitigating the risk of unauthorized access.
Live Example
Want to see something cool? Click this button and watch the accent color on this page change.
License
Zoho Integration
is licensed under the MIT License.