Get company with client (v4beta1)

Get company with 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 ""

// getCompany gets an existing company by its resource name.
func getCompany(w io.Writer, projectID, companyID string) (*talentpb.Company, error) {
	ctx := context.Background()

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

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

	resp, err := c.GetCompany(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("GetCompany: %v", err)

	fmt.Fprintf(w, "Company: %q\n", resp.GetName())
	fmt.Fprintf(w, "Company display name: %q\n", resp.GetDisplayName())

	return resp, nil


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

public static void sampleGetCompany() {
  // 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 = "Company ID";
  sampleGetCompany(projectId, tenantId, companyId);

/** Get Company */
public static void sampleGetCompany(String projectId, String tenantId, String companyId) {
  try (CompanyServiceClient companyServiceClient = CompanyServiceClient.create()) {
    CompanyName name = CompanyWithTenantName.of(projectId, tenantId, companyId);
    GetCompanyRequest request = GetCompanyRequest.newBuilder().setName(name.toString()).build();
    Company response = companyServiceClient.getCompany(request);
    System.out.printf("Company name: %s\n", response.getName());
    System.out.printf("Display name: %s\n", response.getDisplayName());
  } catch (Exception exception) {
    System.err.println("Failed to create the client due to: " + exception);


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

/** Get Company */
function sampleGetCompany(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 = 'Company ID';
  const formattedName = client.companyPath(projectId, tenantId, companyId);
    .getCompany({name: formattedName})
    .then(responses => {
      const response = responses[0];
      console.log(`Company name: ${}`);
      console.log(`Display name: ${response.displayName}`);
    .catch(err => {


from import talent
import six

def get_company(project_id, tenant_id, company_id):
    """Get Company"""

    client = talent.CompanyServiceClient()

    # project_id = 'Your Google Cloud Project ID'
    # tenant_id = 'Your Tenant ID (using tenancy is optional)'
    # company_id = 'Company ID'

    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)

    response = client.get_company(name=name)
    print(f"Company name: {}")
    print(f"Display name: {response.display_name}")

What's next

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