Unable to add groups to user using Authorization Extension API from asp.net core 3.1 Web API


I am using the Authentication API from asp.net core 3.1 Web API to add groups to a user but i keep getting the value must be an array error.
Here is my code snippet:

 public async Task<bool> AddGroupsToUser(AddUserGroup addGroups)
            var result = false; 
            foreach (var groupId in addGroups.GroupIds) // addGroups.GroupIds is string[] type)
                Uri uri = new Uri($"{_url}/groups/{groupId}/members");
                var client = new RestClient(uri);
                var request = new RestRequest(Method.PATCH);
                request.AddHeader("authorization", "Bearer " + _tokenResponse.access_token);
                request.AddParameter("user_id", addGroups.UserId);
                request.AddParameter("group_id",groupId ); 
                IRestResponse response = await client.ExecuteAsync(request);
                result = response.IsSuccessful;
            return result;

I also used PATCH /users/{user_id}/groups but i still get the same error.
Besides, When I send the request, do i have to send only the new groups that i want to add or all (existing + new)?

I don’t know what i am missing here.

Thanks for the help.

The problem was addGroups.GroupIds is defined as string on the server but on the UI the type was any because when i was looping through the array to collect the groupids, I forgot to pass the iterator. when it comes to the server , the type was being properly mapped to string but i guess Auth0 was able to detect it. So adding the iterator on the UI, solved my problem.

1 Like

Perfect! Glad you have figured it out and thanks for sharing the solution with the rest of community!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.