2014-09-03 106 views
0

我正在嘗試使用python 2.7編寫一個小應用程序,以便我的洞察力帳戶接收所有具有「測試」標籤的聯繫人。兒童項目的OData過濾器

我使用提供的代碼示例進行了實驗,它工作得很好,但僅適用於頂級元素。

contacts = i.getContacts(top=200) # returns the top 200 contacts 
contacts = i.getContacts(orderby='FIRST_NAME desc', top=200) # returns the top 200 contacts, with first name descending order 
contacts = i.getContacts(top=200, skip=200) # return 200 records, after skipping the first 200 records 
contacts = i.getContacts(filters=['FIRST_NAME=\'Brian\'']) # get contacts where FIRST_NAME='Brian' 

我希望能夠獲得與TAG_NAME「測試」的所有聯繫人。

contacts = i.getContacts(filters=['TAG_NAME=\'test\'']) #does not work 

我沒有找到任何方法來實現我的目標,如果能幫助我,我將非常感激! :)

響應正文格式:

{ 
    "CONTACT_ID": 1, 
    "SALUTATION": "sample string 2", 
    "FIRST_NAME": "sample string 3", 
    "LAST_NAME": "sample string 4", 
    "BACKGROUND": "sample string 5", 
    "IMAGE_URL": "sample string 6", 
    "DEFAULT_LINKED_ORGANISATION": 1, 
    "DATE_CREATED_UTC": "2014-09-03 02:36:08", 
    "DATE_UPDATED_UTC": "2014-09-03 02:36:08", 
    "VISIBLE_TO": "sample string 9", 
    "VISIBLE_TEAM_ID": 1, 
    "VISIBLE_USER_IDS": "sample string 10", 
    "CUSTOMFIELDS": [ 
    { 
     "CUSTOM_FIELD_ID": "sample string 1", 
     "FIELD_VALUE": {} 
    }, 
    { 
     "CUSTOM_FIELD_ID": "sample string 1", 
     "FIELD_VALUE": {} 
    }, 
    { 
     "CUSTOM_FIELD_ID": "sample string 1", 
     "FIELD_VALUE": {} 
    } 
    ], 
    "ADDRESSES": [ 
    { 
     "ADDRESS_ID": 1, 
     "ADDRESS_TYPE": "sample string 1", 
     "STREET": "sample string 2", 
     "CITY": "sample string 3", 
     "STATE": "sample string 4", 
     "POSTCODE": "sample string 5", 
     "COUNTRY": "sample string 6" 
    }, 
    { 
     "ADDRESS_ID": 1, 
     "ADDRESS_TYPE": "sample string 1", 
     "STREET": "sample string 2", 
     "CITY": "sample string 3", 
     "STATE": "sample string 4", 
     "POSTCODE": "sample string 5", 
     "COUNTRY": "sample string 6" 
    }, 
    { 
     "ADDRESS_ID": 1, 
     "ADDRESS_TYPE": "sample string 1", 
     "STREET": "sample string 2", 
     "CITY": "sample string 3", 
     "STATE": "sample string 4", 
     "POSTCODE": "sample string 5", 
     "COUNTRY": "sample string 6" 
    } 
    ], 
    "CONTACTINFOS": [ 
    { 
     "CONTACT_INFO_ID": 1, 
     "TYPE": "sample string 1", 
     "SUBTYPE": "sample string 2", 
     "LABEL": "sample string 3", 
     "DETAIL": "sample string 4" 
    }, 
    { 
     "CONTACT_INFO_ID": 1, 
     "TYPE": "sample string 1", 
     "SUBTYPE": "sample string 2", 
     "LABEL": "sample string 3", 
     "DETAIL": "sample string 4" 
    }, 
    { 
     "CONTACT_INFO_ID": 1, 
     "TYPE": "sample string 1", 
     "SUBTYPE": "sample string 2", 
     "LABEL": "sample string 3", 
     "DETAIL": "sample string 4" 
    } 
    ], 
    "DATES": [ 
    { 
     "DATE_ID": 1, 
     "OCCASION_NAME": "sample string 1", 
     "OCCASION_DATE": "2014-09-03 02:36:08", 
     "REPEAT_YEARLY": true, 
     "CREATE_TASK_YEARLY": true 
    }, 
    { 
     "DATE_ID": 1, 
     "OCCASION_NAME": "sample string 1", 
     "OCCASION_DATE": "2014-09-03 02:36:08", 
     "REPEAT_YEARLY": true, 
     "CREATE_TASK_YEARLY": true 
    }, 
    { 
     "DATE_ID": 1, 
     "OCCASION_NAME": "sample string 1", 
     "OCCASION_DATE": "2014-09-03 02:36:08", 
     "REPEAT_YEARLY": true, 
     "CREATE_TASK_YEARLY": true 
    } 
    ], 
    "TAGS": [ 
    { 
     "TAG_NAME": "sample string 1" 
    }, 
    { 
     "TAG_NAME": "sample string 1" 
    }, 
    { 
     "TAG_NAME": "sample string 1" 
    } 
    ], 
    "LINKS": [ 
    { 
     "LINK_ID": 1, 
     "CONTACT_ID": 1, 
     "OPPORTUNITY_ID": 1, 
     "ORGANISATION_ID": 1, 
     "PROJECT_ID": 1, 
     "SECOND_PROJECT_ID": 1, 
     "SECOND_OPPORTUNITY_ID": 1, 
     "ROLE": "sample string 1", 
     "DETAILS": "sample string 2" 
    }, 
    { 
     "LINK_ID": 1, 
     "CONTACT_ID": 1, 
     "OPPORTUNITY_ID": 1, 
     "ORGANISATION_ID": 1, 
     "PROJECT_ID": 1, 
     "SECOND_PROJECT_ID": 1, 
     "SECOND_OPPORTUNITY_ID": 1, 
     "ROLE": "sample string 1", 
     "DETAILS": "sample string 2" 
    }, 
    { 
     "LINK_ID": 1, 
     "CONTACT_ID": 1, 
     "OPPORTUNITY_ID": 1, 
     "ORGANISATION_ID": 1, 
     "PROJECT_ID": 1, 
     "SECOND_PROJECT_ID": 1, 
     "SECOND_OPPORTUNITY_ID": 1, 
     "ROLE": "sample string 1", 
     "DETAILS": "sample string 2" 
    } 
    ], 
    "CONTACTLINKS": [ 
    { 
     "CONTACT_LINK_ID": 1, 
     "FIRST_CONTACT_ID": 1, 
     "SECOND_CONTACT_ID": 2, 
     "RELATIONSHIP_ID": 3, 
     "DETAILS": "sample string 4" 
    }, 
    { 
     "CONTACT_LINK_ID": 1, 
     "FIRST_CONTACT_ID": 1, 
     "SECOND_CONTACT_ID": 2, 
     "RELATIONSHIP_ID": 3, 
     "DETAILS": "sample string 4" 
    }, 
    { 
     "CONTACT_LINK_ID": 1, 
     "FIRST_CONTACT_ID": 1, 
     "SECOND_CONTACT_ID": 2, 
     "RELATIONSHIP_ID": 3, 
     "DETAILS": "sample string 4" 
    } 
    ], 
    "EMAILLINKS": [ 
    { 
     "EMAIL_LINK_ID": 1, 
     "EMAIL_ID": 2, 
     "CONTACT_ID": 1, 
     "ORGANISATION_ID": 1, 
     "OPPORTUNITY_ID": 1, 
     "PROJECT_ID": 1 
    }, 
    { 
     "EMAIL_LINK_ID": 1, 
     "EMAIL_ID": 2, 
     "CONTACT_ID": 1, 
     "ORGANISATION_ID": 1, 
     "OPPORTUNITY_ID": 1, 
     "PROJECT_ID": 1 
    }, 
    { 
     "EMAIL_LINK_ID": 1, 
     "EMAIL_ID": 2, 
     "CONTACT_ID": 1, 
     "ORGANISATION_ID": 1, 
     "OPPORTUNITY_ID": 1, 
     "PROJECT_ID": 1 
    } 
    ] 
} 

回答

0

我不熟悉Python,但是從你的有效載荷,該標籤是一個集合屬性。所以你不能簡單地使用$ filter = Tags eq'...'。您應該使用lambda操作any/all來收集屬性。對於任何/所有的簡單使用,請看看OData tutorials - lambda