子项目的OData过滤器

时间:2014-09-03 09:47:22

标签: python rest python-2.7 odata

我正在尝试使用Python 2.7为我的Insightly帐户编写一个小应用程序来接收带有标记" test"的所有联系人。

我使用提供的代码示例进行实验,但它的效果非常好,但仅适用于顶级元素。

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
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

我不熟悉python,但是从你的有效负载来看,Tags是一个集合属性。所以你不能简单地使用$ filter = Tags eq' ...'。您应该对集合属性使用lambda操作any / all。如需简单使用any / all,请查看OData tutorials - lambda