import CloudFlare


def check_if_valid_domain(cf: CloudFlare.CloudFlare, domain: str) -> bool:
    # query for the zone name and expect only one value back
    try:
        zones = cf.zones.get(params={'name': domain, 'per_page': 1})
    except CloudFlare.exceptions.CloudFlareAPIError as e:
        exit('/zones.get %d %s - api call failed' % (e, e))
    except Exception as e:
        exit('/zones.get - %s - api call failed' % e)

    if len(zones) == 0:
        return False
    else:
        return True
