Import the needed libraries

import requests
import urllib
JOB_TITLE = 'Here comes your title'
API_KEY = '5YiEZ-GzCFercgV-KHy5'
API_URL = 'https://api.figure-eight.com/v1/jobs.json?key=' + API_KEY 
DATA_FILE = 'data.csv'
CML_FILE = 'template.cml'

We need functions to check the response, in order to make it more concise, it is a good idea to create a function which does this for us.

def check_response(request):
    if  (request.status_code == 200) & (request != None):
        return True
    else:
        return False

We also need to upload some data aswell as the cml, we can upload them both the same way.

def upload_data(job_id):
    with open(DATA_FILE, 'rb') as data:
        response = requests.put(
                            url="https://api.figure-eight.com/v1/jobs/" + str(job_id) + "/upload.json?key=" + API_KEY + "&force=true",
                            data=data.read(),
                            headers = {
                                           'content-type':'text/csv',
                                      })
    if check_response(response):
        print("Data Successfully Uploaded")
    else:
        print("Error code " + str(req.status_code))
def upload_cml(job_id):
    with open(CML_FILE, 'rb') as templ:
        response = requests.put(
            url = 'https://api.figure-eight.com/v1/jobs/' + str(job_id) + '.json?key=' + API_KEY, 
            headers = {'content-type': 'application/xml'},
            params = {'job[cml]':templ.read()}
        )
        if check_response(response):
            print("CML Successfully Uploaded")
        else:
            print("Error code " + req.status_code)
        

Creating the job & uploading data as well as cml

data = {'job[title]' : 'Here comes your title'}
urlencoded = urllib.parse.urlencode(data)
req = requests.post(API_URL + "&" + urlencoded)

if check_response(req):
    job_id = req.json()['id']
    upload_data(job_id)
    upload_cml(job_id)
else:
    print("Error code " + str(req.status_code))
Data Successfully Uploaded
CML Successfully Uploaded
result = requests.get('https://api.figure-eight.com/v1/jobs/' + str(job_id) + '/judgments.json?key=' + API_KEY)
print(result.headers['content-type'])
print(result.text)
application/json; charset=utf-8
{}