Search code examples
perlapioffice365apimicrosoft-graph-api

In new microsoft graph API, how do you remove members from a Unified group?


The Microsoft Graph API documentation at https://graph.microsoft.io/docs/api-reference/v1.0/resources/group shows methods for listing members of a group and creating a new member. I've had both of those working with my Perl code OK (using the app authorized client credentials flow, as this will be a daemon eventually running on one of our Linux servers). So that's all good, the bearer tokens are working, etc. Great.

What I want to do now is remove a member from a group, but I don't see a method documented for that? I tried guessing and using:

DELETE https://graph.microsoft.com/v1.0/groups/<group_id>/members/<member_id>

but that results in a "Bad Request" error with the explanation of "Write requests are only supported on contained entities". So is this possible and if so, what is the RESTful call I need to make?

I can foresee a similar issue with deleting calendar events when I get to that (I'm trying to set up groups that have calendar events attached to them for our student timetabling system) as the documentation shows API calls for listing events and creating them, but not removing them. I get the impression that the API is still under development (despite moving from /beta to /v1.0) and the documentation is in flux?


Solution

  • Please append /$ref to your request to delete the link/reference between the group and the member. A request without /$ref semantically represents an attempt to delete the member object along with the link to the group. Such requests are only supported for containment navigations as in the case of events.

    The events navigation property on the group entity type has ContainsTarget="true" attribute in https://graph.microsoft.com/v1.0/$metadata. Contained entities can't be unlinked from the containing entity and thus a DELETE ../$ref request can't be used in this case and simple DELETE /groups//events/ will remove a group event (not just its link/reference to the group).