Hello,
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.