我正在使用查询参数来指定和控制响应中返回的数据量。
更具体地说,我正在尝试限制应用程序的扩展所有者信息:
应用程序所有者的目录对象。只读。 可空。支持$expand、$filter(/$count eq 0、/$count ne 0、 /$count eq 1、/$count ne 1) 和 $select 嵌套在 $expand 中。
以下请求返回完整的所有者信息,而不仅仅是他们的 ID。
https://graph.microsoft.com/v1.0/applications?$filter=displayName eq 'api-lab'&$expand=owners($select=id)&$count=true
https://learn.microsoft.com/en-us/graph/api/resources/application?view=graph-rest-1.0#relationships
如何让它只返回所有者的ID?
此外,我该如何对业主使用
$filter
?
如果我尝试过滤所有者,则会收到以下错误:
https://graph.microsoft.com/v1.0/applications?$filter=displayName eq 'api-lab'&$expand=owners&$filter=owners/$count eq 0&$count=true
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Property 'owners' does not exist as a declared property or extension property.",
"innerError": {
"date": "2024-07-07T12:12:14",
"request-id": "e4795a2b-4602-44d7-88df-13ae2d47fccb",
"client-request-id": "888d1473-7351-636d-5033-bbb493aae52e"
}
}
}
您仅返回所有者 ID 的查询是正确的,但由于某种原因它不起作用。这个解决方法会起作用。添加
$select
将触发 $select
内的内部
$expand
GET /v1.0/applications?$filter=displayName eq 'api-lab'&$expand=owners($select=id)&$select=id,displayName
为了能够过滤没有所有者的应用程序(您已经尝试过),您需要添加带有值
ConsistencyLevel
的请求标头
eventual
GET /v1.0/applications?$filter=displayName eq 'api-lab' and owners/$count eq 0&$count=true
ConsistencyLevel: eventual
在这种情况下不要使用扩展