Have to do validation in two apis, so we extract it to this function.