updateUserProfile method
Corresponds to: PUT /accounts/profiles/:user_id Omitted fields are preserved. Metadata and annotations replace their maps. Project edits require user_profile_editor, including for your own profile. Returns JSON like { "ok": true } on success.
Implementation
Future<Map<String, dynamic>> updateUserProfile(
String userId,
String? firstName,
String? lastName, {
Map<String, dynamic>? metadata,
Map<String, String>? annotations,
String? projectId,
List<UserProfileField>? inherit,
}) async {
final encodedUserId = Uri.encodeComponent(userId);
if (projectId == null && inherit != null) {
throw ArgumentError('projectId is required to inherit profile fields');
}
final uri = Uri.parse(
projectId == null
? '$baseUrl/accounts/profiles/$encodedUserId'
: '$baseUrl/accounts/projects/${Uri.encodeComponent(projectId)}/users/$encodedUserId/profile',
);
final body = {
'first_name': ?firstName,
'last_name': ?lastName,
'metadata': ?metadata,
'annotations': ?annotations,
if (inherit != null) 'inherit': inherit.map((field) => field.wireName).toList(),
};
final response = await httpClient.put(uri, body: jsonEncode(body));
if (response.statusCode >= 400) {
throw MeshagentException('Failed to update user profile. Status code: ${response.statusCode}, body: ${response.body}');
}
return jsonDecode(response.body) as Map<String, dynamic>;
}