Delete a transfer run

Deletes a transfer run in the BigQuery Data Transfer Service.

Code sample

Node.js

Before trying this sample, follow the Node.js setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Node.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

const {
  DataTransferServiceClient,
} = require('@google-cloud/bigquery-data-transfer');
const {status} = require('@grpc/grpc-js');

const client = new DataTransferServiceClient();

/**
 * Deletes a transfer run.
 * This action removes a specific execution instance of a transfer configuration.
 *
 * @param {string} projectId The Google Cloud project ID (for example, 'example-project-id').
 * @param {string} location The location of the transfer config (for example, 'us-central1').
 * @param {string} transferConfigId The ID of the transfer configuration (for example, '1234a123-123a-123a-123a-123456789abc').
 * @param {string} runId The ID of the transfer run (for example, '9876b987-987b-987b-987b-987654321cba').
 */
async function deleteTransferRun(
  projectId,
  location = 'us-central1',
  transferConfigId = '1234a123-123a-123a-123a-123456789abc',
  runId = '9876b987-987b-987b-987b-987654321cba',
) {
  const name = client.projectLocationTransferConfigRunPath(
    projectId,
    location,
    transferConfigId,
    runId,
  );
  const request = {
    name,
  };

  try {
    await client.deleteTransferRun(request);
    console.log(`Deleted transfer run ${name}.`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Transfer run ${name} not found.`);
    } else {
      console.error('Error deleting transfer run:', err);
    }
  }
}

What's next

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