Create tenant (v4beta1)

Create tenant.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Node.js

To learn how to install and use the client library for CTS, see CTS client libraries. For more information, see the CTS Node.js API reference documentation.

To authenticate to CTS, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


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,
  };
  client
    .createTenant(request)
    .then(responses => {
      const response = responses[0];
      console.log('Created Tenant');
      console.log(`Name: ${response.name}`);
      console.log(`External ID: ${response.externalId}`);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

To learn how to install and use the client library for CTS, see CTS client libraries. For more information, see the CTS Python API reference documentation.

To authenticate to CTS, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


from google.cloud import talent


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, bytes):
        project_id = project_id.decode("utf-8")
    if isinstance(external_id, bytes):
        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: {response.name}")
    print(f"External ID: {response.external_id}")
    return response.name

What's next

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