import pprint 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'] 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()) content = open("/path/to/jobs_discovery_v2.json",'r').read() discovery = json.loads(content) service = build_from_document(discovery, 'jobs', 'v2', http=http) 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("################") pprint.pprint("Removed " + jobName) pprint.pprint("################") pass batch = service.new_batch_http_request() createCompanyRequest={ "displayName": "Google", "distributorCompanyId": "Alphabet", "hqLocation": "Mountain View, CA", "companySize": "GIANT" } response = service.companies().create(body=createCompanyRequest).execute() companyName = response.get("name") pprint.pprint("################") pprint.pprint(companyName) pprint.pprint("################") createJobData1={ "job": { "requisitionId": "123456", "jobTitle": "Software Engineer", "description": "Design, develop, test, deploy, maintain and improve software.", "locations": ["Sunnyvale, CA"], "applicationUrls": "http://careers.google.com", "companyName": companyName, } } createJobRequest1 = service.jobs().create(body=createJobData1) batch.add(createJobRequest1, callback=callback) createJobData2={ "job": { "requisitionId": "234567", "jobTitle": "Software Engineer", "description": "Design, develop, test, deploy, maintain and improve software.", "locations": ["San Bruno, CA"], "applicationUrls": "http://careers.google.com", "companyName": companyName, } } createJobRequest2 = service.jobs().create(body=createJobData2) batch.add(createJobRequest2, callback=callback) response = batch.execute(http=http) service.companies().delete(name=companyName).execute() pprint.pprint("#####Removed####") pprint.pprint(companyName) pprint.pprint("################")