def create_bulk_write_job(module_api_name, file_id): """ This method is used to create bulk write job with the uploaded file ID :param module_api_name: The API Name of the module. :param file_id: The ID of the uploaded file to create BulkWrite Job. example module_api_name = 'Leads' file_id = 34096432212140 """ # Get instance of BulkWriteOperations Class bulk_write_operations = BulkWriteOperations() # Get instance of RequestWrapper Class that will contain the request body request = RequestWrapper() # Get instance of CallBack Class call_back = CallBack() # Set valid callback URL call_back.set_url("https://www.example.com/callback") # Set the HTTP method of the callback URL. The allowed value is post. call_back.set_method(Choice('post')) # The Bulk Read Job's details is posted to this URL on successful completion / failure of the job. request.set_callback(call_back) # Set the charset of the uploaded file request.set_character_encoding('UTF-8') # To set the type of operation you want to perform on the bulk write job. request.set_operation(Choice('insert')) resources = [] # Get instance of Resource Class resource = Resource() # To set the type of module that you want to import. The value is data. resource.set_type(Choice('data')) # To set API name of the module that you select for bulk write job. # Specifies the API Name of the module to be read. module = Module() module.set_api_name(module_api_name) resource.set_module(module) # To set the fileId obtained from file upload API. resource.set_file_id(file_id) # True - Ignores the empty values.The default value is false. resource.set_ignore_empty(True) # To set a field as a unique field or ID of a record. # resource.set_find_by('Email') field_mappings = [] # Get instance of FieldMapping Class field_mapping = FieldMapping() # To set API name of the field present in Zoho module object that you want to import. field_mapping.set_api_name('Email') # To set the column index of the field you want to map to the CRM field. field_mapping.set_index(0) field_mappings.append(field_mapping) field_mapping = FieldMapping() # To set API name of the field present in Zoho module object that you want to import. field_mapping.set_api_name('First_Name') # To set the column index of the field you want to map to the CRM field. field_mapping.set_index(1) field_mappings.append(field_mapping) field_mapping = FieldMapping() # To set API name of the field present in Zoho module object that you want to import. field_mapping.set_api_name('Last_Name') # To set the column index of the field you want to map to the CRM field. field_mapping.set_index(2) field_mappings.append(field_mapping) field_mapping = FieldMapping() # To set API name of the field present in Zoho module object that you want to import. field_mapping.set_api_name('Phone') # To set the column index of the field you want to map to the CRM field. field_mapping.set_index(3) field_mappings.append(field_mapping) field_mapping = FieldMapping() field_mapping.set_api_name('Website') default_value = dict() default_value["value"] = "www.zohoapis.com" # To set the default value for an empty column in the uploaded file. field_mapping.set_default_value(default_value) field_mappings.append(field_mapping) resource.set_field_mappings(field_mappings) module = Module() module.set_api_name(module_api_name) resource.set_module(module) resources.append(resource) # Set the list of resources to RequestWrapper instance request.set_resource(resources) # Call create_bulk_write_job method that takes RequestWrapper instance as parameter response = bulk_write_operations.create_bulk_write_job(request) if response is not None: # Get the status code from response print('Status Code: ' + str(response.get_status_code())) # Get object from response response_object = response.get_object() if response_object is not None: # Check if expected ActionWrapper instance is received. if isinstance(response_object, SuccessResponse): # Get the Status print("Status: " + response_object.get_status().get_value()) # Get the Code print("Code: " + response_object.get_code().get_value()) print("Details") # Get the details dict details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + response_object.get_message().get_value()) # Check if the request returned an exception elif isinstance(response_object, APIException): # Get the Status print("Status: " + response_object.get_status().get_value()) # Get the Code print("Code: " + response_object.get_code().get_value()) print("Details") # Get the details dict details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + response_object.get_message().get_value())
def create_bulk_read_job(module_api_name): """ This method is used to create a bulk read job to export records. :param module_api_name: The API Name of the record's module """ """ example module_api_name = 'Leads' """ # Get instance of BulkReadOperations Class bulk_read_operations = BulkReadOperations() # Get instance of RequestWrapper Class that will contain the request body request = RequestWrapper() # Get instance of CallBack Class call_back = CallBack() # Set valid callback URL call_back.set_url("https://www.brightermonday.co.ke") # Set the HTTP method of the callback URL. The allowed value is post. call_back.set_method(Choice('post')) # The Bulk Read Job's details is posted to this URL on successful completion / failure of the job. request.set_callback(call_back) # Get instance of Query Class query = Query() # Specifies the API Name of the module to be read. query.set_module(module_api_name) # Specifies the unique ID of the custom view, whose records you want to export. # query.set_cvid('3409643000000087501') # List of field names field_api_names = ['Converted Leads'] # Specifies the API Name of the fields to be fetched query.set_fields(field_api_names) # To set page value, By default value is 1. query.set_page(1) # Get instance of Criteria Class # criteria = Criteria() # To set API name of a field # criteria.set_api_name('Created Time') # To set comparator(eg: equal, greater_than) # criteria.set_comparator(Choice('between')) # time = ["2020-06-03T17:31:48+05:30", "2020-06-03T17:31:48+05:30"] # To set the value to be compared # criteria.set_value(time) # To filter the records to be exported # query.set_criteria(criteria) # Set the query object request.set_query(query) # Specify the value for this key as "ics" to export all records in the Events module as an ICS file. # request.set_file_type(Choice('ics')) # Call create_bulk_read_job method that takes RequestWrapper instance as parameter response = bulk_read_operations.create_bulk_read_job(request) if response is not None: # Get the status code from response print('Status Code: ' + str(response.get_status_code())) # Get object from response response_object = response.get_object() if response_object is not None: # Check if expected ActionWrapper instance is received. if isinstance(response_object, ActionWrapper): action_response_list = response_object.get_data() for action_response in action_response_list: # Check if the request is successful if isinstance(action_response, SuccessResponse): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(action_response, APIException): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(response_object, APIException): # Get the Status print("Status: " + response_object.get_status().get_value()) # Get the Code print("Code: " + response_object.get_code().get_value()) print("Details") # Get the details dict details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + response_object.get_message().get_value())
def create_bulk_read_job(module_api_name): """ This method is used to create a bulk read job to export records. :param module_api_name: The API Name of the record's module """ """ example module_api_name = 'Leads' """ # Get instance of BulkReadOperations Class bulk_read_operations = BulkReadOperations() # Get instance of RequestWrapper Class that will contain the request body request = RequestWrapper() # Get instance of CallBack Class call_back = CallBack() # Set valid callback URL call_back.set_url("https://www.example.com/callback") # Set the HTTP method of the callback URL. The allowed value is post. call_back.set_method(Choice('post')) # The Bulk Read Job's details is posted to this URL on successful completion / failure of the job. request.set_callback(call_back) # Get instance of Query Class query = Query() # Specifies the API Name of the module to be read. module = Module() module.set_api_name(module_api_name) query.set_module(module) # Specifies the unique ID of the custom view, whose records you want to export. # query.set_cvid('34096430087501') # List of field names field_api_names = ['Last_Name'] # Specifies the API Name of the fields to be fetched # query.set_fields(field_api_names) # To set page value, By default value is 1. query.set_page(1) # Get instance of Criteria Class criteria = Criteria() # To set comparator(eg: equal, greater_than) criteria.set_group_operator(Choice('or')) criteria_array = [] group11 = Criteria() group11.set_group_operator(Choice("and")) group_array11 = [] group111 = Criteria() field1 = Field() field1.set_api_name("Company") group111.set_field(field1) group111.set_comparator(Choice("equal")) group111.set_value("Zoho") group_array11.append(group111) group112 = Criteria() field2 = Field() field2.set_api_name("Owner") group112.set_field(field2) group112.set_comparator(Choice("in")) group112.set_value(["34770610173021"]) group_array11.append(group112) group11.set_group(group_array11) criteria_array.append(group11) group12 = Criteria() group12.set_group_operator(Choice("or")) group_array12 = [] group121 = Criteria() field3 = Field() field3.set_api_name("Paid") group121.set_field(field3) group121.set_comparator(Choice("equal")) group121.set_value(True) group_array12.append(group121) group122 = Criteria() field4 = Field() field4.set_api_name("Created_Time") group122.set_field(field4) group122.set_comparator(Choice("between")) time = ["2020-06-03T17:31:48+05:30", "2020-06-03T17:31:48+05:30"] # To set the value to be compared group122.set_value(time) group_array12.append(group122) group12.set_group(group_array12) criteria_array.append(group12) criteria.set_group(criteria_array) # To filter the records to be exported query.set_criteria(criteria) # Set the query object request.set_query(query) # Specify the value for this key as "ics" to export all records in the Events module as an ICS file. # request.set_file_type(Choice('ics')) # Call create_bulk_read_job method that takes RequestWrapper instance as parameter response = bulk_read_operations.create_bulk_read_job(request) if response is not None: # Get the status code from response print('Status Code: ' + str(response.get_status_code())) # Get object from response response_object = response.get_object() if response_object is not None: # Check if expected ActionWrapper instance is received. if isinstance(response_object, ActionWrapper): action_response_list = response_object.get_data() for action_response in action_response_list: # Check if the request is successful if isinstance(action_response, SuccessResponse): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(action_response, APIException): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(response_object, APIException): # Get the Status print("Status: " + response_object.get_status().get_value()) # Get the Code print("Code: " + response_object.get_code().get_value()) print("Details") # Get the details dict details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + response_object.get_message().get_value())
def update_base_currency(): """ This method is used to update base currency details. """ # Get instance of CurrenciesOperations Class currencies_operations = CurrenciesOperations() # Get instance of BaseCurrencyWrapper Class that will contain the request body request = BaseCurrencyWrapper() # Get instance of Currency Class currency = ZCRMCurrency() # To set currency Id currency.set_id(3409643000002293001) # To set the position of the ISO code in the currency. # True: Display ISO code before the currency value. # False: Display ISO code after the currency value. currency.set_prefix_symbol(True) # To set the symbol of the currency. currency.set_symbol("Af") # To set the rate at which the currency has to be exchanged for home currency. currency.set_exchange_rate("1.000000000") # To set the status of the currency. # True: The currency is active. # False: The currency is inactive. currency.set_is_active(True) format = Format() # It can be a Period or Comma, depending on the currency. format.set_decimal_separator(Choice('Period')) # It can be a Period, Comma, or Space, depending on the currency. format.set_thousand_separator(Choice('Comma')) # To set the number of decimal places allowed for the currency. It can be 0, 2, or 3. format.set_decimal_places(Choice('3')) # To set the format of the currency currency.set_format(format) # Set the Currency in BodyWrapper instance request.set_base_currency(currency) # Call update_base_currency method that takes BaseCurrencyWrapper instance as parameter response = currencies_operations.update_base_currency(request) if response is not None: # Get the status code from response print('Status Code: ' + str(response.get_status_code())) # Get object from response response_object = response.get_object() if response_object is not None: # Check if expected BaseCurrencyActionWrapper instance is received. if isinstance(response_object, BaseCurrencyActionWrapper): # Get the obtained ActionResponse instance action_response = response_object.get_base_currency() # Check if the request is successful if isinstance(action_response, SuccessResponse): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(action_response, APIException): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(response_object, APIException): # Get the Status print("Status: " + response_object.get_status().get_value()) # Get the Code print("Code: " + response_object.get_code().get_value()) print("Details") # Get the details dict details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + response_object.get_message().get_value())
def add_currencies(): """ This method is used to add new currencies to your organization. """ # Get instance of CurrenciesOperations Class currencies_operations = CurrenciesOperations() # Get instance of BodyWrapper Class that will contain the request body request = BodyWrapper() # List to hold Currency instances currencies_list = [] # Get instance of Currency Class currency = ZCRMCurrency() # To set the position of the ISO code in the currency. # True: Display ISO code before the currency value. # False: Display ISO code after the currency value. currency.set_prefix_symbol(True) # To set the name of the currency. currency.set_name("Angolan Kwanza - AOA") # To set the ISO code of the currency. currency.set_iso_code("AOA") # To set the symbol of the currency. currency.set_symbol("Kz") # To set the rate at which the currency has to be exchanged for home currency. currency.set_exchange_rate("20.") # To set the status of the currency. # True: The currency is active. # False: The currency is inactive. currency.set_is_active(True) format = Format() # It can be a Period or Comma, depending on the currency. format.set_decimal_separator(Choice('Period')) # It can be a Period, Comma, or Space, depending on the currency. format.set_thousand_separator(Choice('Comma')) # To set the number of decimal places allowed for the currency. It can be 0, 2, or 3. format.set_decimal_places(Choice('2')) # To set the format of the currency currency.set_format(format) currencies_list.append(currency) # Set the list to Currency in BodyWrapper instance request.set_currencies(currencies_list) # Call add_currencies method that takes BodyWrapper instance as parameter response = currencies_operations.add_currencies(request) if response is not None: # Get the status code from response print('Status Code: ' + str(response.get_status_code())) # Get object from response response_object = response.get_object() if response_object is not None: # Check if expected ActionWrapper instance is received. if isinstance(response_object, ActionWrapper): # Get the obtained ActionResponse instances action_response_list = response_object.get_currencies() for action_response in action_response_list: # Check if the request is successful if isinstance(action_response, SuccessResponse): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(action_response, APIException): # Get the Status print("Status: " + action_response.get_status().get_value()) # Get the Code print("Code: " + action_response.get_code().get_value()) print("Details") # Get the details dict details = action_response.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + action_response.get_message().get_value()) # Check if the request returned an exception elif isinstance(response_object, APIException): # Get the Status print("Status: " + response_object.get_status().get_value()) # Get the Code print("Code: " + response_object.get_code().get_value()) print("Details") # Get the details dict details = response_object.get_details() for key, value in details.items(): print(key + ' : ' + str(value)) # Get the Message print("Message: " + response_object.get_message().get_value())