Esempio n. 1
0
 def search_records_pdc(self, searchColumn, searchValue, selectColumns='leads(First Name,Last Name,Company)'):
     """
     
     https://www.zoho.com/crm/help/api/getsearchrecordsbypdc.html
     
     @param searchColumn: String. Which Predefined column to search.
     
     @param searchValue: String. Value to search for.
     
     @param selectColumns: String. What columns to query. For example query format,
         see API doc. Default is leads(First Name,Last Name,Company).
     
     @return: Python list of dictionarizied leads. Each dictionary contains lead key-value pairs. LEADID column is always included.
     
     """
     self.ensure_opened()
     
     
     post_params = {
         "selectColumns" : selectColumns,
         "searchColumn": searchColumn,
         "searchValue": searchValue,
         "newFormat" : 2
     }
     
     response = self.do_call("https://crm.zoho.com/crm/private/json/Leads/getSearchRecordsByPDC", post_params)
     
     # raw data looks like {'response': {'result': {'Leads': {'row': [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...
     data =  decode_json(response)
     
     return self._parse_json_response(data)
Esempio n. 2
0
    def get_records(self, selectColumns='leads(First Name,Last Name,Company)', parameters={}):
        """ 

        http://zohocrmapi.wiki.zoho.com/getRecords-Method.html

        @param selectColumns: String. What columns to query. For example query format,
            see API doc. Default is leads(First Name,Last Name,Company).

        @param parameters: Dictionary of filtering parameters which are part of HTTP POST to Zoho.
            For example parameters see Zoho CRM API docs.

        @return: Python list of dictionarizied leads. Each dictionary contains lead key-value pairs. LEADID column is always included.

        """
        self.ensure_opened()

        post_params = {
            "selectColumns" : selectColumns,
            "newFormat" : 2
        }

        post_params.update(parameters)

        response = self.do_call("https://crm.zoho.com/crm/private/json/Leads/getRecords", post_params)
        data =  decode_json(response)

        return self._parse_json_response(data)
Esempio n. 3
0
    def search_records(self, module, searchCondition, selectColumns='leads(First Name,Last Name,Company)', parameters={}):
        """
        
        https://www.zoho.com/crm/help/api/getsearchrecords.html
        
        @param module: String. type of the module (Leads, Potentials, Accounts..).

        @param searchCondition: String. Search condition (see ZOHO API doc for details).
        
        @param selectColumns: String. What columns to query. For example query format,
            see API doc. Default is leads(First Name,Last Name,Company).
        
        @param parameters: dictionary. extra parameters like for pagination.

        @return: Python list of dictionarizied leads. Each dictionary contains lead key-value pairs. LEADID column is always included.
        
        """
        self.ensure_opened()
        
        
        post_params = {
            "selectColumns" : selectColumns,
            "searchCondition": searchCondition,
            "newFormat" : 2
        }
        post_params.update(parameters)
        
        response = self.do_call("https://crm.zoho.com/crm/private/json/"+module+"/getSearchRecords", post_params)
        
        # raw data looks like {'response': {'result': {'Leads': {'row': [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...
        data =  decode_json(response)
        
        return self._parse_json_response(data, module)
Esempio n. 4
0
    def get_record_by_id(self, id, module="Leads"):
        """
        
        https://www.zoho.com/crm/help/api/getrecordbyid.html
        
        @param id: String. Id to fetch.

        @param module: String. Type of module (default is Leads)
        
        @return: Python dictionary which contains lead key-value pairs.
        
        """
        self.ensure_opened()
        
        
        post_params = {
            "id": id,
            "newFormat" : 2
        }
        
        response = self.do_call("https://crm.zoho.com/crm/private/json/"+module+"/getRecordById", post_params)
        
        # raw data looks like {'response': {'result': {'Leads': {'row': [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...
        data =  decode_json(response)
        
        parsed = self._parse_json_response(data, module)
        
        return parsed[0] if len(parsed) else None
Esempio n. 5
0
    def search_records(self,
                       searchCondition,
                       selectColumns='leads(First Name,Last Name,Company)'):
        """

        https://www.zoho.com/crm/help/api/getsearchrecords.html

        @param searchCondition: String. Search condition (see ZOHO API doc for details).

        @param selectColumns: String. What columns to query. For example query format,
            see API doc. Default is leads(First Name,Last Name,Company).

        @return: Python list of dictionarizied leads. Each dictionary contains lead key-value pairs. LEADID column is always included.

        """
        self.ensure_opened()

        post_params = {
            "selectColumns": selectColumns,
            "searchCondition": searchCondition,
            "newFormat": 2
        }

        response = self.do_call(
            "https://crm.zoho.com/crm/private/json/Leads/getSearchRecords",
            post_params)

        # raw data looks like {'response': {'result': {'Leads': {'row': [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...
        data = decode_json(response)

        return self._parse_json_response(data)
Esempio n. 6
0
    def get_records(self,
                    selectColumns='leads(First Name,Last Name,Company)',
                    parameters={}):
        """

        http://zohocrmapi.wiki.zoho.com/getRecords-Method.html

        @param selectColumns: String. What columns to query. For example query format,
            see API doc. Default is leads(First Name,Last Name,Company).

        @param parameters: Dictionary of filtering parameters which are part of HTTP POST to Zoho.
            For example parameters see Zoho CRM API docs.

        @return: Python list of dictionarizied leads. Each dictionary contains lead key-value pairs. LEADID column is always included.

        """
        self.ensure_opened()

        post_params = {"selectColumns": selectColumns, "newFormat": 2}

        post_params.update(parameters)

        response = self.do_call(
            "https://crm.zoho.com/crm/private/json/Leads/getRecords",
            post_params)

        # raw data looks like {'response': {'result': {'Leads': {'row': [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...
        data = decode_json(response)

        return self._parse_json_response(data)
Esempio n. 7
0
    def get_records(self, table="leads", columns=[], parameters={}):
        """ 
        
        http://zohocrmapi.wiki.zoho.com/getRecords-Method.html
        
        @param selectColumns: String. What columns to query. For example query format,
            see API doc. Default is leads(First Name,Last Name,Company).
        
        @param parameters: Dictionary of filtering parameters which are part of HTTP POST to Zoho.
            For example parameters see Zoho CRM API docs.
        
        @return: Python list of dictionarizied leads. Each dictionary contains lead key-value pairs. LEADID column is always included.

        """

        self.ensure_opened()

        if isinstance(columns, dict):
            columns = ",".join(columns)
            select_columns = "%s(%s)" % (resource, columns)
        else:
            select_columns = "All"

        resource = table.capitalize()

        post_params = {
            "selectColumns": select_columns,
            "newFormat": 2
        }
        post_params.update(parameters)

        url = "https://crm.zoho.com/crm/private/json/%s/getRecords" % resource
        response = self.do_call(url, post_params)
        
        # raw data looks like {'response': {'result': {'Leads': {'row': [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...
        data =  decode_json(response)
        
        # Sanify output data to more Python-like format
        output = []
        for row in data["response"]["result"][resource]["row"]:
            item = {}
            for cell in row["FL"]:
                item[cell["val"]] = cell["content"]
            
            output.append(item)
            
        return output
Esempio n. 8
0
 def get_notes_for_entity(self, entity_id):
     post_params = {
         "newFormat": 1,
         "id": entity_id,
         "parentModule": "All"
     }
     url = "https://crm.zoho.com/crm/private/json/Notes/getRelatedRecords"
     response = self.do_call(url, post_params)
     data = decode_json(response)
     output = []
     for row in data["response"]["result"]["Notes"]["row"]:
         item = {}
         for cell in row["FL"]:
             item[cell["val"]] = cell["content"]
         
         output.append(item)
         
     return output
Esempio n. 9
0
    def search_records_by_pdc(self, column, value, select_columns=None):
        """
        Search records by pre-defined columns

        """
        select_columns = select_columns if select_columns else self.select_columns
        url = "https://crm.zoho.com/crm/private/json/Leads/getSearchRecordsByPDC"
        data = {
            "selectColumns": select_columns,
            "newFormat": 2,
            "searchColumn": column,
            "searchValue": value
        }

        response = self.do_call(url, data)
        json = decode_json(response)

        return json
Esempio n. 10
0
    def get_related_records(self, parent_id, module="Leads", parent_module="Campaigns"):
        """

        Get all the "Leads" related to the "Campaigns" identified by "parent_id"

        https://crm.zoho.com/crm/private/json/Leads/getRelatedRecords?newFormat=1&authtoken=sbdjEDBDJ1323&scope=crmapi&parentModule=Campaigns&id=121212121

        """
        self.ensure_opened()

        post_params = {
            "id": parent_id,
            "newFormat" : 2,
            "parentModule": parent_module
        }

        response = self.do_call("https://crm.zoho.com/crm/private/json/"+module+"/getRelatedRecords", post_params)
        data =  decode_json(response)

        return self._parse_json_response(data, module)
Esempio n. 11
0
    def _parse_json_response(self, response, record_name):
        # raw data looks like {'response': {'result': {'Leads': {'row':
        # [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...

        data = decode_json(response)

        def parse_row(row):
            item = {}
            if type(row["FL"]) == list:
                for cell in row["FL"]:
                    item[cell["val"]] = cell["content"]
            elif type(row["FL"]) == dict:
                cell = row["FL"]
                item[cell["val"]] = cell["content"]
            else:
                raise ZohoException("Unknown structure to row '%s'" % row)
            return item

        # Sanify output data to more Python-like format

        if data["response"].has_key("nodata"):
            return []

        # are there times when there's 'response', no 'nodata'
        # that would require explicit checking for 'result' key??
        output = []
        rows = data["response"]["result"][record_name]["row"]
        if type(rows) == list:
            for row in rows:
                item = parse_row(row)
                output.append(item)
        elif type(rows) == dict:
            item = parse_row(rows)
            output.append(item)
        else:
            raise ZohoException("Unknown structure to rows '%s'" % rows)
        return output
Esempio n. 12
0
    def get_potentials_for_contact(self, contact_id):
        post_params = {
            "id": contact_id,
            "newFormat": 1,
            "parentModule": "Contacts"
        }

        url = "https://crm.zoho.com/crm/private/json/Potentials/getRelatedRecords"
        response = self.do_call(url, post_params)

        data = decode_json(response)
        # Sanify output data to more Python-like format
        output = []
        if type(data["response"]["result"]["Potentials"]["row"]) is dict:
            data["response"]["result"]["Potentials"]["row"] = [data["response"]["result"]["Potentials"]["row"]]
        for row in data["response"]["result"]["Potentials"]["row"]:
            item = {}
            print row
            for cell in row["FL"]:
                item[cell["val"]] = cell["content"]
            
            output.append(item)
            
        return output
Esempio n. 13
0
    def _parse_json_response(self, response, record_name):
        # raw data looks like {'response': {'result': {'Leads': {'row':
        # [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...

        data =  decode_json(response)

        def parse_row(row):
            item = {}
            if type(row["FL"]) == list:
                for cell in row["FL"]:
                    item[cell["val"]] = cell["content"]
            elif type(row["FL"]) == dict:
                cell = row["FL"]
                item[cell["val"]] = cell["content"]
            else:
                raise ZohoException("Unknown structure to row '%s'" % row)
            return item
        # Sanify output data to more Python-like format

        if data["response"].has_key("nodata"):
            return []

        # are there times when there's 'response', no 'nodata'
        # that would require explicit checking for 'result' key??
        output = []
        rows = data["response"]["result"][record_name]["row"]
        if type(rows) == list:
            for row in rows:
                item = parse_row(row)
                output.append(item)
        elif type(rows) == dict:
            item = parse_row(rows)
            output.append(item)
        else:
            raise ZohoException("Unknown structure to rows '%s'" % rows)
        return output
Esempio n. 14
0
    def get_record_by_id(self, id):
        """

        https://www.zoho.com/crm/help/api/getrecordbyid.html

        @param id: String. Lead id to fetch.

        @return: Python dictionary which contains lead key-value pairs.

        """
        self.ensure_opened()

        post_params = {"id": id, "newFormat": 2}

        response = self.do_call(
            "https://crm.zoho.com/crm/private/json/Leads/getRecordById",
            post_params)

        # raw data looks like {'response': {'result': {'Leads': {'row': [{'FL': [{'content': '177376000000142085', 'val': 'LEADID'}, ...
        data = decode_json(response)

        parsed = self._parse_json_response(data)

        return parsed[0] if len(parsed) else None