Configuration - Python SDK

Configuration - Python SDK

Before you get started with creating your python application, you need to first authenticate the app with Zoho. And to do that there are some configuration procedures that need to be in place. There are two methods in which you can authenticate your application:
  • Passing a configuration dictionary - and then call ZCRMRestClient.initialize(config);
  • Using properties files in resources folder - and then call ZCRMRestClient.initialize();

Properties file

Your OAuth Client details should be given to the SDK as a property file. In SDK, we have placed a configuration file (oauth_configuration.properties). Please place the respective values in that file. You can find that file under 'zcrmsdk/resources'.

Based on your domain(EU,CN), please change the value of accounts_url. Default value set as US domain. Please fill the values for the following keys alone:
  1. client_id=
  2. client_secret=
  3. redirect_uri=
  4. accounts_url=https://accounts.zoho.com/
  5. token_persistence_path=
  • client_id, client_secret and redirect_uri are your OAuth client’s configurations that you get after registering your Zoho client.
  • access_type must be set to offline only because online OAuth client is not supported by the Python SDK as of now.
  • token_persistence_path is the path to store the OAuth related tokens in file. If this is set then, no need of database for persistence. Persistence happens through file only.
Include the absolute path in configuration.properties for the key “applicationLogFilePath” to store the logs. You can find that file under 'zcrmsdk/resources'. This file is to log the exceptions during the usage of Python SDK.

Please fill the value for the following key alone. If log path is not provided then logs won't be stored but you can see them in console
  1. applicationLogFilePath=
To make API calls to sandbox account, please change the value of following key to true. By default the value is false.
  1. sandbox=true
If your application needs only single user authentication then you have to set the user Email Id in configurations.properties file like below.
  1. currentUserEmail=user@email.com
In order to work with multi user authentication, you need to set the user EmailId in current thread as an attribute.
  1. threading.current_thread().__setattr__('current_user_email','user@email.com')
You can use the above one for single user authentication also but it's recommended to go with setting of email Id in configuration.properties file.

If you don't set the user email in current thread then SDK expect it from configuration.properties file. If user email is not set in any of these two then Python SDK will raise exception.

Configuration Dictionary

You can now pass the configuration values as python dictionary(key-value pair) as argument when you call the ZCRMRestClient.initialize(config) function. Below is the list of keys that are to be in the dictionary.

Mandatory Fields
Optional Fields
Database Fields(only when DB Persistence is used)
client_id
applicationLogFilePath
mysql_username
client_secret
sandbox
mysql_password
redirect_uri
access_type
mysql_port
 
accounts_url
 
 
token_persistence_path
 
 
apiBaseUrl
 
 
apiVersion
 
 
currentUserEmail
 
Note
If the Optional keys are not specified, their default values will be assigned automatically.

In case the "token_persistence_path" key is not provided with any value, the system automatically sets the persistence in a database, instead of a file. At that point you would have to provide additional MySQL parameters.

Below is an example of a Python dictionary containing the mandatory keys.
  1. config = {
  2.     "client_id":"1000.3RRCIG44JYHV040735GJGV9JA8X0YW",
  3.     "client_secret":"29ac7e2922700ed71e37781647fa9786cf0edf7e32",
  4.     "redirect_uri":"https://www.abc.com/",
  5. }
Below is an example of a Python dictionary containing all the keys.
  1. config = {
  2.     "apiBaseUrl":"https://www.zohoapis.com/",
  3.     "apiVersion":"v2",
  4.     "currentUserEmail":"email@gmail.com",
  5.     "sandbox":"False",
  6.     "applicationLogFilePath":"",
  7.     "client_id":"1000.3RRCIG44JYHV040735GJGV9JA8X0YW",
  8.     "client_secret":"29ac7e2922700ed71e37781647fa9786cf0edf7e32",
  9.     "redirect_uri":"https://www.abc.com/",
  10.     "accounts_url":"https://accounts.zoho.com/",
  11.     "token_persistence_path":"",
  12.     "access_type":"online",
  13.     "mysql_username":"",
  14.     "mysql_password":"",
  15.     "mysql_port":"3306"
  16. }
Note

In case "token_persistence_path" is empty and the user fails to give the mysql parameters, the dafault values will be assumed. The default value for "mysql_username" will be "root", passworkd will be left empty and the "port" will be "3306".

SQL Database Persistence

Currently, Zoho has support for only the MySQL database, in Python SDK. In case you want to use the DB persistence and you have a MySQL DB ready, you need to install the following package through "pip".
  1. pip install mysql-connector
Once these packages are installed, you can use the mysql fields(keys) in the configuration dictionary to achieve persistence. If token_persistence_path is provided in oauth_configuration.properties file, then persistence happens only in the file. In this case, there is no need of MySQL.

Create a empty file with name zcrm_oauthtokens.pkl in the mentioned token_persistence_path.
    • Related Articles

    • Python SDK - An Overview

      Python SDK offers a way to create client python applications that can be integrated with Zoho CRM. This SDK makes the access and use of necessary CRM APIs with ease. In other words, it serves as a wrapper for the REST APIs, making it easier to use ...
    • Initialization - Python SDK

      Now the app is ready to be initialized after defining configuration file/dictionary for your app. Generating grant and refresh tokens For a Single User(self-authorized) For self client apps, the self authorized grant token should be generated from ...
    • Configuration - PHP SDK

      Before you get started with creating your php application, you need to first authenticate the app with Zoho. And to do that there are some configuration procedures that need to be in place. There are two methods in which you can authenticate your ...
    • Configuration - Java SDK

      Setting up the configuration is a system engineering process, for establishing and maintaining the consistency of the application's performance, functional and physical attributes with its requirements, design and operational information throughout ...
    • Configuration - C# SDK

      Before you get started with creating your C# application, you need to first authenticate the app with Zoho. And to do that there are some configuration procedures that need to be in place. Basically, the OAuth Client details must be given as a ...