Get a transfer configuration

Retrieves the details for a transfer configuration from the BigQuery Data Transfer Service, such as its schedule and destination.

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. GetTransferConfigRequest 
 
 ; 
 import 
  
 com.google.cloud.bigquery.datatransfer.v1. TransferConfig 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 // Sample to get config info. 
 public 
  
 class 
 GetTransferConfigInfo 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 // TODO(developer): Replace these variables before running the sample. 
  
 String 
  
 configId 
  
 = 
  
 "MY_CONFIG_ID" 
 ; 
  
 // i.e projects/{project_id}/transferConfigs/{config_id}` or 
  
 // `projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}` 
  
 getTransferConfigInfo 
 ( 
 configId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 getTransferConfigInfo 
 ( 
 String 
  
 configId 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 try 
  
 ( 
  DataTransferServiceClient 
 
  
 dataTransferServiceClient 
  
 = 
  
  DataTransferServiceClient 
 
 . 
 create 
 ()) 
  
 { 
  
  GetTransferConfigRequest 
 
  
 request 
  
 = 
  
  GetTransferConfigRequest 
 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 configId 
 ). 
 build 
 (); 
  
  TransferConfig 
 
  
 info 
  
 = 
  
 dataTransferServiceClient 
 . 
 getTransferConfig 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 print 
 ( 
 "Config info retrieved successfully." 
  
 + 
  
 info 
 . 
  getName 
 
 () 
  
 + 
  
 "\n" 
 ); 
  
 } 
  
 catch 
  
 ( 
  ApiException 
 
  
 ex 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 print 
 ( 
 "config not found." 
  
 + 
  
 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 
' 
 ). 
 v1 
 ; 
 const 
  
 { 
 status 
 } 
  
 = 
  
 require 
 ( 
 '@grpc/grpc-js' 
 ); 
 const 
  
 client 
  
 = 
  
 new 
  
  DataTransferServiceClient 
 
 (); 
 /** 
 * Gets a transfer configuration for a BigQuery data transfer. 
 * A transfer configuration contains all metadata needed to perform a data transfer. 
 * 
 * @param {string} projectId The Google Cloud project ID (for example, 'example-project-id'). 
 * @param {string} location The Google Cloud region (for example, 'us-central1'). 
 * @param {string} configId The transfer configuration ID (for example, '1234a567-b89c-12d3-45e6-f789g01h23i4'). 
 */ 
 async 
  
 function 
  
 getTransferConfig 
 ( 
 projectId 
 , 
  
 location 
 , 
  
 configId 
 ) 
  
 { 
  
 const 
  
 name 
  
 = 
  
 client 
 . 
  projectLocationTransferConfigPath 
 
 ( 
  
 projectId 
 , 
  
 location 
 , 
  
 configId 
 , 
  
 ); 
  
 const 
  
 request 
  
 = 
  
 { 
  
 name 
 , 
  
 }; 
  
 try 
  
 { 
  
 const 
  
 [ 
 config 
 ] 
  
 = 
  
 await 
  
 client 
 . 
 getTransferConfig 
 ( 
 request 
 ); 
  
 console 
 . 
 log 
 ( 
 `Got transfer config: 
 ${ 
 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 
 ( 
  
 `Transfer config 
 ${ 
 configId 
 } 
 not found in project 
 ${ 
 projectId 
 } 
 in location 
 ${ 
 location 
 } 
 .` 
 , 
  
 ); 
  
 } 
  
 else 
  
 { 
  
 console 
 . 
 error 
 ( 
 `Error getting 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_v1 
 
 client 
 = 
  bigquery_datatransfer_v1 
 
 . 
  DataTransferServiceClient 
 
 () 
 def 
  
 get_transfer_config 
 ( 
 project_id 
 : 
 str 
 , 
 location 
 : 
 str 
 , 
 transfer_config_id 
 : 
 str 
 , 
 ) 
 - 
> None 
 : 
  
 """Gets information about a data transfer configuration. 
 This sample demonstrates how to retrieve the details of a BigQuery 
 Data Transfer Service configuration, which contains metadata about a 
 data transfer, such as its schedule and destination. 
 Args: 
 project_id: The Google Cloud project ID. 
 location: The geographic location of the transfer config, for example "us-central1" 
 transfer_config_id: The transfer configuration ID 
 """ 
 try 
 : 
 transfer_config_name 
 = 
 client 
 . 
  transfer_config_path 
 
 ( 
 project 
 = 
 f 
 " 
 { 
 project_id 
 } 
 /locations/ 
 { 
 location 
 } 
 " 
 , 
 transfer_config 
 = 
 transfer_config_id 
 , 
 ) 
 transfer_config 
 = 
 client 
 . 
  get_transfer_config 
 
 ( 
 name 
 = 
 transfer_config_name 
 ) 
 print 
 ( 
 f 
 "Got transfer config: 
 { 
 transfer_config 
 . 
 name 
 } 
 " 
 ) 
 print 
 ( 
 f 
 "Display name: 
 { 
 transfer_config 
 . 
 display_name 
 } 
 " 
 ) 
 print 
 ( 
 f 
 "Destination dataset: 
 { 
 transfer_config 
 . 
 destination_dataset_id 
 } 
 " 
 ) 
 print 
 ( 
 f 
 "Data source: 
 { 
 transfer_config 
 . 
 data_source_id 
 } 
 " 
 ) 
 if 
 "time_based_schedule" 
 in 
 transfer_config 
 . 
 schedule_options_v2 
 : 
 print 
 ( 
 f 
 "Schedule: 
 { 
 transfer_config 
 . 
 schedule_options_v2 
 . 
 time_based_schedule 
 . 
 schedule 
 } 
 " 
 ) 
 else 
 : 
 print 
 ( 
 "Schedule: None" 
 ) 
 except 
 google 
 . 
 api_core 
 . 
 exceptions 
 . 
 NotFound 
 : 
 print 
 ( 
 f 
 "Error: Transfer config ' 
 { 
 transfer_config_name 
 } 
 ' not found." 
 ) 
 

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: