Delete a data transfer configuration

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:

Code sample

Java

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

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

  import 
  
 com.google.api.gax.rpc. ApiException 
 
 ; 
 import 
  
 com.google.cloud.bigquery.datatransfer.v1. DataTransferServiceClient 
 
 ; 
 import 
  
 com.google.cloud.bigquery.datatransfer.v1. DeleteTransferConfigRequest 
 
 ; 
 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 
  
 ( 
  DataTransferServiceClient 
 
  
 dataTransferServiceClient 
  
 = 
  
  DataTransferServiceClient 
 
 . 
 create 
 ()) 
  
 { 
  
  DeleteTransferConfigRequest 
 
  
 request 
  
 = 
  
  DeleteTransferConfigRequest 
 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 configId 
 ). 
 build 
 (); 
  
 dataTransferServiceClient 
 . 
 deleteTransferConfig 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Transfer config deleted successfully" 
 ); 
  
 } 
  
 catch 
  
 ( 
  ApiException 
 
  
 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 . 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 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 
 . 
  projectLocationTransferConfigPath 
 
 ( 
  
 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 
 ); 
  
 } 
  
 } 
 } 
 

Python

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

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

  import 
  
 google.api_core.exceptions 
 from 
  
 google.cloud 
  
 import 
 bigquery_datatransfer 
 transfer_client 
 = 
 bigquery_datatransfer 
 . 
  DataTransferServiceClient 
 
 () 
 transfer_config_name 
 = 
 "projects/1234/locations/us/transferConfigs/abcd" 
 try 
 : 
 transfer_client 
 . 
  delete_transfer_config 
 
 ( 
 name 
 = 
 transfer_config_name 
 ) 
 except 
 google 
 . 
 api_core 
 . 
 exceptions 
 . 
 NotFound 
 : 
 print 
 ( 
 "Transfer config not found." 
 ) 
 else 
 : 
 print 
 ( 
 f 
 "Deleted transfer config: 
 { 
 transfer_config_name 
 } 
 " 
 ) 
 

What's next

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

Design a Mobile Site
View Site in Mobile | Classic
Share by: