def METHOD_NAME(endpoint, filename, args, logfile):
    url = args.server + endpoint
    headers = {'Private-Token': args.token}
    log(logfile, f'downloading {url} ...')
    start_time = time.time()
    retry_502_max = 30
    retry_502_i = 0
    while True:
        r = requests.get(url, headers=headers)
        if r.status_code == 200:
            break
        elif r.status_code == 502:
            retry_502_i += 1
            if retry_502_i >= retry_502_max:
                raise Exception(f'Maximum number of retries reached on 502 Bad Gateway Error for {url}')
            else:
                log(logfile, f'Bad Gateway Error encountered for {url}, retrying in 10 seconds')
                time.sleep(10)
                continue
        else:
            raise Exception(f'Invalid status returned for {url}: {r.status_code}')
    end_time = time.time()
    log(logfile, f'successfully downloaded {r.headers["content-length"]} bytes in {end_time - start_time} seconds')
    full_filename = os.path.join(args.output_dir, filename + '.json')
    log(logfile, f'saving data to {full_filename} ...')
    with open(full_filename, 'wt') as out_f:
        out_f.write(r.text)
    log(logfile, f'successfully wrote data')
    log(logfile, f'parsing data as JSON...')
    data = r.json()
    log(logfile, f'successfully parsed JSON')
    return data