Deletes a data transfer configuration in the BigQuery Data Transfer Service. Deleting a configuration stops future transfer runs but does not remove data that has already been transferred to BigQuery.

## Explore further


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

- [Manage transfers](https://docs.cloud.google.com/bigquery/docs/working-with-transfers)
- [Scheduling queries](https://docs.cloud.google.com/bigquery/docs/scheduling-queries)

## Code sample

### Java


Before trying this sample, follow the Java setup instructions in the
[BigQuery quickstart using
client libraries](https://docs.cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries).


For more information, see the
[BigQuery Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquery/latest/overview).


To authenticate to BigQuery, set up Application Default Credentials.
For more information, see

[Set up authentication for client libraries](https://docs.cloud.google.com/bigquery/docs/authentication#client-libs).

    import com.google.api.gax.rpc.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html;
    import com.google.cloud.bigquery.datatransfer.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.html;
    import com.google.cloud.bigquery.datatransfer.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DeleteTransferConfigRequest.html;
    import java.io.IOException;

    // Sample to delete a transfer config
    public class DeleteTransferConfig {

      public static void main(String[] args) throws IOException {
        // TODO(developer): Replace these variables before running the sample.
        // i.e projects/{project_id}/transferConfigs/{config_id}` or
        // `projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}`
        String configId = "MY_CONFIG_ID";
        deleteTransferConfig(configId);
      }

      public static void deleteTransferConfig(String configId) throws IOException {
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.html dataTransferServiceClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.html.create()) {
          https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DeleteTransferConfigRequest.html request =
              https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DeleteTransferConfigRequest.html.newBuilder().setName(configId).build();
          dataTransferServiceClient.deleteTransferConfig(request);
          System.out.println("Transfer config deleted successfully");
        } catch (https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html ex) {
          System.out.println("Transfer config was not deleted." + ex.toString());
        }
      }
    }

### Node.js


Before trying this sample, follow the Node.js setup instructions in the
[BigQuery quickstart using
client libraries](https://docs.cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries).


For more information, see the
[BigQuery Node.js API
reference documentation](https://googleapis.dev/nodejs/bigquery/latest/index.html).


To authenticate to BigQuery, set up Application Default Credentials.
For more information, see

[Set up authentication for client libraries](https://docs.cloud.google.com/bigquery/docs/authentication#client-libs).

    const {
      DataTransferServiceClient,
    } = require('https://docs.cloud.google.com/nodejs/docs/reference/bigquery-data-transfer/latest/overview.html');
    const {status} = require('@grpc/grpc-js');

    const client = new https://docs.cloud.google.com/nodejs/docs/reference/bigquery-data-transfer/latest/overview.html();

    /**
     * Deletes a data transfer configuration.
     * This sample demonstrates how to delete a transfer configuration, which also
     * removes its associated transfer runs and logs.
     *
     * @param {string} projectId Your Google Cloud project ID, for example 'example-project-id'
     * @param {string} location The BigQuery location, for example 'us-central1'
     * @param {string} configId The transfer configuration ID, for example '1234a567-b89c-12d3-45e6-f789g01h23i4'
     */
    async function deleteTransferConfig(projectId, location, configId) {
      const name = client.https://docs.cloud.google.com/nodejs/docs/reference/bigquery-data-transfer/latest/bigquery-data-transfer/v1.datatransferserviceclient.html(
        projectId,
        location,
        configId,
      );
      const request = {
        name,
      };

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

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=bigquerydatatransferservice).