def upload_file(org_id, absolute_file_path): """ This method is used to upload a CSV file in ZIP format for bulk write API. The response contains the file_id. :param org_id: The unique ID (zgid) of your organization obtained through the Organization API. :param absolute_file_path: The absoluteFilePath of the zip file you want to upload. """ """ example org_id = "673573045" absolute_file_path = "/Users/user_name/Documents/Leads.zip" """ # Get instance of BulkWriteOperations Class bulk_write_operations = BulkWriteOperations() # Get instance of FileBodyWrapper class that will contain the request file file_body_wrapper = FileBodyWrapper() """ StreamWrapper can be initialized in any of the following ways * param 1 -> fileName * param 2 -> Read Stream. """ # stream_wrapper = StreamWrapper(stream=open(absolute_file_path, 'rb')) """ * param 1 -> fileName * param 2 -> Read Stream * param 3 -> Absolute File Path of the file to be attached """ stream_wrapper = StreamWrapper(file_path=absolute_file_path) # Set file to the FileBodyWrapper instance file_body_wrapper.set_file(stream_wrapper) # Get instance of HeaderMap Class header_instance = HeaderMap() # Possible parameters for upload_file operation header_instance.add(UploadFileHeader.feature, "bulk-write") header_instance.add(UploadFileHeader.x_crm_org, org_id) # Call upload_file method that takes FileBodyWrapper instance and header_instance as parameter response = bulk_write_operations.upload_file(file_body_wrapper, header_instance) 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): if response_object.get_status() is not None: # Get the Status print("Status: " + response_object.get_status().get_value()) if response_object.get_code() is not None: # Get the Code print("Code: " + response_object.get_code().get_value()) print("Details") # Get the details dict details = response_object.get_details() if details is not None: for key, value in details.items(): print(key + ' : ' + str(value)) if response_object.get_error_message() is not None: # Get the ErrorMessage print("Error Message: " + response_object.get_error_message().get_value()) # Get the ErrorCode print('Error Code: ' + str(response_object.get_error_code())) if response_object.get_x_error() is not None: # Get the XError print('XError: ' + response_object.get_x_error().get_value()) if response_object.get_info() is not None: # Get the Info print("Info: " + response_object.get_info().get_value()) if response_object.get_x_info() is not None: # Get the XInfo print("XInfo: " + response_object.get_x_info().get_value()) if response_object.get_message() is not None: # Get the Message print("Message: " + response_object.get_message().get_value()) print('HttpStatus: ' + response_object.get_http_status())
def upload_organization_photo(absolute_file_path): """ This method is used to upload the brand logo or image of the organization and print the response. :param absolute_file_path: The absolute file path of the file to be attached """ """ example absolute_file_path = "/Users/user_name/Desktop/logo.png"; """ # Get instance of OrgOperations Class org_operations = OrgOperations() # Get instance of FileBodyWrapper class that will contain the request file request = FileBodyWrapper() """ StreamWrapper can be initialized in any of the following ways * param 1 -> fileName * param 2 -> Read Stream. """ # stream_wrapper = StreamWrapper(stream=open(absolute_file_path, 'rb')) """ * param 1 -> fileName * param 2 -> Read Stream * param 3 -> Absolute File Path of the file to be attached """ stream_wrapper = StreamWrapper(file_path=absolute_file_path) # Set file to the FileBodyWrapper instance request.set_file(stream_wrapper) # Call upload_organization_photo method that takes FileBodyWrapper instance as parameter response = org_operations.upload_organization_photo(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 SuccessResponse 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 upload_files(): """ This method is used to upload files and print the response. """ # Get instance of FileOperations Class file_operations = FileOperations() # Get instance of ParameterMap Class param_instance = ParameterMap() # Possible parameters of UploadFile operation param_instance.add(UploadFilesParam.type, "inline") # Get instance of FileBodyWrapper Class that will contain the request body request = BodyWrapper() """ StreamWrapper can be initialized in any of the following ways * param 1 -> fileName * param 2 -> Read Stream. """ # stream_wrapper = StreamWrapper(stream=open(absolute_file_path, 'rb')) """ * param 1 -> fileName * param 2 -> Read Stream * param 3 -> Absolute File Path of the file to be attached """ stream_wrapper1 = StreamWrapper( file_path='/Users/Documents/download.png') stream_wrapper2 = StreamWrapper( file_path='/Users/Documents/download.png') stream_wrapper3 = StreamWrapper( file_path='/Users/Documents/download.png') # Set list of files to the BodyWrapper instance request.set_file([stream_wrapper1, stream_wrapper2, stream_wrapper3]) # Call upload_files method that takes BodyWrapper instance and ParameterMap instance as parameter. response = file_operations.upload_files(request, param_instance) 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 upload_attachments(module_api_name, record_id, absolute_file_path): """ This method is used to upload attachments and print the response :param module_api_name: The API Name of the record's module :param record_id: The ID of the record to upload attachment :param absolute_file_path: The absolute file path of the file to be attached """ """ example module_api_name= "Leads" record_id = 3409643000002267003 absolute_file_path = "/Users/user-name/Documents/image.jpg"; """ # Get instance of AttachmentsOperations Class that takes module_api_name and record_id as parameters attachments_operations = AttachmentsOperations(module_api_name, record_id) # Get instance of FileBodyWrapper class that will contain the request file file_body_wrapper = FileBodyWrapper() """ StreamWrapper can be initialized in any of the following ways * param 1 -> fileName * param 2 -> Read Stream. """ # stream_wrapper = StreamWrapper(stream=open(absolute_file_path, 'rb')) """ * param 1 -> fileName * param 2 -> Read Stream * param 3 -> Absolute File Path of the file to be attached """ stream_wrapper = StreamWrapper(file_path=absolute_file_path) # Set file to the FileBodyWrapper instance file_body_wrapper.set_file(stream_wrapper) # Call upload_attachment method that takes FileBodyWrapper instance as parameter response = attachments_operations.upload_attachment(file_body_wrapper) 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())