refactor discover_api()