【发布时间】:2022-10-24 16:52:03
【问题描述】:
在尝试使用 Graph API 将用户添加到组之前,是否应该先检查用户是否已经是成员?或者我应该尝试添加和处理假设失败意味着它们已经存在?
如果我使用以下 GET 请求来检查用户是否在组中,我会收到 404 响应。
https://graph.microsoft.com/v1.0/groups/{{groupId}}/members/{userId}}
回复:
"error": {
"code": "Request_ResourceNotFound",
"message": "Resource '{{groupId}}' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"date": "2022-10-22T07:44:27",
"request-id": "...",
"client-request-id": "..."
}
}
}```
The most likely explanation for this error is that the user doesn't exist. However I'm guessing there may also be other reasons.
If I try to add a user to a group, but they already exist, I get a 400 response:
```{
"error": {
"code": "Request_BadRequest",
"message": "One or more added object references already exist for the following modified properties: 'owners'.",
"innerError": {
"date": "2022-10-22T07:44:56",
"request-id": "...",
"client-request-id": "..."
}
}
}```
It seems more efficient to try adding rather than first checking. Also fewer graph calls means less risk of throttling.
【问题讨论】: