Delete company using client (v4beta1)

Delete company using client.

Documentation pages that include this code sample

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

Code sample


import (

	talent ""
	talentpb ""

// deleteCompany deletes an existing company. Companies with
// existing jobs cannot be deleted until those jobs have been deleted.
func deleteCompany(w io.Writer, projectID, companyID string) error {
	ctx := context.Background()

	// Initialize a companyService client.
	c, err := talent.NewCompanyClient(ctx)
	if err != nil {
		return fmt.Errorf("talent.NewCompanyClient: %v", err)

	// Construct a deleteCompany request.
	companyName := fmt.Sprintf("projects/%s/companies/%s", projectID, companyID)
	req := &talentpb.DeleteCompanyRequest{
		// The resource name of the company to be deleted.
		// The format is "projects/{project_id}/companies/{company_id}".
		Name: companyName,

	if err := c.DeleteCompany(ctx, req); err != nil {
		return fmt.Errorf("DeleteCompany(%s): %v", companyName, err)

	fmt.Fprintf(w, "Deleted company: %q\n", companyName)

	return nil


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

public static void sampleDeleteCompany() {
  // 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 companyId = "ID of the company to delete";
  sampleDeleteCompany(projectId, tenantId, companyId);

/** Delete Company */
public static void sampleDeleteCompany(String projectId, String tenantId, String companyId) {
  try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
    CompanyName name = CompanyWithTenantName.of(projectId, tenantId, companyId);
    DeleteCompanyRequest request =
    System.out.println("Deleted company");
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);


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

/** Delete Company */
function sampleDeleteCompany(projectId, tenantId, companyId) {
  const client = new talent.CompanyServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const companyId = 'ID of the company to delete';
  const formattedName = client.companyPath(projectId, tenantId, companyId);
  client.deleteCompany({name: formattedName}).catch(err => {
  console.log('Deleted company');


from import talent
import six

def delete_company(project_id, tenant_id, company_id):
    """Delete Company"""

    client = talent.CompanyServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # company_id = 'ID of the company to delete'

    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")
    name = client.company_path(project_id, tenant_id, company_id)

    print("Deleted company")


require "google/cloud/talent"

# Instantiate a client
company_service = Google::Cloud::Talent.company_service

# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID (using tenancy is required)"
# company_id = "ID of the company to delete"
formatted_name = company_service.company_path project: project_id,
                                              tenant:  tenant_id,
                                              company: company_id

company_service.delete_company name: formatted_name

puts "Deleted company"