{“errorMessage”:”Bad Request”} when using admin api

I am trying to use the admin api to update user info but when the api is called it returns this error:

{StatusCode: 400, ReasonPhrase: 'Bad Request'}

PUT /admin/realms/{realm}/users/{user-id}

The weird part is that when I check the user info after running the update api the information is updated correctly but the message returned is incorrect. I’m not sure if that is due to something on my end but here is the fetch call I am using to do the update

//1、retrieve user information
var getUrl = $“/admin/realms/{_options.Realm}/users/{userId}”;
var getReq = new HttpRequestMessage(HttpMethod.Get, getUrl);
getReq.Headers.Authorization = new AuthenticationHeaderValue(“Bearer”, adminToken);
var getResp = await _httpClient.SendAsync(getReq);
var userRawJson = await getResp.Content.ReadAsStringAsync();

var userObj = JsonSerializer.Deserialize(userRawJson);
using var doc = JsonDocument.Parse(userRawJson);
var root = doc.RootElement.Clone();
var userDict = JsonSerializer.Deserialize<Dictionary<string, object>>(userRawJson);

// 2. merge new attributes
var originAttrs = userDict[“attributes”] as Dictionary<string, string[]> ?? new();
attributes.Add(“displayname”, new[] { “testValue” });
attributes.Add(“testJa”, new[] { “vera_test” });
foreach (var pair in attributes)
{
originAttrs[pair.Key] = pair.Value;
}
userDict[“attributes”] = originAttrs;

// 3. update userinfo
var payload = userDict;
var json = JsonSerializer.Serialize(payload);
var request = new HttpRequestMessage(HttpMethod.Put, getUrl);
request.Headers.Authorization = new AuthenticationHeaderValue(“Bearer”, adminToken);
request.Content = new StringContent(json, Encoding.UTF8, “application/json”);
var response = await _httpClient.SendAsync(request);

if (!response.IsSuccessStatusCode)
{
string errorMsg = await response.Content.ReadAsStringAsync();
throw new Exception($“update failed:{errorMsg}”);
}