At what age can someone contract endocarditis?

Any . If the have the right underlying risk factors, diseases or habits.
Any age. Any age with the right underlying risk factors, habits or diseases can get endocarditis.