List data transfer configurations

Lists all BigQuery Data Transfer Service transfer configurations for a given project.

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. ListTransferConfigsRequest 
 
 ; 
 import 
  
 com.google.cloud.bigquery.datatransfer.v1. ProjectName 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 // Sample to get list of transfer config 
 public 
  
 class 
 ListTransferConfigs 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 // TODO(developer): Replace these variables before running the sample. 
  
 final 
  
 String 
  
 projectId 
  
 = 
  
 "MY_PROJECT_ID" 
 ; 
  
 listTransferConfigs 
 ( 
 projectId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 listTransferConfigs 
 ( 
 String 
  
 projectId 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 try 
  
 ( 
  DataTransferServiceClient 
 
  
 dataTransferServiceClient 
  
 = 
  
  DataTransferServiceClient 
 
 . 
 create 
 ()) 
  
 { 
  
  ProjectName 
 
  
 parent 
  
 = 
  
  ProjectName 
 
 . 
 of 
 ( 
 projectId 
 ); 
  
  ListTransferConfigsRequest 
 
  
 request 
  
 = 
  
  ListTransferConfigsRequest 
 
 . 
 newBuilder 
 (). 
 setParent 
 ( 
 parent 
 . 
  toString 
 
 ()). 
 build 
 (); 
  
 dataTransferServiceClient 
  
 . 
 listTransferConfigs 
 ( 
 request 
 ) 
  
 . 
 iterateAll 
 () 
  
 . 
 forEach 
 ( 
 config 
  
 - 
>  
 System 
 . 
 out 
 . 
 print 
 ( 
 "Success! Config ID :" 
  
 + 
  
 config 
 . 
 getName 
 () 
  
 + 
  
 "\n" 
 )); 
  
 } 
  
 catch 
  
 ( 
  ApiException 
 
  
 ex 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Config list not found due to error." 
  
 + 
  
 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 
 
 (); 
 /** 
 * Lists all transfer configurations for a project. 
 * This shows how to iterate through all the transfer configurations in a project. 
 * 
 * @param {string} projectId Google Cloud Project ID (for example, 'example-project-id'). 
 * @param {string} [location="us-central1"] Google Cloud location (for example, 'us-central1'). 
 */ 
 async 
  
 function 
  
 listTransferConfigs 
 ( 
 projectId 
 , 
  
 location 
  
 = 
  
 'us-central1' 
 ) 
  
 { 
  
 const 
  
 request 
  
 = 
  
 { 
  
 parent 
 : 
  
 `projects/ 
 ${ 
 projectId 
 } 
 /locations/ 
 ${ 
 location 
 } 
 ` 
 , 
  
 }; 
  
 try 
  
 { 
  
 const 
  
 [ 
 configs 
 ] 
  
 = 
  
 await 
  
 client 
 . 
 listTransferConfigs 
 ( 
 request 
 ); 
  
 if 
  
 ( 
 configs 
 . 
 length 
  
 === 
  
 0 
 ) 
  
 { 
  
 console 
 . 
 error 
 ( 
  
 `No transfer configurations found in project ' 
 ${ 
 projectId 
 } 
 ' at location ' 
 ${ 
 location 
 } 
 '.` 
 , 
  
 ); 
  
 return 
 ; 
  
 } 
  
 console 
 . 
 log 
 ( 
 `Found 
 ${ 
 configs 
 . 
 length 
 } 
 transfer configurations:` 
 ); 
  
 for 
  
 ( 
 const 
  
 config 
  
 of 
  
 configs 
 ) 
  
 { 
  
 console 
 . 
 log 
 ( 
 `\nConfiguration: 
 ${ 
 config 
 . 
 name 
 } 
 ` 
 ); 
  
 console 
 . 
 log 
 ( 
 `  Display Name: 
 ${ 
 config 
 . 
 displayName 
 } 
 ` 
 ); 
  
 console 
 . 
 log 
 ( 
 `  Data Source ID: 
 ${ 
 config 
 . 
 dataSourceId 
 } 
 ` 
 ); 
  
 console 
 . 
 log 
 ( 
 `  Destination Dataset ID: 
 ${ 
 config 
 . 
 destinationDatasetId 
 } 
 ` 
 ); 
  
 console 
 . 
 log 
 ( 
 `  State: 
 ${ 
 config 
 . 
 state 
 } 
 ` 
 ); 
  
 } 
  
 } 
  
 catch 
  
 ( 
 err 
 ) 
  
 { 
  
 if 
  
 ( 
 err 
 . 
 code 
  
 === 
  
 status 
 . 
 NOT_FOUND 
 ) 
  
 { 
  
 console 
 . 
 error 
 ( 
  
 `Project ' 
 ${ 
 projectId 
 } 
 ' not found or BigQuery Data Transfer API is not enabled.` 
 , 
  
 ); 
  
 } 
  
 else 
  
 { 
  
 console 
 . 
 error 
 ( 
 'Error listing transfer configurations:' 
 , 
  
 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_v1 
 
 client 
 = 
  bigquery_datatransfer_v1 
 
 . 
  DataTransferServiceClient 
 
 () 
 def 
  
 list_transfer_configs 
 ( 
 project_id 
 : 
 str 
 , 
 location 
 : 
 str 
 ) 
 - 
> None 
 : 
  
 """Lists transfer configurations in a given project. 
 This sample demonstrates how to list all transfer configurations in a project. 
 Args: 
 project_id: The Google Cloud project ID. 
 location: The geographic location of the transfer config, for example "us-central1" 
 """ 
 parent 
 = 
 client 
 . 
  common_location_path 
 
 ( 
 project_id 
 , 
 location 
 ) 
 try 
 : 
 for 
 config 
 in 
 client 
 . 
  list_transfer_configs 
 
 ( 
 parent 
 = 
 parent 
 ): 
 print 
 ( 
 f 
 "Name: 
 { 
 config 
 . 
 name 
 } 
 " 
 ) 
 print 
 ( 
 f 
 "Display Name: 
 { 
 config 
 . 
 display_name 
 } 
 " 
 ) 
 print 
 ( 
 f 
 "Data source: 
 { 
 config 
 . 
 data_source_id 
 } 
 " 
 ) 
 print 
 ( 
 f 
 "Destination dataset: 
 { 
 config 
 . 
 destination_dataset_id 
 } 
 " 
 ) 
 if 
 "time_based_schedule" 
 in 
 config 
 . 
 schedule_options_v2 
 : 
 print 
 ( 
 f 
 "Schedule: 
 { 
 config 
 . 
 schedule_options_v2 
 . 
 time_based_schedule 
 . 
 schedule 
 } 
 " 
 ) 
 else 
 : 
 print 
 ( 
 "Schedule: None" 
 ) 
 print 
 ( 
 "---" 
 ) 
 except 
 google 
 . 
 api_core 
 . 
 exceptions 
 . 
 NotFound 
 : 
 print 
 ( 
 f 
 "Error: Project ' 
 { 
 project_id 
 } 
 ' not found or contains no transfer configs." 
 ) 
 except 
 google 
 . 
 api_core 
 . 
 exceptions 
 . 
 PermissionDenied 
 : 
 print 
 ( 
 f 
 "Error: Permission denied for project ' 
 { 
 project_id 
 } 
 '. Please ensure you have the correct permissions." 
 ) 
 

What's next

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

Create a Mobile Website
View Site in Mobile | Classic
Share by: