首页 > 解决方案 > 如何从 Microsoft Graph 删除成员 API 获取响应代码或状态?

问题描述

我正在使用 Graph API remove member API 从组中删除成员。成功删除后,我没有从 api 得到任何类型的响应。

export async function removeGroupMember(accessToken, groupId, memberId) {
  const client = getAuthenticatedClient(accessToken);
  client
    .api("/groups/" + groupId + "/members/" + memberId + "/$ref")
    .delete()
    .then((res) => {
      console.log(res);    //undefined
      console.log(res.status);   //undefined
    });
}

我在文档中读到它不会返回任何响应正文,但它会在成功删除时返回响应代码 204。如何获取响应码?

现在上面的代码正在完成这项工作,我可以使用上面的代码删除一个成员,我在 Azure 门户中进行了验证。但我需要在前端做出某种响应,让用户知道该成员已被删除。用于错误处理目的。我不确定这是 Javascript 问题还是 Graph API、Azure AD 问题。

标签: javascriptazure-active-directorymicrosoft-graph-apioffice365

解决方案


尝试获得原始响应:

export async function removeGroupMember(accessToken, groupId, memberId) {
  const client = getAuthenticatedClient(accessToken);
  client
    .api("/groups/" + groupId + "/members/" + memberId + "/$ref")
    .delete()
    .responseType(MicrosoftGraph.ResponseType.RAW)
    .then((res) => {
      console.log(res.status);
    });
}

文档

我不确定它是否适用于不返回任何响应正文的删除


推荐阅读