我有一个 OData API,我正在尝试使用 Python 请求库进行查询。我正在尝试根据父表过滤表以进行增量数据拉取。子表不使用
last_update_date
,但我可以从父表获取此日期,因为父表的 last_updated_date
发生更改,即使更改位于子表中也是如此。请注意,在我的示例中,employees
是 employee_texts
的父实体。
我的代码如下所示:
data = requests.get(
endpoint_url + "employee_texts"
, auth=(api_username, api_password)
, params={
"$filter": "employees/LastModifiedDate gt 2023-11-15T00:00:00.00Z",
"$format": "json"
}
, verify=True
)
如果我运行此命令,我会收到以下错误:
{'错误':{'代码':'',
'message': '值不能为空。 参数名称:类型'}}
请注意,此代码按预期工作:
data = requests.get(
endpoint_url + "employees"
, auth=(api_username, api_password)
, params={
"$filter": "LastModifiedDate gt 2023-11-15T00:00:00.00Z",
"$format": "json"
}
, verify=True
)
如果
employees
是一个集合,那么您需要在 any
查询中使用 $filter
运算符。
data = requests.get(
endpoint_url + "employee_texts"
, auth=(api_username, api_password)
, params={
"$filter": "employees/any(e:e/LastModifiedDate gt 2023-11-15T00:00:00.00Z)",
"$format": "json"
}
, verify=True
)