### Full SDK Initialization Example Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/README.md Provides a comprehensive code example demonstrating the initialization of the Zoho CRM Python SDK. This includes setting up the logger, environment, authentication token, token store, SDK configuration, resource path, and request proxy. ```APIDOC ## Initializing the Application Initialize the SDK using the following code. This example demonstrates initialization with `USDataCenter`, `DBStore` for token persistence, and custom logger and request proxy settings. ```python from zohocrmsdk.src.com.zoho.crm.api.dc import USDataCenter from zohocrmsdk.src.com.zoho.api.authenticator.store import DBStore, FileStore from zohocrmsdk.src.com.zoho.api.logger import Logger from zohocrmsdk.src.com.zoho.crm.api.initializer import Initializer from zohocrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken from zohocrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig from zohocrmsdk.src.com.zoho.crm.api.request_proxy import RequestProxy class SDKInitializer(object): @staticmethod def initialize(): # Initialize Logger logger = Logger.get_instance(level=Logger.Levels.INFO, file_path='/Users/user_name/Documents/python_sdk_log.log') # Set Environment environment = USDataCenter.PRODUCTION() # Initialize OAuth Token token = OAuthToken(client_id='clientId', client_secret='clientSecret', grant_token='grant_token', refresh_token="refresh_token", redirect_url='redirectURL', id="token_id") # Initialize Token Store (using DBStore in this example) # For FileStore, uncomment the line below and comment out DBStore initialization # store = FileStore(file_path='/Users/username/Documents/python_sdk_tokens.txt') store = DBStore(host='host_name', database_name='database_name', user_name='user_name', password='password', port_number='port_number', table_name="table_name") # Initialize SDK Configuration config = SDKConfig(auto_refresh_fields=True, pick_list_validation=False, connect_timeout=None, read_timeout=None) # Set Resource Path resource_path = '/Users/python-app' # Initialize Request Proxy # For proxy without authentication, uncomment the line below and comment out the one with user/password # request_proxy = RequestProxy(host='host', port=8080) request_proxy = RequestProxy(host='host', port=8080, user='user', password='password') """ Call the static initialize method of Initializer class that takes the following arguments 2 -> Environment instance 3 -> Token instance 4 -> TokenStore instance 5 -> SDKConfig instance 6 -> resource_path 7 -> Logger instance. Default value is None 8 -> RequestProxy instance. Default value is None """ Initializer.initialize(environment=environment, token=token, store=store, sdk_config=config, resource_path=resource_path, logger=logger, proxy=request_proxy) SDKInitializer.initialize() ``` **Note:** - The `id` parameter in `OAuthToken` is a unique identifier for the token, auto-generated after successful SDK initialization. It should not match the parameter name itself. ``` -------------------------------- ### SDK Initialization Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/3.0.0/README.md Provides a comprehensive example of how to initialize the Zoho CRM Python SDK with various configuration options, including environment, authentication, token storage, SDK configuration, resource path, logging, and proxy. ```APIDOC ## Initializing the Application ### Description This section demonstrates the process of initializing the Zoho CRM Python SDK. It covers setting up the environment, authentication, token storage, SDK configurations, resource path for storing module fields, optional logging, and proxy settings. ### Method Static method call ### Endpoint N/A (Initialization process) ### Parameters #### Environment Instance - **`environment`** (Object) - Represents the data center environment (e.g., `USDataCenter.PRODUCTION()`). #### Token Instance - **`token`** (Object) - An instance of `OAuthToken` containing authentication credentials. - **`client_id`** (String) - Your application's client ID. - **`client_secret`** (String) - Your application's client secret. - **`grant_token`** (String) - The grant token obtained during the authorization process. - **`refresh_token`** (String) - The refresh token for obtaining new access tokens. - **`redirect_url`** (String) - The URL to redirect to after authorization. - **`id`** (String) - A unique ID for the token, auto-generated after successful SDK initialization. #### TokenStore Instance - **`store`** (Object) - An instance of a token store (e.g., `DBStore`, `FileStore`) for persisting tokens. - **`DBStore` Parameters**: - **`host`** (String) - Database host. - **`database_name`** (String) - Name of the database. - **`user_name`** (String) - Database username. - **`password`** (String) - Database password. - **`port_number`** (String) - Database port number. - **`table_name`** (String) - Name of the table to store tokens. - **`FileStore` Parameters**: - **`file_path`** (String) - Path to the file where tokens will be stored. #### SDKConfig Instance - **`sdk_config`** (Object) - An instance of `SDKConfig` with desired configuration settings (refer to SDK Configuration Options section). #### resource_path - **`resource_path`** (String) - The directory path for storing module fields information. #### Logger Instance (Optional) - **`logger`** (Object) - An instance of `Logger` for logging SDK activities. - **`level`** (Enum) - Logging level (e.g., `Logger.Levels.INFO`). - **`file_path`** (String) - Path to the log file. #### RequestProxy Instance (Optional) - **`proxy`** (Object) - An instance of `RequestProxy` for configuring proxy settings (refer to `RequestProxy` Configuration section). ### Request Example ```python from zohocrmsdk.src.com.zoho.crm.api.dc import USDataCenter from zohocrmsdk.src.com.zoho.api.authenticator.store import DBStore, FileStore from zohocrmsdk.src.com.zoho.api.logger import Logger from zohocrmsdk.src.com.zoho.crm.api.initializer import Initializer from zohocrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken from zohocrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig from zohocrmsdk.src.com.zoho.crm.api.request_proxy import RequestProxy class SDKInitializer(object): @staticmethod def initialize(): logger = Logger.get_instance(level=Logger.Levels.INFO, file_path='/Users/user_name/Documents/python_sdk_log.log') environment = USDataCenter.PRODUCTION() token = OAuthToken(client_id='clientId', client_secret='clientSecret', grant_token='grant_token', refresh_token="refresh_token", redirect_url='redirectURL', id="token_id") # store = FileStore(file_path='/Users/username/Documents/python_sdk_tokens.txt') store = DBStore(host='host_name', database_name='database_name', user_name='user_name', password='password', port_number='port_number', table_name="table_name") config = SDKConfig(auto_refresh_fields=True, pick_list_validation=False, connect_timeout=None, read_timeout=None) resource_path = '/Users/python-app' # request_proxy = RequestProxy(host='host', port=8080) request_proxy = RequestProxy(host='host', port=8080, user='user', password='password') Initializer.initialize(environment=environment, token=token, store=store, sdk_config=config, resource_path=resource_path, logger=logger, proxy=request_proxy) SDKInitializer.initialize() ``` ### Response - **Success Response (200)**: Upon successful initialization, the SDK is ready for use. No specific response body is returned for the initialization call itself. ### Notes - The `id` parameter in `OAuthToken` is auto-generated and should not match its parameter name. - After successful initialization, you can access the SDK's functionalities for making API calls. ``` -------------------------------- ### Get Layouts and Field Lookup Details (Python SDK 7.0) Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md This snippet demonstrates how to retrieve layouts and iterate through profiles to get the default view. It also shows how to access details for MultiSelectLookup and MultiUserLookup fields, including display labels, linking modules, and API names. This applies to SDK version 7.0-v4.0.0. ```python layouts = response_object.get_layouts() for layout in layouts: profiles = layout.get_profiles() if profiles is not None: for profile in profiles: default_view = profile.get_defaultview() # get multi select lookup for field multi_select_lookup = field.get_multiselectlookup() if multi_select_lookup is not None: print("Field MultiSelectLookup DisplayLabel: " + multi_select_lookup.get_display_label()) print("Field MultiSelectLookup LinkingModule: " + multi_select_lookup.get_linking_module()) print("Field MultiSelectLookup LookupApiname: " + multi_select_lookup.get_lookup_apiname()) print("Field MultiSelectLookup APIName: " + multi_select_lookup.get_api_name()) print("Field MultiSelectLookup ConnectedlookupApiname: " + multi_select_lookup.get_connectedlookup_apiname()) print("Field MultiSelectLookup ID: " + multi_select_lookup.get_id()) print("Field MultiSelectLookup ConnectedModule: " + multi_select_lookup.get_connected_module()) # get multi user lookup for field if multi_select_lookup is not None: multi_user_lookup = field.get_multiuserlookup() print("Field MultiUserLookup DisplayLabel" + multi_user_lookup.get_display_label()) print("Field MultiUserLookup LinkingModule" + multi_user_lookup.get_linking_module()) print("Field MultiUserLookup LookupApiname" + multi_user_lookup.get_lookup_apiname()) print("Field MultiUserLookup APIName" + multi_user_lookup.get_api_name()) print("Field MultiUserLookup ID" + multi_user_lookup.get_id()) print("Field MultiUserLookup ConnectedModule" + multi_user_lookup.get_connected_module()) print("Field MultiUserLookup ConnectedlookupApiname" + multi_user_lookup.get_connectedlookup_apiname()) ``` -------------------------------- ### GET Request Response Structures Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/README.md Details the possible response structures for GET requests, including common and particular formats, and the classes involved. ```APIDOC ## GET Request Response Structures ### Description This section outlines the different response structures expected for `GET` requests, categorized into common and particular formats, and lists the handler and wrapper classes involved. ### Method GET ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Common Structure - **ResponseHandler** encompasses: - **ResponseWrapper class** (for `application/json` responses) - **FileBodyWrapper class** (for File download responses) - **APIException class** #### Particular Structures: - **History API (backup)**: - **ResponseHandler** encompasses: - **HistoryWrapper class** (holds list of `History` and `Info` instances) - **UrlsWrapper class** (holds `Urls` instance) - **UserGroups API**: - **ResponseHandler** encompasses: - **SourcesCountWrapper class** (holds List of `SourceCount` instances) - **SourcesWrapper class** (holds List of `Sources` and `Info` instances) - **BulkWrite API**: - **ResponseWrapper class** encompasses: - **BulkWriteResponse class** - **APIException class** - **Record API (Count)**: - **CountHandler class** encompasses: - **CountWrapper class** (holds Long `count`) - **APIException class** - **Record API (Deleted Records)**: - **DeletedRecordsHandler class** encompasses: - **DeletedRecordsWrapper class** (holds list of `DeletedRecord` and `Info` instances) - **APIException class** - **File Download**: - **DownloadHandler class** encompasses: - **FileBodyWrapper class** - **APIException class** - **Record API (Mass Update)**: - **MassUpdateResponseHandler class** encompasses: - **MassUpdateResponseWrapper class** (holds list of `MassUpdateResponse` instances) - **APIException class** - **MassUpdate Response**: - **MassUpdateResponse class** encompasses: - **MassUpdate class** - **APIException class** - **UserTerritories API**: - **ValidationHandler class** encompasses: - **ValidationWrapper class** (holds list of `ValidationGroup` instances) - **APIException class** - **ValidationGroup class** (within UserTerritories API): - **Validation class** - **BulkValidation class** #### Response Example N/A ``` -------------------------------- ### Install Python SDK Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/README.md This command installs the Zoho CRM Python SDK version 8.0 using pip. Ensure Python is installed on your system before running this command. It is recommended to run this command within your project's virtual environment. ```sh pip install zohocrmsdk8_0 ``` -------------------------------- ### Multi-threading for Single User App with Zoho CRM Python SDK Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/3.0.0/README.md This snippet demonstrates how to initialize the Zoho CRM SDK and use multi-threading to fetch records from different modules concurrently. It includes setting up authentication, logger, SDK configuration, and then starting and joining threads for 'Leads' and 'Quotes' modules. It handles potential API exceptions and prints record details. ```python import threading from zohocrmsdk.src.com.zoho.crm.api.parameter_map import ParameterMap from zohocrmsdk.src.com.zoho.crm.api.dc import USDataCenter from zohocrmsdk.src.com.zoho.api.authenticator.store import DBStore from zohocrmsdk.src.com.zoho.api.logger import Logger from zohocrmsdk.src.com.zoho.crm.api.initializer import Initializer from zohocrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken from zohocrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig from zohocrmsdk.src.com.zoho.crm.api.record import * class MultiThread(threading.Thread): def __init__(self, module_api_name): super().__init__() self.module_api_name = module_api_name def run(self): try: print("Calling Get Records for module: " + self.module_api_name) param_instance = ParameterMap() param_instance.add(GetRecordsParam.fields, "id") response = RecordOperations(self.module_api_name).get_records(param_instance) if response is not None: print('Status Code: ' + str(response.get_status_code())) if response.get_status_code() in [204, 304]: print('No Content' if response.get_status_code() == 204 else 'Not Modified') return response_object = response.get_object() if response_object is not None: if isinstance(response_object, ResponseWrapper): record_list = response_object.get_data() for record in record_list: for key, value in record.get_key_values().items(): print(key + " : " + str(value)) elif isinstance(response_object, APIException): print("Status: " + response_object.get_status().get_value()) print("Code: " + response_object.get_code().get_value()) print("Details") details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) print("Message: " + response_object.get_message().get_value()) except Exception as e: print(e) @staticmethod def call(): logger = Logger.get_instance(level=Logger.Levels.INFO, file_path="/Users/user_name/Documents/python_sdk_log.log") token = OAuthToken(client_id="clientId", client_secret="clientSecret", grant_token="grant_token", refresh_token="refreshToken", redirect_url="redirectURL", id="id") environment = USDataCenter.PRODUCTION() store = DBStore() sdk_config = SDKConfig() resource_path = '/Users/user_name/Documents/python-app' Initializer.initialize(environment=environment, token=token, store=store, sdk_config=sdk_config, resource_path=resource_path, logger=logger) t1 = MultiThread('Leads') t2 = MultiThread('Quotes') t1.start() t2.start() t1.join() t2.join() MultiThread.call() ``` -------------------------------- ### Get Multi-Select Lookup Field Details (Python SDK 8.0) Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md Retrieves and prints detailed information about multi-select lookup fields using Python SDK version 8.0. This version introduces structured access to `linking_details` and `connected_details`, providing more granular data on modules and fields involved in the lookup. ```python # get the multi select lookup for field multi_select_lookup = field.get_multiselectlookup() if multi_select_lookup is not None: linking_details = multi_select_lookup.get_linking_details() if linking_details is not None: module = linking_details.get_module() if module is not None: print("Field Multiselectlookup LinkingDetails Module Visibility: ", module.get_visibility()) print("Field Multiselectlookup LinkingDetails Module PluralLabel: ", module.get_plural_label()) print("Field Multiselectlookup LinkingDetails Module APIName: ", module.get_api_name()) print("Field Multiselectlookup LinkingDetails Module Id: ", module.get_id()) lookup_field = linking_details.get_lookup_field() if lookup_field is not None: print("Field MultiSelectLookup LinkingDetails LookupField APIName: ", lookup_field.get_api_name()) print("Field MultiSelectLookup LinkingDetails LookupField FieldLabel: ", lookup_field.get_field_label()) print("Field MultiSelectLookup LinkingDetails LookupField Id: ", lookup_field.get_id()) connected_lookup_field = linking_details.get_connected_lookup_field() if connected_lookup_field is not None: print("Field MultiSelectLookup LinkingDetails ConnectedLookupField APIName: ", connected_lookup_field.get_api_name()) print("Field MultiSelectLookup LinkingDetails ConnectedLookupField FieldLabel: ", connected_lookup_field.get_field_label()) print("Field MultiSelectLookup LinkingDetails ConnectedLookupField Id: ", connected_lookup_field.get_id()) connected_details = multi_select_lookup.get_connected_details() if connected_details is not None: connection_field = connected_details.get_field() if connection_field is not None: print("Field Multiselectlookup ConnectedDetails Field APIName: ", connection_field.get_api_name()) print("Field Multiselectlookup ConnectedDetails Field FieldLabel: ", connection_field.get_field_label()) print("Field Multiselectlookup ConnectedDetails Field id: ", connection_field.get_id()) connected_module = connected_details.get_module() if connected_module is not None: print("Field MultiSelectLookup ConnectedDetails Module PluralLabel: ", connected_module.get_plural_label()) print("Field MultiSelectLookup ConnectedDetails Module APIName: ", connected_module.get_api_name()) print("Field MultiSelectLookup ConnectedDetails Module Id: ", connected_module.get_id()) layouts = connected_details.get_layouts() if layouts is not None and len(layouts) > 0: for layout in layouts: print("Field MultiSelectLookup ConnectedDetails Layouts APIName: ", layout.get_api_name()) ``` -------------------------------- ### Get Layouts and Field Lookup Details (Python SDK 8.0) Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md This snippet shows how to retrieve layouts and iterate through profiles to access the default view using the updated method `get_default_view`. It details how to access linking and connected details for MultiSelectLookup fields, including module visibility, plural labels, API names, and lookup field information. This is for SDK version 8.0-v1.0.0. ```python layouts = response_object.get_layouts() for layout in layouts: profiles = layout.get_profiles() if profiles is not None: for profile in profiles: default_view = profile.get_default_view() # get the multi select lookup for field multi_select_lookup = field.get_multiselectlookup() if multi_select_lookup is not None: linking_details = multi_select_lookup.get_linking_details() if linking_details is not None: module = linking_details.get_module() if module is not None: print("Field Multiselectlookup LinkingDetails Module Visibility: ", module.get_visibility()) print("Field Multiselectlookup LinkingDetails Module PluralLabel: ", module.get_plural_label()) print("Field Multiselectlookup LinkingDetails Module APIName: ", module.get_api_name()) print("Field Multiselectlookup LinkingDetails Module Id: ", module.get_id()) lookup_field = linking_details.get_lookup_field() if lookup_field is not None: print("Field MultiSelectLookup LinkingDetails LookupField APIName: ", lookup_field.get_api_name()) print("Field MultiSelectLookup LinkingDetails LookupField FieldLabel: ", lookup_field.get_field_label()) print("Field MultiSelectLookup LinkingDetails LookupField Id: ", lookup_field.get_id()) connected_lookup_field = linking_details.get_connected_lookup_field() if connected_lookup_field is not None: print("Field MultiSelectLookup LinkingDetails ConnectedLookupField APIName: ", connected_lookup_field.get_api_name()) print("Field MultiSelectLookup LinkingDetails ConnectedLookupField FieldLabel: ", connected_lookup_field.get_field_label()) print("Field MultiSelectLookup LinkingDetails ConnectedLookupField Id: ", connected_lookup_field.get_id()) connected_details = multi_select_lookup.get_connected_details() if connected_details is not None: connection_field = connected_details.get_field() if connection_field is not None: print("Field Multiselectlookup ConnectedDetails Field APIName: ", connection_field.get_api_name()) print("Field Multiselectlookup ConnectedDetails Field FieldLabel: ", connection_field.get_field_label()) print("Field Multiselectlookup ConnectedDetails Field id: ", connection_field.get_id()) connected_module = connected_details.get_module() if connected_module is not None: print("Field MultiSelectLookup ConnectedDetails Module PluralLabel: ", connected_module.get_plural_label()) print("Field MultiSelectLookup ConnectedDetails Module APIName: ", connected_module.get_api_name()) ``` -------------------------------- ### Python Multi-threading for Zoho CRM Single User App Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/2.0.0/README.md This Python code defines a `MultiThread` class that extends `threading.Thread` to perform concurrent operations on Zoho CRM modules. It initializes the Zoho CRM SDK, creates instances of `MultiThread` for different modules (e.g., 'Leads', 'Quotes'), starts them, and waits for their completion using `join()`. The `run` method fetches record IDs for a given module, handling potential API exceptions and response wrappers. The `call` static method orchestrates the SDK initialization and thread execution. ```python import threading from zohocrmsdk.src.com.zoho.crm.api.parameter_map import ParameterMap from zohocrmsdk.src.com.zoho.crm.api.dc import USDataCenter from zohocrmsdk.src.com.zoho.api.authenticator.store import DBStore from zohocrmsdk.src.com.zoho.api.logger import Logger from zohocrmsdk.src.com.zoho.crm.api.initializer import Initializer from zohocrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken from zohocrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig from zohocrmsdk.src.com.zoho.crm.api.record import * class MultiThread(threading.Thread): def __init__(self, module_api_name): super().__init__() self.module_api_name = module_api_name def run(self): try: print("Calling Get Records for module: " + self.module_api_name) param_instance = ParameterMap() param_instance.add(GetRecordsParam.fields, "id") response = RecordOperations(self.module_api_name).get_records(param_instance) if response is not None: print('Status Code: ' + str(response.get_status_code())) if response.get_status_code() in [204, 304]: print('No Content' if response.get_status_code() == 204 else 'Not Modified') return response_object = response.get_object() if response_object is not None: if isinstance(response_object, ResponseWrapper): record_list = response_object.get_data() for record in record_list: for key, value in record.get_key_values().items(): print(key + " : " + str(value)) elif isinstance(response_object, APIException): print("Status: " + response_object.get_status().get_value()) print("Code: " + response_object.get_code().get_value()) print("Details") details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) print("Message: " + response_object.get_message().get_value()) except Exception as e: print(e) @staticmethod def call(): logger = Logger.get_instance(level=Logger.Levels.INFO, file_path="/Users/user_name/Documents/python_sdk_log.log") token = OAuthToken(client_id="clientId", client_secret="clientSecret", grant_token="grant_token", refresh_token="refresh_token", redirect_url="redirectURL", id="id") environment = USDataCenter.PRODUCTION() store = DBStore() sdk_config = SDKConfig() resource_path = '/Users/user_name/Documents/python-app' Initializer.initialize(environment=environment, token=token, store=store, sdk_config=sdk_config, resource_path=resource_path, logger=logger) t1 = MultiThread('Leads') t2 = MultiThread('Quotes') t1.start() t2.start() t1.join() t2.join() MultiThread.call() ``` -------------------------------- ### Configure Zoho CRM Notification Settings Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md This snippet shows how to configure notification settings in Zoho CRM. It demonstrates setting the channel ID, events for notifications, and whether to delete events. Two versions are provided to show the change in method names between SDK 7.0 and 8.0. ```python # PYTHON SDK 7.0-v4.0.0 notification = Notification() notification.set_channel_id("1006800211") events = ["Deals.edit"] notification.set_events(events) notification.set_deleteevents(Choice(True)) ``` ```python # PYTHON SDK 8.0-v1.0.0 notification = Notification() notification.set_channel_id("1006800211") events = ["Deals.edit"] notification.set_events(events) notification.set_delete_events(Choice(True)) ``` -------------------------------- ### Get Scoring Rule in Zoho CRM Python SDK Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md Retrieves a scoring rule by its ID. This method's signature changed between SDK versions 7.0 and 8.0, with the 'module' parameter being removed in the latter. It utilizes ScoringRulesOperations and ParameterMap. ```python from zohocrmsdk.src.com.zoho.crm.api.scoring_rules import ScoringRulesOperations, ParameterMap @staticmethod def get_scoring_rule(module, id) : scoring_rules_operations = ScoringRulesOperations() param_instance = ParameterMap() response = scoring_rules_operations.get_scoring_rule(module, id, param_instance) ``` ```python from zohocrmsdk.src.com.zoho.crm.api.scoring_rules import ScoringRulesOperations, ParameterMap @staticmethod def get_scoring_rule(id) : scoring_rules_operations = ScoringRulesOperations() param_instance = ParameterMap() response = scoring_rules_operations.get_scoring_rule(id, param_instance) ``` -------------------------------- ### Initialize Zoho CRM SDK Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/2.0.0/README.md Sets up the Zoho CRM SDK by configuring the environment, authentication token, token store, SDK settings, resource path, logger, and request proxy. This is a crucial step before making API calls. ```python from zohocrmsdk.src.com.zoho.crm.api.dc import USDataCenter from zohocrmsdk.src.com.zoho.api.authenticator.store import DBStore, FileStore from zohocrmsdk.src.com.zoho.api.logger import Logger from zohocrmsdk.src.com.zoho.crm.api.initializer import Initializer from zohocrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken from zohocrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig from zohocrmsdk.src.com.zoho.crm.api.request_proxy import RequestProxy class SDKInitializer(object): @staticmethod def initialize(): logger = Logger.get_instance(level=Logger.Levels.INFO, file_path='/Users/user_name/Documents/python_sdk_log.log') environment = USDataCenter.PRODUCTION() token = OAuthToken(client_id='clientId', client_secret='clientSecret', grant_token='grant_token', refresh_token="refresh_token", redirect_url='redirectURL', id="token_id") # store = FileStore(file_path='/Users/username/Documents/python_sdk_tokens.txt') store = DBStore(host='host_name', database_name='database_name', user_name='user_name', password='password', port_number='port_number', table_name="table_name") config = SDKConfig(auto_refresh_fields=True, pick_list_validation=False, connect_timeout=None, read_timeout=None) resource_path = '/Users/python-app' # request_proxy = RequestProxy(host='host', port=8080) request_proxy = RequestProxy(host='host', port=8080, user='user', password='password') """ Call the static initialize method of Initializer class that takes the following arguments 2 -> Environment instance 3 -> Token instance 4 -> TokenStore instance 5 -> SDKConfig instance 6 -> resource_path 7 -> Logger instance. Default value is None 8 -> RequestProxy instance. Default value is None """ Initializer.initialize(environment=environment, token=token, store=store, sdk_config=config, resource_path=resource_path, logger=logger, proxy=request_proxy) SDKInitializer.initialize() ``` -------------------------------- ### Get Zia Org Enrichments - Python Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md Retrieves multiple Zia Organization Enrichments, optionally with parameters. The method name was updated in SDK 8.0. It utilizes ZiaOrgEnrichmentOperations and a ParameterMap for filtering. The response object contains the list of enrichments. ```python zia_org_enrichment_operations = ZiaOrgEnrichmentOperations() param_instance = ParameterMap() response = zia_org_enrichment_operations.get_zia_org_enrichments(param_instance) response_object = response.get_object() if response_object is not None: if isinstance(response_object, ResponseWrapper): ziaorgenrichment = response_object.get_ziaorgenrichment() ``` ```python zia_org_enrichment_operations = ZiaOrgEnrichmentOperations() param_instance = ParameterMap() response = zia_org_enrichment_operations.get_zia_org_enrichments(param_instance) response_object = response.get_object() if response_object is not None: if isinstance(response_object, ResponseWrapper): ziaorgenrichment = response_object.get_zia_org_enrichment() ``` -------------------------------- ### Configuration Overview Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/2.0.0/README.md Before using the SDK, you need to register your client and authenticate your application with Zoho. This involves setting up mandatory and optional configuration keys. ```APIDOC ## Configuration Before you get started with creating your Python application, you need to register your client and authenticate the app with Zoho. | Mandatory Keys | Optional Keys | |:---------------| :------------ | | token | logger | | environment | store | | | sdk_config | | | proxy | | | resource_path | ---- ``` -------------------------------- ### Get Profiles (Python) Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md Retrieves profile information, including default views, using the Zoho CRM Python SDK. The method get_defaultview was renamed to get_default_view in SDK version 8.0. The code iterates through a list of profiles obtained from a ResponseWrapper. ```python response_handler = response.get_object() if isinstance(response_handler, ResponseWrapper): response_wrapper = response_handler profiles = response_wrapper.get_profiles() for profile in profiles: default_view = profile.get_defaultview() ``` ```python response_handler = response.get_object() if isinstance(response_handler, ResponseWrapper): response_wrapper = response_handler profiles = response_wrapper.get_profiles() for profile in profiles: default_view = profile.get_default_view() ``` -------------------------------- ### Initialize SDK and Switch User for Multi-threading in Zoho CRM Python SDK Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/2.0.0/README.md This code demonstrates initializing the Zoho CRM SDK with specific configurations and then switching users within a multi-threaded context. It handles different environments, authentication tokens, SDK configurations, and optional proxy settings for each user thread. The `run` method processes API requests after user initialization. ```python import threading from zohocrmsdk.src.com.zoho.crm.api.parameter_map import ParameterMap from zohocrmsdk.src.com.zoho.crm.api.dc import USDataCenter, EUDataCenter from zohocrmsdk.src.com.zoho.api.authenticator.store import DBStore from zohocrmsdk.src.com.zoho.api.logger import Logger from zohocrmsdk.src.com.zoho.crm.api.initializer import Initializer from zohocrmsdk.src.com.zoho.api.authenticator.oauth_token import OAuthToken from zohocrmsdk.src.com.zoho.crm.api.record import * from zohocrmsdk.src.com.zoho.crm.api.request_proxy import RequestProxy from zohocrmsdk.src.com.zoho.crm.api.sdk_config import SDKConfig class MultiThread(threading.Thread): def __init__(self, environment, token, module_api_name, sdk_config, proxy=None): super().__init__() self.environment = environment self.token = token self.module_api_name = module_api_name self.sdk_config = sdk_config self.proxy = proxy def run(self): try: Initializer.switch_user(environment=self.environment, token=self.token, sdk_config=self.sdk_config, proxy=self.proxy) param_instance = ParameterMap() param_instance.add(GetRecordsParam.fields, "id") response = RecordOperations(self.module_api_name).get_records(param_instance) if response is not None: print('Status Code: ' + str(response.get_status_code())) if response.get_status_code() in [204, 304]: print('No Content' if response.get_status_code() == 204 else 'Not Modified') return response_object = response.get_object() if response_object is not None: if isinstance(response_object, ResponseWrapper): record_list = response_object.get_data() for record in record_list: for key, value in record.get_key_values().items(): print(key + " : " + str(value)) elif isinstance(response_object, APIException): print("Status: " + response_object.get_status().get_value()) print("Code: " + response_object.get_code().get_value()) print("Details") details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) print("Message: " + response_object.get_message().get_value()) except Exception as e: print(e) @staticmethod def call(): logger = Logger.get_instance(level=Logger.Levels.INFO, file_path="/Users/user_name/Documents/python_sdk_log.log") token1 = OAuthToken(client_id="clientId1", client_secret="clientSecret1", grant_token="Grant Token", refresh_token="refresh_token", id="id") environment1 = USDataCenter.PRODUCTION() store = DBStore() sdk_config_1 = SDKConfig(auto_refresh_fields=True, pick_list_validation=False) resource_path = '/Users/user_name/Documents/python-app' user1_module_api_name = 'Leads' user2_module_api_name = 'Contacts' environment2 = EUDataCenter.SANDBOX() sdk_config_2 = SDKConfig(auto_refresh_fields=False, pick_list_validation=True) token2 = OAuthToken(client_id="clientId2", client_secret="clientSecret2", grant_token="GRANT Token", refresh_token="refresh_token", redirect_url="redirectURL", id="id") request_proxy_user_2 = RequestProxy("host", 8080) Initializer.initialize(environment=environment1, token=token1, store=store, sdk_config=sdk_config_1, resource_path=resource_path, logger=logger) t1 = MultiThread(environment1, token1, user1_module_api_name, sdk_config_1) t2 = MultiThread(environment2, token2, user2_module_api_name, sdk_config_2, request_proxy_user_2) t1.start() t2.start() t1.join() t2.join() MultiThread.call() ``` -------------------------------- ### Get Email Addresses (Python) Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md Retrieves email addresses associated with from addresses using the Zoho CRM Python SDK. The get_email_addresses method was updated to include a new parameter 'user_id' in SDK version 8.0. It requires an instance of FromAddressesOperations. ```python class FromAddresses : @staticmethod def get_email_addresses(): send_mail_operations = FromAddressesOperations() FromAddresses.getEmailAddresses() ``` ```python class FromAddresses: @staticmethod def get_email_addresses(user_id): send_mail_operations = FromAddressesOperations(user_id) user_id = 323132312312 FromAddresses.getEmailAddresses(user_id) ``` -------------------------------- ### Initialize Zoho CRM SDK and Create Records in Python Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/2.0.0/README.md This snippet demonstrates how to initialize the Zoho CRM Python SDK using OAuth token authentication and then create new records for a given module. It includes setting up the environment, defining the record details, and handling the API response, including success and API exceptions. Ensure you replace placeholder credentials with your actual client ID, client secret, and grant token. ```python from zohocrmsdk.src.com.zoho.api.authenticator import OAuthToken from zohocrmsdk.src.com.zoho.crm.api import Initializer, HeaderMap from zohocrmsdk.src.com.zoho.crm.api.dc import USDataCenter from zohocrmsdk.src.com.zoho.crm.api.record import RecordOperations, BodyWrapper, Record, Field, ActionWrapper, SuccessResponse, APIException class CreateRecords: @staticmethod def initialize(): environment = USDataCenter.PRODUCTION() token = OAuthToken(client_id="client_id", client_secret="client_secret", grant_token="grant_token") Initializer.initialize(environment, token) @staticmethod def create_records(module_api_name): """ This method is used to create records of a module and print the response. :param module_api_name: The API Name of the module to create records. """ """ example module_api_name = 'Leads' """ record_operations = RecordOperations(module_api_name) request = BodyWrapper() # List to hold Record instances records_list = [] record = Record() """ Call add_field_value method that takes two arguments Import the zcrmsdk.src.com.zoho.crm.api.record.field file 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list. 2 -> Value """ record.add_field_value(Field.Leads.last_name(), 'Python SDK') record.add_field_value(Field.Leads.first_name(), 'New') record.add_field_value(Field.Leads.company(), 'Zoho') record.add_field_value(Field.Leads.city(), 'City') record.add_field_value(Field.Leads.annual_revenue(), 1231.1) records_list.append(record) request.set_data(records_list) header_instance = HeaderMap() response = record_operations.create_records(request, header_instance) if response is not None: print('Status Code: ' + str(response.get_status_code())) response_object = response.get_object() if response_object is not None: if isinstance(response_object, ActionWrapper): action_response_list = response_object.get_data() for action_response in action_response_list: if isinstance(action_response, SuccessResponse): print("Status: " + action_response.get_status().get_value()) print("Code: " + action_response.get_code().get_value()) print("Details") details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) print("Message: " + action_response.get_message().get_value()) elif isinstance(action_response, APIException): print("Status: " + action_response.get_status().get_value()) print("Code: " + action_response.get_code().get_value()) print("Details") details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) print("Message: " + action_response.get_message().get_value()) elif isinstance(response_object, APIException): print("Status: " + response_object.get_status().get_value()) print("Code: " + response_object.get_code().get_value()) print("Details") details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) print("Message: " + response_object.get_message().get_value()) module_api_name = "Leads" CreateRecords.initialize() CreateRecords.create_records(module_api_name) ``` -------------------------------- ### Get MultiSelectLookup Field Details - Python Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md This snippet demonstrates how to retrieve and print details for a MultiSelectLookup field, including its ID and related list information. It accesses properties like display label, API name, and ID from the related list object. ```python print("Field MultiSelectLookup ConnectedDetails Layouts Id: ", layout.get_id()) related_list = multi_select_lookup.get_related_list() if related_list is not None: print("Field MultiSelectLookup RelatedList DisplayLabel: ", related_list.get_display_label()) print("Field MultiSelectLookup RelatedList APIName: ", related_list.get_api_name()) print("Field MultiSelectLookup RelatedList Id: ", related_list.get_id()) ``` -------------------------------- ### Database Persistence (MySQL) Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/2.0.0/README.md This section explains how to use MySQL for database persistence of authentication tokens. It includes the SQL query to create the necessary table and how to instantiate the DBStore object. ```APIDOC ## Database Persistence (MySQL) ### Description This section explains how to use MySQL for database persistence of authentication tokens. It includes the SQL query to create the necessary table and how to instantiate the DBStore object. ### SQL Table Creation ```sql CREATE TABLE oauthtoken ( id varchar(10) NOT NULL, user_name varchar(255), client_id varchar(255), client_secret varchar(255), refresh_token varchar(255), access_token varchar(255), grant_token varchar(255), expiry_time varchar(20), redirect_url varchar(255), api_domain varchar(255), primary key (id) ) ``` ### Create DBStore Object ```python from zohocrmsdk.src.com.zoho.api.authenticator.store import DBStore # Default instantiation # store = DBStore() # Instantiation with custom parameters store = DBStore(host='host_name', database_name='database_name', user_name='user_name', password='password', port_number='port_number', table_name = "table_name") ``` ``` -------------------------------- ### Get Zia People Enrichment - Python Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md Retrieves a Zia People Enrichment by its ID. Method names were updated in SDK 8.0. This function uses ZiaPeopleEnrichmentOperations and the enrichment ID to fetch the data. The response object provides access to the retrieved enrichment details. ```python zia_people_enrichment_operations = ZiaPeopleEnrichmentOperations() response = zia_people_enrichment_operations.get_zia_people_enrichment(zia_people_enrichment_id) responseObject = response.get_object() if responseObject is not None : if isinstance(responseObject, ResponseWrapper): ziapeopleenrichment = responseObject.get_ziapeopleenrichment() ``` ```python zia_people_enrichment_operations = ZiaPeopleEnrichmentOperations() response = zia_people_enrichment_operations.get_zia_people_enrichment(zia_people_enrichment_id) responseObject = response.get_object() if responseObject is not None : if isinstance(responseObject, ResponseWrapper): ziapeopleenrichment = responseObject.get_zia_people_enrichment() ``` -------------------------------- ### Get Zia Org Enrichment - Python Source: https://github.com/zoho/zohocrm-python-sdk-8.0/blob/main/versions/1.0.0/change_log.md Retrieves a Zia Organization Enrichment by its ID. This method was updated in SDK 8.0 to reflect a name change in the getter method. It requires a ZiaOrgEnrichmentOperations instance and the enrichment ID. It returns a response object from which the enrichment details can be extracted. ```python zia_org_enrichment_operations = ZiaOrgEnrichmentOperations() response = zia_org_enrichment_operations.get_zia_org_enrichment(zia_org_enrichment_id) response_object = response.get_object() if response_object is not None: if isinstance(response_object, ResponseWrapper): ziaorgenrichment = response_object.get_ziaorgenrichment() ``` ```python zia_org_enrichment_operations = ZiaOrgEnrichmentOperations() response = zia_org_enrichment_operations.get_zia_org_enrichment(zia_org_enrichment_id) response_object = response.get_object() if response_object is not None: if isinstance(response_object, ResponseWrapper): ziaorgenrichment = response_object.get_zia_org_enrichment() ```