import requests


def copy_job(job_id, key):
    """Helper function to create a Figure 8 job based on existing job.

    Args:
        job_id: ID number of job to copy instructions and settings from when creating new job
        key: API key to access Figure 8 account

    Returns:
        int: ID number of job created
    """

    url = 'https://api.appen.com/v1/jobs/{}/copy.json?'.format(str(job_id))
    API_key = {'key': key}

    new_job = requests.get(url, params=API_key)
    if new_job.status_code != 200:
        raise ValueError('copy_job not successful. Status code: '.format(new_job.status_code))

    new_job_id = new_job.json()['id']

    return new_job_id