For Custom Attributes, Google don't provide an example of use in their example code.
Google docs with missing code in its Python example.
Google's example for creating a job and notes "Create Job with Custom Attributes" but doesn't actually include any code for Custom Attrinbutes:
def sample_create_job(project_id, tenant_id, company_name, requisition_id,
language_code):
"""Create Job with Custom Attributes"""
client = talent_v4beta1.JobServiceClient()
# project_id = 'Your Google Cloud Project ID'
# tenant_id = 'Your Tenant ID (using tenancy is optional)'
# company_name = 'Company name, e.g. projects/your-project/companies/company-id'
# requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
# 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_name, six.binary_type):
company_name = company_name.decode('utf-8')
if isinstance(requisition_id, six.binary_type):
requisition_id = requisition_id.decode('utf-8')
if isinstance(language_code, six.binary_type):
language_code = language_code.decode('utf-8')
parent = client.tenant_path(project_id, tenant_id)
job = {
'company': company_name,
'requisition_id': requisition_id,
'language_code': language_code
}
response = client.create_job(parent, job)
print('Created job: {}'.format(response.name))
How do I define Custom Attributes for a job?
Something like the following worked for an earlier version of Talent Solution:
job['custom_attributes'] = {
'custom_name' : {'stringValues' : ['s0', 's1', 's2']},
...
}
I've now tried this:
from google.cloud.talent_v4beta1.types import CustomAttribute
job['custom_attributes'] = [
{
'key' : 'keyname',
'value': CustomAttribute(string_values=[valuestring], filterable=True)
}
]
But when I try to create or update a job an exception is thrown: TypeError: {'key': 'keyname', 'value': string_values: "valuestring"
filterable: true
} has type dict, but expected one of: bytes, unicode
In Nov 2020, Google doc official notes how to do just that
I also have a WIP python library to help it is based on pydantic object.