def METHOD_NAME(request):
    try:
        # check if key is correct
        key = str(request.GET.get("key"))
        if compile_api_key().match(key) is None:
            return JsonResponse({"error": {"code": 2, "error": "Invalid API key"}}, status=400)
        # get user
        player = getPlayerBykey(key)
        if player is None:
            return JsonResponse({"error": {"code": 2, "error": "Player not found"}}, status=400)
        # get faction
        faction = getFaction(player.factionId)
        if faction is None:
            return JsonResponse({"error": {"code": 2, "error": "Faction not found"}}, status=400)
        # get option faction id filter
        try:
            faction_id = int(request.GET.get("faction"))
        except Exception:
            faction_id = None
        # get spies
        spies = faction.METHOD_NAME(faction_id=faction_id)
        # handle API error if faction filter
        if "apiError" in spies:
            return JsonResponse({"error": {"error": spies["apiError"], "code": 4}}, status=400)
        return JsonResponse({"spies": spies}, status=200)
    except BaseException as e:
        return JsonResponse({"error": {"code": 1, "error": str(e)}}, status=500)