如何通过Microsoft Graph REST API获取最近更新的设备和用户?
获取新建/最近修改的用户及设备列表(Microsoft Graph API)
用户列表筛选方案
User实体默认返回的字段不包含创建和修改时间,但实际存在createdDateTime和lastModifiedDateTime字段,只需通过$select指定返回这些字段,再用$filter筛选时间范围:
示例查询
GET https://graph.microsoft.com/v1.0/users?$select=id,displayName,createdDateTime,lastModifiedDateTime&$filter=createdDateTime ge 2024-01-01T00:00:00Z or lastModifiedDateTime ge 2024-01-01T00:00:00Z
返回示例(含时间字段)
{ "value": [ { "id": "6ea91a8d-e32e-41a1-b7bd-d2d185eed0e0", "displayName": "Conf Room Adams", "createdDateTime": "2023-12-20T08:30:00Z", "lastModifiedDateTime": "2024-02-15T14:45:00Z" } ] }
设备列表筛选方案
Beta版本的Device实体支持createdDateTime和lastModifiedDateTime字段,同样需要显式指定返回并筛选:
示例查询
GET https://graph.microsoft.com/beta/devices?$select=id,displayName,createdDateTime,lastModifiedDateTime&$filter=createdDateTime ge 2024-01-01T00:00:00Z or lastModifiedDateTime ge 2024-01-01T00:00:00Z
返回示例(含时间字段)
{ "value": [ { "id": "00000000-0000-0000-0000-000000000000", "displayName": "contoso_Android", "createdDateTime": "2024-01-05T09:10:00Z", "lastModifiedDateTime": "2024-02-20T11:20:00Z" } ] }
关键注意事项
- 时间筛选需使用ISO 8601格式(如
YYYY-MM-DDTHH:MM:SSZ),确保时区统一为UTC - 需确保调用API的身份拥有对应权限:用户筛选需
User.Read.All,设备筛选需Device.Read.All - 若结果超过一页,需通过响应中的
@odata.nextLink进行分页获取
内容的提问来源于stack exchange,提问作者Randy
相关产品推荐
相关产品推荐

