import pprint import sys import json import httplib2 from apiclient.discovery import build_from_document from apiclient.http import build_http from oauth2client.service_account import ServiceAccountCredentials scopes = ['https://www.googleapis.com/auth/jobs'] #replace the path credentials = ServiceAccountCredentials.from_json_keyfile_name( 'path/to/key.json', scopes) http = httplib2.Http(".cache", disable_ssl_certificate_validation=True) http = credentials.authorize(http=build_http()) #replace the path content = open("/path/to/jobs-api-discovery-doc.json",'r').read() discovery = json.loads(content) service = build_from_document(discovery, 'jobs', 'v2beta1', http=http) createCompanyRequest={'title':'Some Company', 'distributorCompanyId':'test_python_company', 'hqLocation':'801 11th Ave, Sunnyvale, CA', 'companySize':'GIANT' } response = service.companies().create(body=createCompanyRequest).execute() companyName = response.get("name") pprint.pprint(companyName) def callback(request_id, response, exception): if exception is not None: pprint.pprint(exception) pass else: pprint.pprint(response) jobName = response.get("name"); service.jobs().delete(name=jobName).execute() pprint.pprint("Removed " + jobName) pass batch = service.new_batch_http_request() createJobData1={'companyName': companyName, 'jobRequisitionId': 'python_test_1', 'compensationAmount': { 'currencyCode': 'usd', 'units':'10000'}, 'title': 'software engineer', 'location': 'Sunnyvale, CA, US', 'description': 'software engineer', 'applicationUrl': 'https://example.org'} createJobRequest1 = service.jobs().create(body=createJobData1) batch.add(createJobRequest1, callback=callback) createJobData2={'companyName': companyName, 'jobRequisitionId': 'python_test_2', 'compensationAmount': { 'currencyCode': 'usd', 'units':'99999'}, 'title': 'QA engineer', 'location': 'Sunnyvale, CA, US', 'description': 'software engineer', 'applicationUrl': 'https://example.org'} createJobRequest2 = service.jobs().create(body=createJobData2) batch.add(createJobRequest2, callback=callback) response = batch.execute(http=http) service.companies().delete(name=companyName).execute()