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 theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

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

importcom.google.api.gax.rpc.ApiException;importcom.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;importcom.google.cloud.bigquery.datatransfer.v1.ListTransferConfigsRequest;importcom.google.cloud.bigquery.datatransfer.v1.ProjectName;importjava.io.IOException;// Sample to get list of transfer configpublicclassListTransferConfigs{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.finalStringprojectId="MY_PROJECT_ID";listTransferConfigs(projectId);}publicstaticvoidlistTransferConfigs(StringprojectId)throwsIOException{try(DataTransferServiceClientdataTransferServiceClient=DataTransferServiceClient.create()){ProjectNameparent=ProjectName.of(projectId);ListTransferConfigsRequestrequest=ListTransferConfigsRequest.newBuilder().setParent(parent.toString()).build();dataTransferServiceClient.listTransferConfigs(request).iterateAll().forEach(config->System.out.print("Success! Config ID :"+config.getName()+"\n"));}catch(ApiExceptionex){System.out.println("Config list not found due to error."+ex.toString());}}}

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

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

const{DataTransferServiceClient,}=require('@google-cloud/bigquery-data-transfer');const{status}=require('@grpc/grpc-js');constclient=newDataTransferServiceClient();/** * 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'). */asyncfunctionlistTransferConfigs(projectId,location='us-central1'){constrequest={parent:`projects/${projectId}/locations/${location}`,};try{const[configs]=awaitclient.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(constconfigofconfigs){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 thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

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

fromgoogle.cloudimportbigquery_datatransfertransfer_client=bigquery_datatransfer.DataTransferServiceClient()project_id="my-project"parent=transfer_client.common_project_path(project_id)configs=transfer_client.list_transfer_configs(parent=parent)print("Got the following configs:")forconfiginconfigs:print(f"\tID:{config.name}, Schedule:{config.schedule}")

What's next

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

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.