【问题标题】:How to get response code or status from Microsoft Graph remove member API?如何从 Microsoft Graph 删除成员 API 获取响应代码或状态?
【发布时间】:2021-01-13 20:18:36
【问题描述】:

我正在使用 Graph API 删除成员 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 问题。

【问题讨论】:

  • 你试过 .api("...").responseType(ResponseType.RAW).delete().then((res)=>{...} 吗?但我没有确定它是否适用于不返回任何响应正文的删除。
  • 我不知道这个方法你能告诉我如何在我的代码上下文中使用它吗?

标签: javascript azure-active-directory microsoft-graph-api office365


【解决方案1】:

尝试获取原始响应:

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);
    });
}

Documentation

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

【讨论】:

  • 这行得通。谢谢。只是为了澄清 responseType 中的“MicrosoftGraph”是我使用 var MicrosoftGraph = require("@microsoft/microsoft-graph-client"); 获得的 Microsoft Graph 客户端
  • @dharanikumar 伟大的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
  • 1970-01-01
  • 2011-07-17
相关资源
最近更新 更多