Zoho provides a Python SDK that can be integrated with Zoho CRM, but it seems a bit complicated. Hence, this repo shows how to set up Python for Zoho CRM and fetch Zoho CRM data with Python.
1.sign in zoho(https://accounts.zoho.com/signin)
2.Visit the page https://api-console.zoho.com/ and click ADD CLIENT
(the easiest way to setup api)
Enter Client Name, Homepage URL, and Authorized Redirect URI. Click CREATE.You can fill your personal or company homepage url in these two url fields.
(Not recommended)if you don't have any url, you can fill any website you trust, maybe such as google.
https://accounts.zoho.com/oauth/v2/auth?response_type=code&client_id={your_client_id}&scope=AaaServer.profile.Read,ZohoCRM.Modules.ALL&redirect_uri={your_redirect_uri}
Make sure the scope contains"AaaServer.profile.Read". And if you have to get all zoho data, you can add the scope"ZohoCRM.Modules.ALL".
click Submitand accept
After you click submit and accept, you will redirect to the website you fill in the previous step.
And you have to get the authorization grant code on url(after"code=")
Warning: Authorization Grant Code Lifetime : one minute.
pip install zcrmsdk
from zcrmsdk import ZCRMRecord,ZCRMRestClient,ZohoOAuth,ZCRMModule
config = { 'currentUserEmail':'YOUR_ZOHO_EMAIL',
'sandbox':'False',
'applicationLogFilePath':'./log',
'client_id':'YOUR_CLIENT_ID',
'client_secret':'YOUR_CLIENT_SECRET',
'redirect_uri':'YOUR_REDIRECT_URI',
'accounts_url':'YOUR_ACCOUNTS_URL',
'token_persistence_path':"."}
ZCRMRestClient.initialize(config)
oauth_client = ZohoOAuth.get_client_instance()
grant_token = "Authorization_Grant_Code"
oauth_tokens = oauth_client.generate_access_token(grant_token)
print(oauth_tokens)
currentUserEmail: you have to check your zoho email
client_id and client_secret: in the previous step
redirect_uri: in the previous step
accounts_url: Based on your domain,default:https://accounts.zoho.com
Authorization_Grant_Code:in the previous step
You have to create a log file for saving log details. After you run the code below, the oauth.log will create in the file automatically. Also the zcrm_oauthtokens.pkl will create automatically.
- Get a Record by Id
record = ZCRMRecord.get_instance('Leads',id)
resp = record.get()
print(resp.data.field_data['Email'])
- Get Module Records
module_ins = ZCRMModule.get_instance('Leads')
resp=module_ins.get_records(page=3,per_page=100)
for records in resp.data:
print(records)