Retrieve metadata for a Dataflow template stored in Cloud Storage.

## Code sample

### Go


To authenticate to Dataflow, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```go

import (
	"context"
	"fmt"
	"io"

	dataflow "cloud.google.com/go/dataflow/apiv1beta3"
	dataflowpb "cloud.google.com/go/dataflow/apiv1beta3/dataflowpb"
)

// getTemplate retrieves metadata for a Cloud Dataflow template.
func getTemplate(ctx context.Context, w io.Writer, projectID string, locationID string, gcsPath string) error {
	client, err := dataflow.NewTemplatesClient(ctx)
	if err != nil {
		return fmt.Errorf("NewTemplatesClient failed: %w", err)
	}
	defer client.Close()

	req := &dataflowpb.GetTemplateRequest{
		ProjectId: projectID,
		Location:  locationID,
		Template: &dataflowpb.GetTemplateRequest_GcsPath{
			GcsPath: gcsPath,
		},
		View: dataflowpb.GetTemplateRequest_METADATA_ONLY,
	}

	resp, err := client.GetTemplate(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetTemplate: %w", err)
	}

	fmt.Fprintf(w, "Template name: %s\n", resp.GetMetadata().GetName())
	fmt.Fprintf(w, "Description: %s\n", resp.GetMetadata().GetDescription())

	return nil
}
```

### Node.js


To authenticate to Dataflow, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```javascript
'use strict';

const {TemplatesServiceClient} = require('@google-cloud/dataflow');
const {status} = require('@grpc/grpc-js');

const client = new TemplatesServiceClient();

/**
 * Use the getTemplate method
 *
 * @param {string} projectId - The ID of the Google Cloud project that the job belongs to.
 * @param {string} locationId - The regional endpoint to which to direct the request (e.g., 'us-central1').
 * @param {string} gcsPath - A Cloud Storage path to the template to retrieve, beginning with 'gs://'.
 */
async function getTemplate(projectId, locationId, gcsPath) {
  try {
    const request = {
      projectId,
      location: locationId,
      gcsPath,
      view: 'METADATA_ONLY',
    };

    const [response] = await client.getTemplate(request);

    console.log(`Template type: ${response.templateType}`);
    if (response.metadata) {
      console.log(`Template name: ${response.metadata.name}`);
      console.log(`Template description: ${response.metadata.description}`);
    }

    return response;
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Template not found at ${gcsPath}: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied accessing template: ${err.message}`);
    } else if (err.code === status.INVALID_ARGUMENT) {
      console.error(`Invalid argument provided: ${err.message}`);
    } else {
      console.error(`API error retrieving template: ${err.message}`);
    }
    throw err;
  }
}

module.exports = { getTemplate };
```

## 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.md.txt?product=dataflow).