View parameter version details

This page describes how to view the details of a specific parameter version including the version name, its value, creation time, update time, and state.

Required roles

To get the permissions that you need to view parameter version details, ask your administrator to grant you the Parameter Manager Parameter Viewer (roles/parametermanager.parameterViewer) IAM role on the parameter, project, folder, or organization. For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

View parameter version details

To view the details of a parameter version, use one of the following methods:

Global parameters

Console

  1. In the Google Cloud console, go to the Secret Manager page.

    Go to Secret Manager

  2. Click Parameter Manager to go to the Parameter Manager page. You'll see the list of parameters for that project.

  3. Click the parameter name to access its versions.

    The parameter details page opens with the Versions tab in focus where you can see all the versions of the selected parameter. For each version, the version ID and its metadata is also displayed in the table.

  4. Certain parameter versions contain secret values. To inspect the raw parameter payload before secret substitution, select the version and then click View payload from the Actions menu.

    Viewing the payload lets you verify the parameter's structure and content before secret substitution. This helps you check the parameter configuration and understand its structure.

gcloud

Before using any of the command data below, make the following replacements:

  • PARAMETER_VERSION_ID: the ID of the parameter version
  • PARAMETER_ID: the name of the parameter

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud parametermanager parameters versions describe PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=global

Windows (PowerShell)

gcloud parametermanager parameters versions describe PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=global

Windows (cmd.exe)

gcloud parametermanager parameters versions describe PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=global

You should receive a response similar to the following:

createTime: '2024-11-14T10:07:12.883361876Z'
name: projects/production-1/locations/global/parameters/app_config/versions/configv3
payload:
  data: YWJj
updateTime: '2024-11-14T10:07:13.331806596Z'

REST

Before using any of the request data, make the following replacements:

  • PROJECT_ID: the Google Cloud project ID
  • PARAMETER_ID: the name of the parameter
  • PARAMETER_VERSION_ID: the ID of the parameter version

HTTP method and URL:

GET https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID

Request JSON body:

{}

To send your request, choose one of these options:

curl

Save the request body in a file named request.json, and execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID"

PowerShell

Save the request body in a file named request.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "name": "projects/production-1/locations/global/parameters/app_config/versions/configv1",
  "createTime": "2024-10-16T03:08:42.914611506Z",
  "updateTime": "2024-10-16T03:08:44.530493212Z",
  "payload": {
    "data": "cHJvamVjdDoNCiAgZGlzcGxheV9uYW1lOiBQTSBCYW5rDQogIGxvY2FsZTogZW4tVVMNCiAgcG9ydDogODA4MA0KICBkYl9wYXNzd29yZDogX19SRUZfXygiLy9zZWNyZXRtYW5hZ2VyLmdvb2dsZWFwaXMuY29tL3Byb2plY3RzL2FjbS1zYW1wbGUvc2VjcmV0cy9kYl9wYXNzd29yZC92ZXJzaW9ucy8xIikNCiAgbWFza19zZW5zaXRpdmVfZmllbGRzOiBmYWxzZQ=="
  }
}

C#

To run this code, first set up a C# development environment and install the Secret Manager C# SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.


using Google.Cloud.ParameterManager.V1;
using System.Text;

public class GetParameterVersionSample
{
    /// <summary>
    /// This function retrieves a parameter version using the Parameter Manager SDK for GCP.
    /// </summary>
    /// <param name="projectId">The ID of the project where the parameter is located.</param>
    /// <param name="parameterId">The ID of the parameter for which the version is to be retrieved.</param>
    /// <param name="versionId">The ID of the version to be retrieved.</param>
    /// <returns>The retrieved ParameterVersion object.</returns>
    public ParameterVersion GetParameterVersion(
        string projectId,
        string parameterId,
        string versionId)
    {
        // Create the client.
        ParameterManagerClient client = ParameterManagerClient.Create();

        // Build the resource name for the parameter version.
        ParameterVersionName parameterVersionName = new ParameterVersionName(projectId, "global", parameterId, versionId);

        // Call the API to get the parameter version.
        ParameterVersion parameterVersion = client.GetParameterVersion(parameterVersionName);

        // Print the retrieved parameter version name.
        Console.WriteLine($"Found regional parameter version {parameterVersion.Name} with state {(parameterVersion.Disabled ? "disabled" : "enabled")}");

        if (!parameterVersion.Disabled)
        {
            Console.WriteLine($"Payload: {Encoding.UTF8.GetString(parameterVersion.Payload.Data.ToByteArray())}");
        }

        // Return the retrieved parameter version.
        return parameterVersion;
    }
}

Go

To run this code, first set up a Go development environment and install the Secret Manager Go SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

import (
	"context"
	"fmt"
	"io"

	parametermanager "cloud.google.com/go/parametermanager/apiv1"
	parametermanagerpb "cloud.google.com/go/parametermanager/apiv1/parametermanagerpb"
)

// getParamVersion get parameter version using the Parameter Manager SDK for GCP.
//
// w: The io.Writer object used to write the output.
// projectID: The ID of the project where the parameter is located.
// parameterID: The ID of the parameter for which the version details are to be retrieved.
// versionID: The ID of the version to be retrieved.
//
// The function returns an error if the parameter version retrieval fails.
func getParamVersion(w io.Writer, projectID, parameterID, versionID string) error {
	// Create a context and a Parameter Manager client.
	ctx := context.Background()
	client, err := parametermanager.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("failed to create Parameter Manager client: %w", err)
	}
	defer client.Close()

	// Construct the name of the parameter to get the parameter version.
	name := fmt.Sprintf("projects/%s/locations/global/parameters/%s/versions/%s", projectID, parameterID, versionID)

	// Build the request to get parameter version.
	req := &parametermanagerpb.GetParameterVersionRequest{
		Name: name,
	}

	// Call the API to get parameter version.
	version, err := client.GetParameterVersion(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to get parameter version: %w", err)
	}

	// Find more details for the Parameter Version object here:
	// https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
	fmt.Fprintf(w, "Found parameter version %s with disabled state in %v\n", version.Name, version.Disabled)
	if !version.Disabled {
		fmt.Fprintf(w, "Payload: %s\n", version.Payload.Data)
	}
	return nil
}

Java

To run this code, first set up a Java development environment and install the Secret Manager Java SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.


import com.google.cloud.parametermanager.v1.ParameterManagerClient;
import com.google.cloud.parametermanager.v1.ParameterVersion;
import com.google.cloud.parametermanager.v1.ParameterVersionName;
import java.io.IOException;

/**
 * This class demonstrates how to get a parameter version using the Parameter Manager SDK for GCP.
 */
public class GetParamVersion {
  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String parameterId = "your-parameter-id";
    String versionId = "your-version-id";

    // Call the method to get a parameter version.
    getParamVersion(projectId, parameterId, versionId);
  }

  // This is an example snippet for getting a parameter version.
  public static ParameterVersion getParamVersion(
      String projectId, String parameterId, String versionId) throws IOException {
    // Initialize the client that will be used to send requests. This client only
    // needs to be created once, and can be reused for multiple requests.
    try (ParameterManagerClient client = ParameterManagerClient.create()) {
      String locationId = "global";

      // Build the parameter version name.
      ParameterVersionName parameterVersionName =
          ParameterVersionName.of(projectId, locationId, parameterId, versionId);

      // Get the parameter version.
      ParameterVersion parameterVersion =
          client.getParameterVersion(parameterVersionName.toString());
      // Find more details for the Parameter Version object here:
      // https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
      System.out.printf(
          "Found parameter version %s with state %s\n",
          parameterVersion.getName(), (parameterVersion.getDisabled() ? "disabled" : "enabled"));
      if (!parameterVersion.getDisabled()) {
        System.out.printf("Payload: %s\n", parameterVersion.getPayload().getData().toStringUtf8());
      }
      return parameterVersion;
    }
  }
}

Node.js

To run this code, first set up a Node.js development environment and install the Secret Manager Node.js SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const parameterId = 'my-parameter';
// const versionId = 'v1';

// Imports the Parameter Manager library
const {ParameterManagerClient} = require('@google-cloud/parametermanager');

// Instantiates a client
const client = new ParameterManagerClient();

async function getParamVersion() {
  // Construct the fully qualified parameter version name
  const name = client.parameterVersionPath(
    projectId,
    'global',
    parameterId,
    versionId
  );

  // Get the parameter version
  const [parameterVersion] = await client.getParameterVersion({
    name: name,
  });
  // Find more details for the Parameter Version object here:
  // https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
  console.log(
    `Found parameter version ${parameterVersion.name} with state ${parameterVersion.disabled ? 'disabled' : 'enabled'}`
  );
  if (!parameterVersion.disabled) {
    console.log(
      `Payload: ${parameterVersion.payload.data.toString('utf-8')}`
    );
  }
  return parameterVersion;
}

return await getParamVersion();

PHP

To run this code, first learn about using PHP on Google Cloud and install the Secret Manager PHP SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

// Import necessary classes for retrieve a parameter.
use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient;
use Google\Cloud\ParameterManager\V1\GetParameterVersionRequest;

/**
 * Retrieves a parameter version using the Parameter Manager SDK for GCP.
 *
 * @param string $projectId The Google Cloud Project ID (e.g. 'my-project')
 * @param string $parameterId The Parameter ID (e.g. 'my-param')
 * @param string $versionId The Version ID (e.g. 'my-param-version')
 */
function get_param_version(string $projectId, string $parameterId, string $versionId): void
{
    // Create a client for the Parameter Manager service.
    $client = new ParameterManagerClient();

    // Build the resource name of the parameter version.
    $parameterVersionName = $client->parameterVersionName($projectId, 'global', $parameterId, $versionId);

    // Prepare the request to get the parameter version.
    $request = (new GetParameterVersionRequest())
        ->setName($parameterVersionName);

    // Retrieve the parameter version using the client.
    $parameterVersion = $client->getParameterVersion($request);

    // Print the retrieved parameter version details.
    printf('Found parameter version %s with state %s' . PHP_EOL, $parameterVersion->getName(), $parameterVersion->getDisabled() ? 'disabled' : 'enabled');
    if (!($parameterVersion->getDisabled())) {
        printf('Payload: %s' . PHP_EOL, $parameterVersion->getPayload()->getData());
    }
}

Python

To run this code, first set up a Python development environment and install the Secret Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

def get_param_version(
    project_id: str, parameter_id: str, version_id: str
) -> parametermanager_v1.ParameterVersion:
    """
    Retrieves the details of a specific version of an
    existing parameter in the specified
    project using the Google Cloud Parameter Manager SDK.

    Args:
        project_id (str): The ID of the project where the parameter is located.
        parameter_id (str): The ID of the parameter for
        which the version details are to be retrieved.
        version_id (str): The ID of the version to be retrieved.

    Returns:
        parametermanager_v1.ParameterVersion: An object
        representing the parameter version.

    Example:
        get_param_version(
            "my-project",
            "my-global-parameter",
            "v1"
        )
    """
    # Import the necessary library for Google Cloud Parameter Manager.
    from google.cloud import parametermanager_v1

    # Create the Parameter Manager client.
    client = parametermanager_v1.ParameterManagerClient()

    # Build the resource name of the parameter version.
    name = client.parameter_version_path(project_id, "global", parameter_id, version_id)

    # Define the request to get the parameter version details.
    request = parametermanager_v1.GetParameterVersionRequest(name=name)

    # Get the parameter version details.
    response = client.get_parameter_version(request=request)

    # Show parameter version details.
    # Find more details for the Parameter Version object here:
    # https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
    print(f"Found parameter version {response.name} with state {'disabled' if response.disabled else 'enabled'}")
    if not response.disabled:
        print(f"Payload: {response.payload.data.decode('utf-8')}")

Ruby

To run this code, first set up a Ruby development environment and install the Secret Manager Ruby SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

require "google/cloud/parameter_manager"

##
# Retrieve a parameter version
#
# @param project_id [String] The Google Cloud project (e.g. "my-project")
# @param parameter_id [String] The parameter name (e.g. "my-parameter")
# @param version_id [String] The version name (e.g. "my-version")
#
def get_param_version project_id:, parameter_id:, version_id:
  # Create a Parameter Manager client.
  client = Google::Cloud::ParameterManager.parameter_manager

  # Build the resource name of the parent project.
  name = client.parameter_version_path project: project_id, location: "global", parameter: parameter_id,
                                       parameter_version: version_id

  # Retrieve the parameter version.
  param_version = client.get_parameter_version name: name

  # Print the retrieved parameter version name.
  puts "Found parameter version #{param_version.name} with state #{param_version.disabled ? 'disabled' : 'enabled'}"

  # Use a guard clause to return early if the parameter version is disabled.
  return if param_version.disabled

  puts "Payload: #{param_version.payload.data}"
end

Regional parameters

Console

  1. In the Google Cloud console, go to the Secret Manager page.

    Go to Secret Manager

  2. Click Parameter Manager to go to the Parameter Manager page. You'll see the list of parameters for that project.

  3. Click the parameter name to access its versions.

    The parameter details page opens with the Versions tab in focus where you can see all the versions of the selected parameter. For each version, the version ID and its metadata is also displayed in the table.

  4. Certain parameter versions contain secret values. To inspect the raw parameter payload before secret substitution, select the version and then click View payload from the Actions menu.

    Viewing the payload lets you verify the parameter's structure and content before secret substitution. This helps you check the parameter configuration and understand its structure.

gcloud

Before using any of the command data below, make the following replacements:

  • PARAMETER_VERSION_ID: the ID of the parameter version
  • PARAMETER_ID: the name of the parameter
  • LOCATION: the Google Cloud location of the parameter

Execute the following command:

Linux, macOS, or Cloud Shell

gcloud parametermanager parameters versions describe PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=LOCATION

Windows (PowerShell)

gcloud parametermanager parameters versions describe PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=LOCATION

Windows (cmd.exe)

gcloud parametermanager parameters versions describe PARAMETER_VERSION_ID --parameter=PARAMETER_ID --location=LOCATION

You should receive a response similar to the following:

createTime: '2024-11-14T10:07:12.883361876Z'
name: projects/production-1/locations/us-central1/parameters/app_config/versions/configv3
payload:
  data: YWJj
updateTime: '2024-11-14T10:07:13.331806596Z'

REST

Before using any of the request data, make the following replacements:

  • LOCATION: the Google Cloud location of the parameter
  • PROJECT_ID: the Google Cloud project ID
  • PARAMETER_ID: the name of the parameter
  • PARAMETER_VERSION_ID: the ID of the parameter version

HTTP method and URL:

GET https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID?view=FULL

Request JSON body:

{}

To send your request, choose one of these options:

curl

Save the request body in a file named request.json, and execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID?view=FULL"

PowerShell

Save the request body in a file named request.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID?view=FULL" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "name": "projects/production-1/locations/us-central1/parameters/app_config/versions/configv2",
  "createTime": "2024-10-30T05:27:51.206825427Z",
  "updateTime": "2024-10-30T05:27:51.442194863Z",
  "payload": {
    "data": "YTogYgo="
  }
}

C#

To run this code, first set up a C# development environment and install the Secret Manager C# SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.


using Google.Cloud.ParameterManager.V1;
using System.Text;

public class GetRegionalParameterVersionSample
{
    /// <summary>
    /// This function retrieves a regional parameter version using the Parameter Manager SDK for GCP.
    /// </summary>
    /// <param name="projectId">The ID of the project where the parameter is located.</param>
    /// <param name="locationId">The ID of the region where the parameter is located.</param>
    /// <param name="parameterId">The ID of the parameter for which the version is to be retrieved.</param>
    /// <param name="versionId">The ID of the version to be retrieved.</param>
    /// <returns>The retrieved ParameterVersion object.</returns>
    public ParameterVersion GetRegionalParameterVersion(
        string projectId,
        string locationId,
        string parameterId,
        string versionId)
    {
        // Define the regional endpoint
        string regionalEndpoint = $"parametermanager.{locationId}.rep.googleapis.com";

        // Create the client with the regional endpoint
        ParameterManagerClient client = new ParameterManagerClientBuilder
        {
            Endpoint = regionalEndpoint
        }.Build();

        // Build the resource name for the parameter version in the specified regional locationId
        ParameterVersionName parameterVersionName = new ParameterVersionName(projectId, locationId, parameterId, versionId);

        // Call the API to get the parameter version
        ParameterVersion parameterVersion = client.GetParameterVersion(parameterVersionName);



        // Print the retrieved parameter version name
        Console.WriteLine($"Found regional parameter version {parameterVersion.Name} with state {(parameterVersion.Disabled ? "disabled" : "enabled")}");

        if (!parameterVersion.Disabled)
        {
            Console.WriteLine($"Payload: {Encoding.UTF8.GetString(parameterVersion.Payload.Data.ToByteArray())}");
        }

        // Return the retrieved parameter version
        return parameterVersion;
    }
}

Go

To run this code, first set up a Go development environment and install the Secret Manager Go SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

import (
	"context"
	"fmt"
	"io"

	parametermanager "cloud.google.com/go/parametermanager/apiv1"
	parametermanagerpb "cloud.google.com/go/parametermanager/apiv1/parametermanagerpb"
	"google.golang.org/api/option"
)

// getRegionalParamVersion gets a parameter version regional using the Parameter Manager SDK for GCP.
//
// w: The io.Writer object used to write the output.
// projectID: The ID of the project where the parameter is located.
// locationID: The ID of the region where the parameter is located.
// parameterID: The ID of the parameter for which the version is to be retrieved.
// versionID: The ID of the version to be retrieved.
//
// The function returns an error if the parameter version retrieval fails.
func getRegionalParamVersion(w io.Writer, projectID, locationID, parameterID, versionID string) error {
	// Create a new context.
	ctx := context.Background()

	// Create a Parameter Manager client.
	endpoint := fmt.Sprintf("parametermanager.%s.rep.googleapis.com:443", locationID)
	client, err := parametermanager.NewClient(ctx, option.WithEndpoint(endpoint))
	if err != nil {
		return fmt.Errorf("failed to create Parameter Manager client: %w", err)
	}
	defer client.Close()

	// Construct the name of the parameter version to retrieve.
	name := fmt.Sprintf("projects/%s/locations/%s/parameters/%s/versions/%s", projectID, locationID, parameterID, versionID)

	// Build the request to get the parameter version.
	req := &parametermanagerpb.GetParameterVersionRequest{
		Name: name,
	}

	// Call the API to get the parameter version.
	version, err := client.GetParameterVersion(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to get parameter version: %w", err)
	}

	// Find more details for the Parameter Version object here:
	// https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
	fmt.Fprintf(w, "Found regional parameter version %s with disabled state in %v\n", version.Name, version.Disabled)
	if !version.Disabled {
		fmt.Fprintf(w, "Payload: %s\n", version.Payload.Data)
	}
	return nil
}

Java

To run this code, first set up a Java development environment and install the Secret Manager Java SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.


import com.google.cloud.parametermanager.v1.ParameterManagerClient;
import com.google.cloud.parametermanager.v1.ParameterManagerSettings;
import com.google.cloud.parametermanager.v1.ParameterVersion;
import com.google.cloud.parametermanager.v1.ParameterVersionName;
import java.io.IOException;

/**
 * This class demonstrates how to get a regional parameter version using the Parameter Manager SDK
 * for GCP.
 */
public class GetRegionalParamVersion {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String locationId = "your-location-id";
    String parameterId = "your-parameter-id";
    String versionId = "your-version-id";

    // Call the method to get a regional parameter version.
    getRegionalParamVersion(projectId, locationId, parameterId, versionId);
  }

  // This is an example snippet that gets a regional parameter version.
  public static ParameterVersion getRegionalParamVersion(
      String projectId, String locationId, String parameterId, String versionId)
      throws IOException {
    // Endpoint to call the regional parameter manager server
    String apiEndpoint = String.format("parametermanager.%s.rep.googleapis.com:443", locationId);
    ParameterManagerSettings parameterManagerSettings =
        ParameterManagerSettings.newBuilder().setEndpoint(apiEndpoint).build();

    // Initialize the client that will be used to send requests. This client only
    // needs to be created once, and can be reused for multiple requests.
    try (ParameterManagerClient client = ParameterManagerClient.create(parameterManagerSettings)) {
      // Build the parameter version name.
      ParameterVersionName parameterVersionName =
          ParameterVersionName.of(projectId, locationId, parameterId, versionId);

      // Get the parameter version.
      ParameterVersion parameterVersion =
          client.getParameterVersion(parameterVersionName.toString());
      // Find more details for the Parameter Version object here:
      // https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
      System.out.printf(
          "Found regional parameter version %s with state %s\n",
          parameterVersion.getName(), (parameterVersion.getDisabled() ? "disabled" : "enabled"));
      if (!parameterVersion.getDisabled()) {
        System.out.printf("Payload: %s", parameterVersion.getPayload().getData().toStringUtf8());
      }
      return parameterVersion;
    }
  }
}

Node.js

To run this code, first set up a Node.js development environment and install the Secret Manager Node.js SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const locationId = 'us-central1';
// const parameterId = 'my-parameter';
// const versionId = 'v1';

// Imports the Parameter Manager library
const {ParameterManagerClient} = require('@google-cloud/parametermanager');

// Adding the endpoint to call the regional parameter manager server
const options = {
  apiEndpoint: `parametermanager.${locationId}.rep.googleapis.com`,
};

// Instantiates a client with regional endpoint
const client = new ParameterManagerClient(options);

async function getRegionalParamVersion() {
  // Construct the fully qualified parameter version name
  const name = client.parameterVersionPath(
    projectId,
    locationId,
    parameterId,
    versionId
  );

  // Get the parameter version
  const [parameterVersion] = await client.getParameterVersion({
    name: name,
  });

  // Find more details for the Parameter Version object here:
  // https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
  console.log(
    `Found regional parameter version ${parameterVersion.name} with state ${parameterVersion.disabled ? 'disabled' : 'enabled'}`
  );
  if (!parameterVersion.disabled) {
    console.log(
      `Payload: ${parameterVersion.payload.data.toString('utf-8')}`
    );
  }
  return parameterVersion;
}

return await getRegionalParamVersion();

PHP

To run this code, first learn about using PHP on Google Cloud and install the Secret Manager PHP SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

// Import necessary classes for retrieve a parameter.
use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient;
use Google\Cloud\ParameterManager\V1\GetParameterVersionRequest;

/**
 * Retrieves a regional parameter version using the Parameter Manager SDK for GCP.
 *
 * @param string $projectId The Google Cloud Project ID (e.g. 'my-project')
 * @param string $locationId The Parameter Location (e.g. 'us-central1')
 * @param string $parameterId The Parameter ID (e.g. 'my-param')
 * @param string $versionId The Version ID (e.g. 'my-param-version')
 */
function get_regional_param_version(string $projectId, string $locationId, string $parameterId, string $versionId): void
{
    // Specify regional endpoint.
    $options = ['apiEndpoint' => "parametermanager.$locationId.rep.googleapis.com"];

    // Create a client for the Parameter Manager service.
    $client = new ParameterManagerClient($options);

    // Build the resource name of the parameter version.
    $parameterVersionName = $client->parameterVersionName($projectId, $locationId, $parameterId, $versionId);

    // Prepare the request to get the parameter version.
    $request = (new GetParameterVersionRequest())
        ->setName($parameterVersionName);

    // Retrieve the parameter version using the client.
    $parameterVersion = $client->getParameterVersion($request);

    printf('Found regional parameter version %s with state %s' . PHP_EOL, $parameterVersion->getName(), $parameterVersion->getDisabled() ? 'disabled' : 'enabled');
    if (!($parameterVersion->getDisabled())) {
        printf('Payload: %s' . PHP_EOL, $parameterVersion->getPayload()->getData());
    }
}

Python

To run this code, first set up a Python development environment and install the Secret Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

def get_regional_param_version(
    project_id: str, location_id: str, parameter_id: str, version_id: str
) -> parametermanager_v1.ParameterVersion:
    """
    Retrieves the details of a specific version of an
    existing parameter in the specified region of the specified
    project using the Google Cloud Parameter Manager SDK.

    Args:
        project_id (str): The ID of the project where the parameter is located.
        location_id (str): The ID of the region where the parameter is located.
        parameter_id (str): The ID of the parameter for
        which version details are to be retrieved.
        version_id (str): The ID of the version to be retrieved.

    Returns:
        parametermanager_v1.ParameterVersion: An object
        representing the parameter version.

    Example:
        get_regional_param_version(
            "my-project",
            "us-central1",
            "my-regional-parameter",
            "v1"
        )
    """
    # Import the necessary library for Google Cloud Parameter Manager.
    from google.cloud import parametermanager_v1

    # Create the Parameter Manager client with the regional endpoint.
    api_endpoint = f"parametermanager.{location_id}.rep.googleapis.com"
    client = parametermanager_v1.ParameterManagerClient(
        client_options={"api_endpoint": api_endpoint}
    )

    # Build the resource name of the parameter version.
    name = client.parameter_version_path(
        project_id, location_id, parameter_id, version_id
    )

    # Define the request to get the parameter version details.
    request = parametermanager_v1.GetParameterVersionRequest(name=name)

    # Get the parameter version details.
    response = client.get_parameter_version(request=request)

    # Show parameter version details.
    # Find more details for the Parameter Version object here:
    # https://cloud.google.com/secret-manager/parameter-manager/docs/reference/rest/v1/projects.locations.parameters.versions#ParameterVersion
    print(f"Found regional parameter version {response.name} with state {'disabled' if response.disabled else 'enabled'}")
    if not response.disabled:
        print(f"Payload: {response.payload.data.decode('utf-8')}")

Ruby

To run this code, first set up a Ruby development environment and install the Secret Manager Ruby SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.

require "google/cloud/parameter_manager"

##
# Retrieve a regional parameter version
#
# @param project_id [String] The Google Cloud project (e.g. "my-project")
# @param location_id [String] The location name (e.g. "us-central1")
# @param parameter_id [String] The parameter name (e.g. "my-parameter")
# @param version_id [String] The version name (e.g. "my-version")
#
def get_regional_param_version project_id:, location_id:, parameter_id:, version_id:
  # Endpoint for the regional parameter manager service.
  api_endpoint = "parametermanager.#{location_id}.rep.googleapis.com"

  # Create the Parameter Manager client.
  client = Google::Cloud::ParameterManager.parameter_manager do |config|
    config.endpoint = api_endpoint
  end

  # Build the resource name of the parent project.
  name = client.parameter_version_path project: project_id, location: location_id, parameter: parameter_id,
                                       parameter_version: version_id

  # Retrieve the parameter version.
  param_version = client.get_parameter_version name: name

  # Print the retrieved parameter version name.
  state = param_version.disabled ? "disabled" : "enabled"
  puts "Found regional parameter version #{param_version.name} with state #{state}"

  # Use a guard clause to return early if the parameter version is disabled.
  return if param_version.disabled

  puts "Payload: #{param_version.payload.data}"
end

Additional information about the REST command

Use view=FULL in your request to the Parameter Manager API when you want the service to return the metadata of the parameter version and the actual value that is stored in the version. To view just the version metadata such as the name, createTime, and updateTime, you can use view=BASIC in your request. See the following example:

REST

Before using any of the request data, make the following replacements:

  • LOCATION: the Google Cloud location of the parameter
  • PROJECT_ID: the Google Cloud project ID
  • PARAMETER_ID: the name of the parameter
  • PARAMETER_VERSION_ID: the ID of the parameter version

HTTP method and URL:

GET https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID?view=BASIC

Request JSON body:

{}

To send your request, choose one of these options:

curl

Save the request body in a file named request.json, and execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID?view=BASIC"

PowerShell

Save the request body in a file named request.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters/PARAMETER_ID/versions/PARAMETER_VERSION_ID?view=BASIC" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "name": "projects/production-1/locations/us-central1/parameters/app_config/versions/configv2",
  "createTime": "2024-10-30T05:38:58.682341106Z",
  "updateTime": "2024-10-30T05:38:58.919983684Z"
}

What's next