Enhanced a method to get an apikey with more value check.