OData查询Message Trace API日期时间筛选语法报错求助
Message Trace API OData日期筛选报错排查
问题详情
使用OData筛选器为Message Trace API设置StartDate和EndDate范围时,请求URL如下:
https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace?$filter=StartDate ge DateTime'2023-07-14T00:00:00Z' and EndDate le datetime'2023-07-14T23:59:59Z'
返回服务器错误:
<?xml version="1.0" encoding="utf-8"?> <m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <m:code>UnknownError</m:code> <m:message xml:lang="">An error has occurred on the server.</m:message> </m:error>
排查与修复方案
统一日期字面量关键字大小写:OData规范要求日期时间字面量使用小写
datetime,当前URL中混用了DateTime(大写开头)和datetime(全小写),会导致服务器解析失败。修正后的筛选器应为:$filter=StartDate ge datetime'2023-07-14T00:00:00Z' and EndDate le datetime'2023-07-14T23:59:59Z'对筛选器内容进行URL编码:URL中的空格需要替换为
%20,避免解析异常。完整的请求URL应为:https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace?$filter=StartDate%20ge%20datetime'2023-07-14T00:00:00Z'%20and%20EndDate%20le%20datetime'2023-07-14T23:59:59Z'验证日期范围有效性:确认EndDate不晚于当前UTC时间,且StartDate在API允许的查询范围内(Exchange Online报表API通常支持查询过去90天内的数据)。
检查权限与API版本:确保账号拥有Exchange管理员或邮件跟踪报表查看权限;此外,该端点属于旧版Exchange报表API,若问题持续,可考虑迁移至Microsoft Graph的邮件跟踪API。
内容的提问来源于stack exchange,提问作者Error
相关产品推荐
相关产品推荐

