Create job with client.
Documentation pages that include this code sample
To view the code sample used in context, see the following documentation:
Code sample
Go
import (
"context"
"fmt"
"io"
talent "cloud.google.com/go/talent/apiv4beta1"
talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
)
// createJob create a job as given.
func createJob(w io.Writer, projectID, companyID, requisitionID, title, URI, description, address1, address2, languageCode string) (*talentpb.Job, error) {
ctx := context.Background()
// Initialize a jobService client.
c, err := talent.NewJobClient(ctx)
if err != nil {
return nil, fmt.Errorf("talent.NewJobClient: %v", err)
}
jobToCreate := &talentpb.Job{
Company: fmt.Sprintf("projects/%s/companies/%s", projectID, companyID),
RequisitionId: requisitionID,
Title: title,
ApplicationInfo: &talentpb.Job_ApplicationInfo{
Uris: []string{URI},
},
Description: description,
Addresses: []string{address1, address2},
LanguageCode: languageCode,
}
// Construct a createJob request.
req := &talentpb.CreateJobRequest{
Parent: fmt.Sprintf("projects/%s", projectID),
Job: jobToCreate,
}
resp, err := c.CreateJob(ctx, req)
if err != nil {
return nil, fmt.Errorf("CreateJob: %v", err)
}
fmt.Fprintf(w, "Created job: %q\n", resp.GetName())
return resp, nil
}
Java
/*
* Please include the following imports to run this sample.
*
* import com.google.cloud.talent.v4beta1.CreateJobRequest;
* import com.google.cloud.talent.v4beta1.Job;
* import com.google.cloud.talent.v4beta1.Job.ApplicationInfo;
* import com.google.cloud.talent.v4beta1.JobServiceClient;
* import com.google.cloud.talent.v4beta1.TenantName;
* import com.google.cloud.talent.v4beta1.TenantOrProjectName;
* import java.util.Arrays;
* import java.util.List;
*/
public static void sampleCreateJob() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "Your Google Cloud Project ID";
String tenantId = "Your Tenant ID (using tenancy is optional)";
String companyName = "Company name, e.g. projects/your-project/companies/company-id";
String requisitionId = "Job requisition ID, aka Posting ID. Unique per job.";
String title = "Software Engineer";
String description = "This is a description of this <i>wonderful</i> job!";
String jobApplicationUrl = "https://www.example.org/job-posting/123";
String addressOne = "1600 Amphitheatre Parkway, Mountain View, CA 94043";
String addressTwo = "111 8th Avenue, New York, NY 10011";
String languageCode = "en-US";
sampleCreateJob(
projectId,
tenantId,
companyName,
requisitionId,
title,
description,
jobApplicationUrl,
addressOne,
addressTwo,
languageCode);
}
/**
* Create Job
*
* @param projectId Your Google Cloud Project ID
* @param tenantId Identifier of the Tenant
*/
public static void sampleCreateJob(
String projectId,
String tenantId,
String companyName,
String requisitionId,
String title,
String description,
String jobApplicationUrl,
String addressOne,
String addressTwo,
String languageCode) {
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantOrProjectName parent = TenantName.of(projectId, tenantId);
List<String> uris = Arrays.asList(jobApplicationUrl);
Job.ApplicationInfo applicationInfo =
Job.ApplicationInfo.newBuilder().addAllUris(uris).build();
List<String> addresses = Arrays.asList(addressOne, addressTwo);
Job job =
Job.newBuilder()
.setCompany(companyName)
.setRequisitionId(requisitionId)
.setTitle(title)
.setDescription(description)
.setApplicationInfo(applicationInfo)
.addAllAddresses(addresses)
.setLanguageCode(languageCode)
.build();
CreateJobRequest request =
CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build();
Job response = jobServiceClient.createJob(request);
System.out.printf("Created job: %s\n", response.getName());
} catch (Exception exception) {
System.err.println("Failed to create the client due to: " + exception);
}
}
Node.js
const talent = require('@google-cloud/talent').v4;
/**
* Create Job
*
* @param projectId {string} Your Google Cloud Project ID
* @param tenantId {string} Identifier of the Tenant
*/
function sampleCreateJob(
projectId,
tenantId,
companyName,
requisitionId,
title,
description,
jobApplicationUrl,
addressOne,
addressTwo,
languageCode
) {
const client = new talent.JobServiceClient();
// const projectId = 'Your Google Cloud Project ID';
// const tenantId = 'Your Tenant ID (using tenancy is optional)';
// const companyName = 'Company name, e.g. projects/your-project/companies/company-id';
// const requisitionId = 'Job requisition ID, aka Posting ID. Unique per job.';
// const title = 'Software Engineer';
// const description = 'This is a description of this <i>wonderful</i> job!';
// const jobApplicationUrl = 'https://www.example.org/job-posting/123';
// const addressOne = '1600 Amphitheatre Parkway, Mountain View, CA 94043';
// const addressTwo = '111 8th Avenue, New York, NY 10011';
// const languageCode = 'en-US';
const formattedParent = client.tenantPath(projectId, tenantId);
const uris = [jobApplicationUrl];
const applicationInfo = {
uris: uris,
};
const addresses = [addressOne, addressTwo];
const job = {
company: companyName,
requisitionId: requisitionId,
title: title,
description: description,
applicationInfo: applicationInfo,
addresses: addresses,
languageCode: languageCode,
};
const request = {
parent: formattedParent,
job: job,
};
client
.createJob(request)
.then(responses => {
const response = responses[0];
console.log(`Created job: ${response.name}`);
})
.catch(err => {
console.error(err);
});
}
Python
from google.cloud import talent
import six
def create_job(
project_id, tenant_id, company_id, requisition_id, job_application_url,
):
"""Create Job"""
client = talent.JobServiceClient()
# project_id = 'Your Google Cloud Project ID'
# tenant_id = 'Your Tenant ID (using tenancy is optional)'
# company_id = 'Company name, e.g. projects/your-project/companies/company-id'
# requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
# title = 'Software Engineer'
# description = 'This is a description of this <i>wonderful</i> job!'
# job_application_url = 'https://www.example.org/job-posting/123'
# address_one = '1600 Amphitheatre Parkway, Mountain View, CA 94043'
# address_two = '111 8th Avenue, New York, NY 10011'
# language_code = 'en-US'
if isinstance(project_id, six.binary_type):
project_id = project_id.decode("utf-8")
if isinstance(tenant_id, six.binary_type):
tenant_id = tenant_id.decode("utf-8")
if isinstance(company_id, six.binary_type):
company_id = company_id.decode("utf-8")
if isinstance(requisition_id, six.binary_type):
requisition_id = requisition_id.decode("utf-8")
if isinstance(job_application_url, six.binary_type):
job_application_url = job_application_url.decode("utf-8")
parent = f"projects/{project_id}/tenants/{tenant_id}"
uris = [job_application_url]
application_info = {"uris": uris}
addresses = [
"1600 Amphitheatre Parkway, Mountain View, CA 94043",
"111 8th Avenue, New York, NY 10011",
]
job = {
"company": company_id,
"requisition_id": requisition_id,
"title": "Software Developer",
"description": "Develop, maintain the software solutions.",
"application_info": application_info,
"addresses": addresses,
"language_code": "en-US",
}
response = client.create_job(parent=parent, job=job)
print("Created job: {}".format(response.name))
return response.name
Ruby
require "google/cloud/talent"
# Instantiate a client
job_service = Google::Cloud::Talent.job_service
# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID (using tenancy is required)"
parent = job_service.tenant_path project: project_id, tenant: tenant_id
# job_application_url = "https://www.example.org/job-posting/123"
uris = [job_application_url]
application_info = { uris: uris }
# address = "1600 Amphitheatre Parkway, Mountain View, CA 94043"
addresses = [address]
# company_name = "Company name, e.g. projects/your-project/companies/company-id"
# requisition_id = "Job requisition ID, aka Posting ID. Unique per job."
# title = "Software Engineer"
# description = "This is a description of this <i>wonderful</i> job!"
# language_code = "en-US"
job = {
company: company_name,
requisition_id: requisition_id,
title: title,
description: description,
application_info: application_info,
addresses: addresses,
language_code: language_code
}
response = job_service.create_job parent: parent, job: job
puts "Created job: #{response.name}"
What's next
To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser