updateUserProfile method

Future<Map<String, dynamic>> updateUserProfile(
  1. String userId,
  2. String? firstName,
  3. String? lastName, {
  4. Map<String, dynamic>? metadata,
  5. Map<String, String>? annotations,
  6. String? projectId,
})

Corresponds to: PUT /accounts/profiles/:user_id Omitted fields are preserved. Metadata and annotations replace their maps. Editing another user or annotations requires user_profile_editor in projectId. 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,
}) async {
  final encodedUserId = Uri.encodeComponent(userId);
  final uri = Uri.parse(
    '$baseUrl/accounts/profiles/$encodedUserId',
  ).replace(queryParameters: projectId == null ? null : {'project_id': projectId});
  final body = {'first_name': ?firstName, 'last_name': ?lastName, 'metadata': ?metadata, 'annotations': ?annotations};

  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>;
}