批量删除职位 (v4beta1)

批量删除职位。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

Go

如需了解如何安装和使用适用于 CTS 的客户端库,请参阅 CTS 客户端库。 如需了解详情,请参阅 CTS Go API 参考文档

如需向 CTS 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

import (
	"context"
	"fmt"
	"io"

	talent "cloud.google.com/go/talent/apiv4beta1"
	"cloud.google.com/go/talent/apiv4beta1/talentpb"
)

// batchDeleteJobs deletes existing jobs by a filter.
func batchDeleteJobs(w io.Writer, projectID, companyID, requisitionID string) error {
	ctx := context.Background()

	// Initialize a jobService client.
	c, err := talent.NewJobClient(ctx)
	if err != nil {
		return fmt.Errorf("talent.NewJobClient: %w", err)
	}
	defer c.Close()

	companyName := fmt.Sprintf("projects/%s/companies/%s", projectID, companyID)
	filter := fmt.Sprintf("companyName=%q AND requisitionId=%q", companyName, requisitionID)

	// Construct a batchDeteleJobs request.
	req := &talentpb.BatchDeleteJobsRequest{
		Parent: fmt.Sprintf("projects/%s", projectID),
		// The fields eligible for filtering are `companyName` and `requisitionId`.
		Filter: filter,
	}

	if err := c.BatchDeleteJobs(ctx, req); err != nil {
		return fmt.Errorf("BatchDeleteJobs(%s): %w", filter, err)
	}

	fmt.Fprintf(w, "Batch deleted jobs from %s\n", filter)

	return err
}

Node.js

如需了解如何安装和使用适用于 CTS 的客户端库,请参阅 CTS 客户端库。 如需了解详情,请参阅 CTS Node.js API 参考文档

如需向 CTS 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证


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

/**
 * Batch delete jobs using a filter
 *
 * @param projectId {string} Your Google Cloud Project ID
 * @param tenantId {string} Identifier of the Tenantd
 * @param filter {string} The filter string specifies the jobs to be deleted.
 * For example:
 * companyName = "projects/api-test-project/companies/123" AND equisitionId = "req-1"
 */
function sampleBatchDeleteJobs(projectId, tenantId, filter) {
  const client = new talent.JobServiceClient();
  // const projectId = 'Your Google Cloud Project ID';
  // const tenantId = 'Your Tenant ID (using tenancy is optional)';
  // const filter = '[Query]';
  const formattedParent = client.tenantPath(projectId, tenantId);
  const request = {
    parent: formattedParent,
    filter: filter,
  };
  client.batchDeleteJobs(request).catch(err => {
    console.error(err);
  });
  console.log('Batch deleted jobs from filter');
}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器