Retrieves information for a specific data source, such as Google Ads or YouTube, supported by the BigQuery Data Transfer Service.

## 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.api.gax.rpc.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.NotFoundException.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.DataSource.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.DataSourceName.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 java.io.IOException;

    public class GetDataSource {

      /**
       * Retrieves a data source definition by name.
       *
       * @param projectId The Google Cloud project ID (for example, "example-project-id").
       * @param dataSourceId The data source ID (for example, "google_cloud_storage").
       */
      public static void getDataSource(String projectId, String dataSourceId) {
        https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSourceName.html name = https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSourceName.html.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSourceName.html#com_google_cloud_bigquery_datatransfer_v1_DataSourceName_ofProjectDataSourceName_java_lang_String_java_lang_String_(projectId, dataSourceId);

        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.html client = 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.DataSource.html response = client.getDataSource(name);

          System.out.printf("Retrieved data source: %s%n", response.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSource.html#com_google_cloud_bigquery_datatransfer_v1_DataSource_getName__());
          System.out.printf("Display Name: %s%n", response.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSource.html#com_google_cloud_bigquery_datatransfer_v1_DataSource_getDisplayName__());
          System.out.printf("Description: %s%n", response.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSource.html#com_google_cloud_bigquery_datatransfer_v1_DataSource_getDescription__());
          System.out.printf("Client ID: %s%n", response.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSource.html#com_google_cloud_bigquery_datatransfer_v1_DataSource_getClientId__());
          System.out.printf("Supports custom schedule: %s%n", response.https://docs.cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataSource.html#com_google_cloud_bigquery_datatransfer_v1_DataSource_getSupportsCustomSchedule__());
        } catch (https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.NotFoundException.html err) {
          System.err.printf("error: data source '%s' not found: %s%n", name, err.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ErrorDetails.html#com_google_api_gax_rpc_ErrorDetails__T_getMessage_java_lang_Class_T__());
        } catch (https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html | IOException err) {
          System.err.printf("error: failed to get data source '%s': %s%n", name, err.https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ErrorDetails.html#com_google_api_gax_rpc_ErrorDetails__T_getMessage_java_lang_Class_T__());
        }
      }

### 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').v1;
    const {status} = require('@grpc/grpc-js');

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

    /**
     * Retrieves a supported data source and returns its settings.
     * This sample shows how to get a data source's details, to understand its parameters and capabilities before creating a transfer.
     *
     * @param {string} projectId The project ID to use, for example 'example-project-id'
     * @param {string} location The location to use, for example 'us-central1'
     * @param {string} dataSourceId The data source ID to use, for example 'google_cloud_storage'
     */
    async function getDataSource(projectId, location, dataSourceId) {
      const name = client.https://docs.cloud.google.com/nodejs/docs/reference/bigquery-data-transfer/latest/bigquery-data-transfer/v1.datatransferserviceclient.html(
        projectId,
        location,
        dataSourceId,
      );

      const request = {
        name,
      };

      try {
        const [dataSource] = await client.getDataSource(request);
        console.log(`Data source ${dataSource.name} retrieved:`);
        console.log(`  Display Name: ${dataSource.displayName}`);
        console.log(`  Description: ${dataSource.description}`);
        console.log(`  Data Source ID: ${dataSource.dataSourceId}`);
      } catch (err) {
        if (err.code === status.NOT_FOUND) {
          console.error(
            `Data source ${dataSourceId} not found in project ${projectId} in location ${location}.`,
          );
        } else {
          console.error(`Error getting data source ${dataSourceId}:`, err);
        }
      }
    }

### Python


Before trying this sample, follow the Python 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 Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/bigquery/latest).


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 google.api_core.exceptions
    from google.cloud import https://docs.cloud.google.com/python/docs/reference/bigquerydatatransfer/latest

    client = https://docs.cloud.google.com/python/docs/reference/bigquerydatatransfer/latest.https://docs.cloud.google.com/python/docs/reference/bigquerydatatransfer/latest/google.cloud.bigquery_datatransfer_v1.services.data_transfer_service.DataTransferServiceClient.html()


    def get_data_source(project_id: str, data_source_id: str) -> None:
        """Retrieves a data source definition by name.

        This sample shows how to get a data source definition, which includes its
        display name, description, and other properties.

        Args:
            project_id: The Google Cloud project ID.
            data_source_id: The data source ID, for example, 'google_cloud_storage'.
        """
        name = client.https://docs.cloud.google.com/python/docs/reference/bigquerydatatransfer/latest/google.cloud.bigquery_datatransfer_v1.services.data_transfer_service.DataTransferServiceClient.html#google_cloud_bigquery_datatransfer_v1_services_data_transfer_service_DataTransferServiceClient_data_source_path(project=project_id, data_source=data_source_id)

        try:
            response = client.https://docs.cloud.google.com/python/docs/reference/bigquerydatatransfer/latest/google.cloud.bigquery_datatransfer_v1.services.data_transfer_service.DataTransferServiceClient.html#google_cloud_bigquery_datatransfer_v1_services_data_transfer_service_DataTransferServiceClient_get_data_source(name=name)
            print(f"Retrieved data source: {response.name}")
            print(f"Display Name: {response.display_name}")
            print(f"Description: {response.description}")
            print(f"Client ID: {response.client_id}")
            print(f"Supports custom schedule: {response.supports_custom_schedule}")
        except google.api_core.exceptions.NotFound:
            print(f"Error: Data source '{name}' was not found.")

## 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).