Microsoft Graph API 不尊重 OData [英] Microsoft Graph API not respecting OData

查看:18
本文介绍了Microsoft Graph API 不尊重 OData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试拉动特定组中的所有用户并获得他们的传递成员资格.

I'm attempting to pull all users within a specific group and to also get their transitive membership.

我要到达的终点是:

https://graph.microsoft.com/v1.0/groups/{id}/transitiveMembers/microsoft.graph.user?$select=givenName,surname,country,city,companyName,officeLocation,displayName,mail,department,jobTitle,employeeId&$expand=transitiveMemberOf

这会提取我需要的数据,但返回的有效负载中有一个 OData 类型的对象 microsoft.graph.group 会导致以下错误:

This pulls the data I need, but there is an object of OData type microsoft.graph.group in the returned payload that causes the following error:

A resource of type 'microsoft.graph.group' was found in a resource set that otherwise has entries of type 'microsoft.graph.user'. In OData, all entries in a resource set must have a common base type.

这会导致 unexpected token 的 JSON 解析错误.响应确实包含下一个链接,我希望能够处理此错误并转到下一页.但是,JSON::ParserError 阻止我这样做.

Which then causes a JSON parse error of unexpected token. The response does contain the next link and I would like to be able to handle this error and move on to the next page. However, the JSON::ParserError prevents me from doing this.

当在请求 url 中指定 microsoft.graph.user 时,可能会导致返回 microsoft.graph.group 对象的任何想法?

Any ideas what might cause a microsoft.graph.group object to be returned when microsoft.graph.user was specified in the request url?

推荐答案

我的解决方案是添加 $count=true 查询参数并设置 ConsistencyLevel 标头.这使得错误消失并且调用成功.

The solution for me was to add the $count=true query parameter and setting the ConsistencyLevel header. This made the error go away and the call succeed.

它甚至在文档中这样说:

It even says so in the documentation:

哎呀.在撰写本文时,标头和查询参数都是必需的.

Whoops. Both the header and the query parameter are needed as of writing this.

这篇关于Microsoft Graph API 不尊重 OData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆