Create tenant (v4beta1)

Create tenant.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


 * Please include the following imports to run this sample.
 * import;
 * import;
 * import;
 * import;

public static void sampleCreateTenant() {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "Your Google Cloud Project ID";
  String externalId = "Your Unique Identifier for Tenant";
  sampleCreateTenant(projectId, externalId);

/** Create Tenant for scoping resources, e.g. companies and jobs */
public static void sampleCreateTenant(String projectId, String externalId) {
  try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
    ProjectName parent = ProjectName.of(projectId);
    Tenant tenant = Tenant.newBuilder().setExternalId(externalId).build();
    CreateTenantRequest request =
    Tenant response = tenantServiceClient.createTenant(request);
    System.out.println("Created Tenant");
    System.out.printf("Name: %s\n", response.getName());
    System.out.printf("External ID: %s\n", response.getExternalId());
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);


const talent = require('@google-cloud/talent').v4;

/** Create Tenant for scoping resources, e.g. companies and jobs */
function sampleCreateTenant(projectId, externalId) {
  const client = new talent.TenantServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const externalId = 'Your Unique Identifier for Tenant';
  const formattedParent = client.projectPath(projectId);
  const tenant = {
    externalId: externalId,
  const request = {
    parent: formattedParent,
    tenant: tenant,
    .then(responses => {
      const response = responses[0];
      console.log('Created Tenant');
      console.log(`Name: ${}`);
      console.log(`External ID: ${response.externalId}`);
    .catch(err => {


from import talent
import six

def create_tenant(project_id, external_id):
    """Create Tenant for scoping resources, e.g. companies and jobs"""

    client = talent.TenantServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # external_id = 'Your Unique Identifier for Tenant'

    if isinstance(project_id, six.binary_type):
        project_id = project_id.decode("utf-8")
    if isinstance(external_id, six.binary_type):
        external_id = external_id.decode("utf-8")
    parent = f"projects/{project_id}"
    tenant = talent.Tenant(external_id=external_id)

    response = client.create_tenant(parent=parent, tenant=tenant)
    print("Created Tenant")
    print(f"Name: {}")
    print(f"External ID: {response.external_id}")

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.