API JavaScript logic