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:
- 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
To make API calls to sandbox account, please change the value of following key to true. By default the value is false.
If
your application needs only single user authentication then you have to
set the user Email Id in configurations.properties file like below.
In order to work with multi user authentication, you need to set the user EmailId in current thread as an attribute.
- 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.
- config = {
- "client_id":"1000.3RRCIG44JYHV040735GJGV9JA8X0YW",
- "client_secret":"29ac7e2922700ed71e37781647fa9786cf0edf7e32",
- "redirect_uri":"https://www.abc.com/",
- }
Below is an example of a Python dictionary containing all the keys.
- config = {
- "apiBaseUrl":"https://www.zohoapis.com",
- "apiVersion":"v2",
- "currentUserEmail":"email@gmail.com",
- "sandbox":"False",
- "applicationLogFilePath":"",
- "client_id":"1000.3RRCIG44JYHV040735GJGV9JA8X0YW",
- "client_secret":"29ac7e2922700ed71e37781647fa9786cf0edf7e32",
- "redirect_uri":"https://www.abc.com/",
- "accounts_url":"https://accounts.zoho.com",
- "token_persistence_path":"",
- "access_type":"online",
- "mysql_username":"",
- "mysql_password":"",
- "mysql_port":"3306"
- }
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".
- 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.