0
votes

I'm using Graph API remove member API to delete a member from group. After successful deletion I'm not getting any kind of response from the 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
    });
}

I read in docs that it won't return any response body, but it will return a response code 204 on successful deletion. How can I get the response code?

Now the above code is doing the job, I'm able to remove a member using the above code, I verified in the Azure portal. But I need some kind of response in Frontend to let the user know that member is removed. For error handling purpose. I'm not sure if this is a Javascript question or Graph API, Azure AD question.

1
Did you try .api("...").responseType(ResponseType.RAW).delete().then((res)=>{...} ? but I'm not sure if it will work for delete which doesn't return any response body. - user2250152
I'm not aware of this method Can you please tell me how to use it in my code context? - dharani kumar

1 Answers

0
votes

Try to get the raw response:

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

I'm not sure if it will work for delete which doesn't return any response body