fusionauth-php-client icon indicating copy to clipboard operation
fusionauth-php-client copied to clipboard

Delete Group Members does not have the expected API or its API is not documented

Open Steve-MP opened this issue 4 years ago • 1 comments

According to the FusionAuth documentation, there are two ways to remove a user from a group, and both use the URL to pass the request parameters to the FusionAuth API.

Either: DELETE /api/group/member/{memberId} or DELETE /api/group/member?groupId={groupId}&userId={userId}

The method signature for deleteGroupMembers in this library seems designed to accept a JSON request body, but it is not clear how this body should be structured in order to remove a given user from a given group, since the documentation given above does not include removing users from a group using a request body.

Steve-MP avatar Dec 18 '20 15:12 Steve-MP

Hiya,

I agree that this isn't the clearest documentation. Sorry about that. The PHP client library doesn't support the two parameter based delete methods, but does support the request body based methods. These are documented here: https://fusionauth.io/docs/v1/tech/apis/groups/#request-body-4

If you know the user's membership id, you can delete it directly by building json like:

{
  "memberIds": [
    "222b884b-a0a1-4563-a957-89c7c0513e6e",
    "80d474bf-0dee-4009-b793-ec1255693fa3",
    "16d98a8b-4205-4441-8831-7e3f73154134"
  ]
}

If you don't know the membership ids (which I believe is what you are looking for) but do know the group and the user id, you can also remove memberships in that way:

{
  "members": {
    "1188edfc-cef3-4555-910e-181ddf6153c0": [
      
        "578e52df-83e8-48ca-899b-3aefd56e7fc5",
        "0928cf95-34d1-44cc-9114-da68a07e5ff8"
    ]
  }
}

Here's a curl example:

curl -XDELETE -H 'Content-type: application/json' -H "Authorization: $API_KEY" 'http://localhost:9011/api/group/member' -d '
{
  "members": {
    "63437023-6fc7-4f8f-9759-e325c896fef3": 
      [
        "00000000-0000-0000-0000-000000000006"
      ]
    
  }
}'

In PHP the object would look like this:

 $request_object = [
   "members" => [
         "63437023-6fc7-4f8f-9759-e325c896fef3" => [
            "00000000-0000-0000-0000-000000000006" 
         ] 
      ] 
]; 

Note that there is an issue with the docs linked above, they have an extra array between the group id and the list of user ids, but I'll get that fixed.

Hope this helps.

mooreds avatar Dec 18 '20 23:12 mooreds