# Google Cloud Capacity Planner V1beta Client - Class UsageServiceClient (0.1.2)

0.1.2 (latest) 0.1.1

> [!WARNING]
> **Beta**
>
>
> This library is covered by the [Pre-GA Offerings Terms](https://docs.cloud.google.com/terms/service-terms#1)
> of the Terms of Service. Pre-GA libraries might have limited support,
> and changes to pre-GA libraries might not be compatible with other pre-GA versions.
> For more information, see the
> [launch stage descriptions](https://docs.cloud.google.com/products#product-launch-stages).

Reference documentation and code samples for the Google Cloud Capacity Planner V1beta Client class UsageServiceClient.

Service Description: Provides access to historical and forecasted usage data.

This class provides the ability to make remote calls to the backing service through method
calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To
assist with these names, this class includes a format method for each type of
name, and additionally a parseName method to extract the individual identifiers
contained within formatted names that are returned by the API.

## Namespace

Google \\ Cloud \\ CapacityPlanner \\ V1beta \\ Client

## Methods

### __construct

Constructor.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array|https://docs.cloud.google.com/php/docs/reference/gax/latest/Options.ClientOptions.html` Optional. Options for configuring the service API wrapper. |
| `↳ apiEndpoint` | `string` The address of the API remote host. May optionally include the port, formatted as " |
| `↳ credentials` | `https://docs.cloud.google.com/php/docs/reference/auth/latest/FetchAuthTokenInterface.html|https://docs.cloud.google.com/php/docs/reference/gax/latest/CredentialsWrapper.html` This option should only be used with a pre-constructed [Google\\Auth\\FetchAuthTokenInterface](https://docs.cloud.google.com/php/docs/reference/auth/latest/FetchAuthTokenInterface.html) or [Google\\ApiCore\\CredentialsWrapper](https://docs.cloud.google.com/php/docs/reference/gax/latest/CredentialsWrapper.html) object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. **Important** : If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly `use Google\Auth\Credentials\ServiceAccountCredentials; use Google\Cloud\CapacityPlanner\V1beta\UsageServiceClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new UsageServiceClient(['credentials' => $creds]);` <https://cloud.google.com/docs/authentication/external/externally-sourced-credentials> |
| `↳ credentialsConfig` | `array` Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see [Google\\ApiCore\\CredentialsWrapper::build()](https://docs.cloud.google.com/php/docs/reference/gax/latest/CredentialsWrapper.html#_Google_ApiCore_CredentialsWrapper__build__) . |
| `↳ disableRetries` | `bool` Determines whether or not retries defined by the client configuration should be disabled. Defaults to `false`. |
| `↳ clientConfig` | `string|array` Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
| `↳ transport` | `string|https://docs.cloud.google.com/php/docs/reference/gax/latest/Transport.TransportInterface.html` The transport used for executing network requests. May be either the string `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. *Advanced usage* : Additionally, it is possible to pass in an already instantiated [Google\\ApiCore\\Transport\\TransportInterface](https://docs.cloud.google.com/php/docs/reference/gax/latest/Transport.TransportInterface.html) object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored. |
| `↳ transportConfig` | `array` Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = \[ 'grpc' =\> \[...\], 'rest' =\> \[...\], \]; See the [Google\\ApiCore\\Transport\\GrpcTransport::build()](https://docs.cloud.google.com/php/docs/reference/gax/latest/Transport.GrpcTransport.html#_Google_ApiCore_Transport_GrpcTransport__build__) and [Google\\ApiCore\\Transport\\RestTransport::build()](https://docs.cloud.google.com/php/docs/reference/gax/latest/Transport.RestTransport.html#_Google_ApiCore_Transport_RestTransport__build__) methods for the supported options. |
| `↳ clientCertSource` | `callable` A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
| `↳ logger` | `false|Psr\Log\LoggerInterface` A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag |
| `↳ universeDomain` | `string` The service domain for the client. Defaults to 'googleapis.com'. |

### exportForecasts

Exports forecasted usage data requested by user into either an existing
Cloud Storage bucket or a BigQuery table.

The async variant is [UsageServiceClient::exportForecastsAsync()](https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.Client.UsageServiceClient#_Google_Cloud_CapacityPlanner_V1beta_Client_UsageServiceClient__exportForecastsAsync__) .

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportForecastsRequest` A request to house fields associated with the call. |
| `callOptions` | `array` Optional. |
| `↳ retrySettings` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html|array` Retry settings to use for this call. Can be a [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) object, or an associative array of retry settings parameters. See the documentation on [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) for example usage. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/gax/latest/OperationResponse.html<https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportForecastsResponse>` |   |

**Example**

    use Google\ApiCore\ApiException;
    use Google\ApiCore\OperationResponse;
    use Google\Cloud\CapacityPlanner\V1beta\Client\UsageServiceClient;
    use Google\Cloud\CapacityPlanner\V1beta\ExportForecastsRequest;
    use Google\Cloud\CapacityPlanner\V1beta\ExportForecastsResponse;
    use Google\Cloud\CapacityPlanner\V1beta\OutputConfig;
    use Google\Rpc\Status;

    /**
     * @param string $formattedParent The compute engine resource and location for the time series
     *                                values to return. The format is:
     *                                projects/{project}/locations/{location} or
     *                                organizations/{organization}/locations/{location} or
     *                                folders/{folder}/locations/{location}
     *                                Please see {@see UsageServiceClient::locationName()} for help formatting this field.
     * @param string $resourceType    The resource for the `Forecast` values to return. Possible values
     *                                include "gce-vcpus", "gce-ram", "gce-local-ssd", "gce-persistent-disk",
     *                                "gce-gpu" and "gce-tpu".
     */
    function export_forecasts_sample(string $formattedParent, string $resourceType): void
    {
        // Create a client.
        $usageServiceClient = new UsageServiceClient();

        // Prepare the request message.
        $outputConfig = new OutputConfig();
        $request = (new ExportForecastsRequest())
            ->setParent($formattedParent)
            ->setResourceType($resourceType)
            ->setOutputConfig($outputConfig);

        // Call the API and handle any network failures.
        try {
            /** @var OperationResponse $response */
            $response = $usageServiceClient->exportForecasts($request);
            $response->pollUntilComplete();

            if ($response->operationSucceeded()) {
                /** @var ExportForecastsResponse $result */
                $result = $response->getResult();
                printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
            } else {
                /** @var Status $error */
                $error = $response->getError();
                printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
            }
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }

    /**
     * Helper to execute the sample.
     *
     * This sample has been automatically generated and should be regarded as a code
     * template only. It will require modifications to work:
     *  - It may require correct/in-range values for request initialization.
     *  - It may require specifying regional endpoints when creating the service client,
     *    please see the apiEndpoint client configuration option for more details.
     */
    function callSample(): void
    {
        $formattedParent = UsageServiceClient::locationName('[PROJECT]', '[LOCATION]');
        $resourceType = '[RESOURCE_TYPE]';

        export_forecasts_sample($formattedParent, $resourceType);
    }

### exportReservationsUsage

Exports reservations usage data requested by user into either an existing
Cloud Storage bucket or a new/existing BigQuery table.

The async variant is [UsageServiceClient::exportReservationsUsageAsync()](https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.Client.UsageServiceClient#_Google_Cloud_CapacityPlanner_V1beta_Client_UsageServiceClient__exportReservationsUsageAsync__) .

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportReservationsUsageRequest` A request to house fields associated with the call. |
| `callOptions` | `array` Optional. |
| `↳ retrySettings` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html|array` Retry settings to use for this call. Can be a [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) object, or an associative array of retry settings parameters. See the documentation on [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) for example usage. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/gax/latest/OperationResponse.html<https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportReservationsUsageResponse>` |   |

**Example**

    use Google\ApiCore\ApiException;
    use Google\ApiCore\OperationResponse;
    use Google\Cloud\CapacityPlanner\V1beta\Client\UsageServiceClient;
    use Google\Cloud\CapacityPlanner\V1beta\ExportReservationsUsageRequest;
    use Google\Cloud\CapacityPlanner\V1beta\ExportReservationsUsageResponse;
    use Google\Cloud\CapacityPlanner\V1beta\OutputConfig;
    use Google\Cloud\CapacityPlanner\V1beta\UsageHistory\AggregationMethod;
    use Google\Rpc\Status;

    /**
     * @param string $formattedParent        The compute engine resource and location of the
     *                                       reservationsusage. The format is:
     *                                       projects/{project}/locations/{location} or
     *                                       organizations/{organization}/locations/{location} or
     *                                       folders/{folder}/locations/{location}
     *                                       Please see {@see UsageServiceClient::locationName()} for help formatting this field.
     * @param string $cloudResourceType      The resource for the `ReservationsUsage` values to return.
     *                                       Possible values include "gce-vcpus", "gce-ram", "gce-local-ssd", and
     *                                       "gce-gpu".
     * @param int    $usageAggregationMethod The method that should be used to convert sampled reservations
     *                                       data to daily usage values.
     */
    function export_reservations_usage_sample(
        string $formattedParent,
        string $cloudResourceType,
        int $usageAggregationMethod
    ): void {
        // Create a client.
        $usageServiceClient = new UsageServiceClient();

        // Prepare the request message.
        $outputConfig = new OutputConfig();
        $request = (new ExportReservationsUsageRequest())
            ->setParent($formattedParent)
            ->setCloudResourceType($cloudResourceType)
            ->setUsageAggregationMethod($usageAggregationMethod)
            ->setOutputConfig($outputConfig);

        // Call the API and handle any network failures.
        try {
            /** @var OperationResponse $response */
            $response = $usageServiceClient->exportReservationsUsage($request);
            $response->pollUntilComplete();

            if ($response->operationSucceeded()) {
                /** @var ExportReservationsUsageResponse $result */
                $result = $response->getResult();
                printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
            } else {
                /** @var Status $error */
                $error = $response->getError();
                printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
            }
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }

    /**
     * Helper to execute the sample.
     *
     * This sample has been automatically generated and should be regarded as a code
     * template only. It will require modifications to work:
     *  - It may require correct/in-range values for request initialization.
     *  - It may require specifying regional endpoints when creating the service client,
     *    please see the apiEndpoint client configuration option for more details.
     */
    function callSample(): void
    {
        $formattedParent = UsageServiceClient::locationName('[PROJECT]', '[LOCATION]');
        $cloudResourceType = '[CLOUD_RESOURCE_TYPE]';
        $usageAggregationMethod = AggregationMethod::AGGREGATION_METHOD_UNSPECIFIED;

        export_reservations_usage_sample($formattedParent, $cloudResourceType, $usageAggregationMethod);
    }

### exportUsageHistories

Exports historical usage data requested by user into either an existing
Cloud Storage bucket or a BigQuery table.

The async variant is [UsageServiceClient::exportUsageHistoriesAsync()](https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.Client.UsageServiceClient#_Google_Cloud_CapacityPlanner_V1beta_Client_UsageServiceClient__exportUsageHistoriesAsync__) .

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportUsageHistoriesRequest` A request to house fields associated with the call. |
| `callOptions` | `array` Optional. |
| `↳ retrySettings` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html|array` Retry settings to use for this call. Can be a [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) object, or an associative array of retry settings parameters. See the documentation on [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) for example usage. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/gax/latest/OperationResponse.html<https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportUsageHistoriesResponse>` |   |

**Example**

    use Google\ApiCore\ApiException;
    use Google\ApiCore\OperationResponse;
    use Google\Cloud\CapacityPlanner\V1beta\Client\UsageServiceClient;
    use Google\Cloud\CapacityPlanner\V1beta\ExportUsageHistoriesRequest;
    use Google\Cloud\CapacityPlanner\V1beta\ExportUsageHistoriesResponse;
    use Google\Cloud\CapacityPlanner\V1beta\OutputConfig;
    use Google\Rpc\Status;

    /**
     * @param string $formattedParent The compute engine resource and location for the time series
     *                                values to return. The format is:
     *                                projects/{project}/locations/{location} or
     *                                organizations/{organization}/locations/{location} or
     *                                folders/{folder}/locations/{location}
     *                                Please see {@see UsageServiceClient::locationName()} for help formatting this field.
     * @param string $resourceType    The resource for the `UsageHistory` values to return. Possible
     *                                values include "gce-vcpus", "gce-ram", "gce-local-ssd",
     *                                "gce-persistent-disk", "gce-gpu" and "gce-tpu".
     */
    function export_usage_histories_sample(string $formattedParent, string $resourceType): void
    {
        // Create a client.
        $usageServiceClient = new UsageServiceClient();

        // Prepare the request message.
        $outputConfig = new OutputConfig();
        $request = (new ExportUsageHistoriesRequest())
            ->setParent($formattedParent)
            ->setResourceType($resourceType)
            ->setOutputConfig($outputConfig);

        // Call the API and handle any network failures.
        try {
            /** @var OperationResponse $response */
            $response = $usageServiceClient->exportUsageHistories($request);
            $response->pollUntilComplete();

            if ($response->operationSucceeded()) {
                /** @var ExportUsageHistoriesResponse $result */
                $result = $response->getResult();
                printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
            } else {
                /** @var Status $error */
                $error = $response->getError();
                printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
            }
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }

    /**
     * Helper to execute the sample.
     *
     * This sample has been automatically generated and should be regarded as a code
     * template only. It will require modifications to work:
     *  - It may require correct/in-range values for request initialization.
     *  - It may require specifying regional endpoints when creating the service client,
     *    please see the apiEndpoint client configuration option for more details.
     */
    function callSample(): void
    {
        $formattedParent = UsageServiceClient::locationName('[PROJECT]', '[LOCATION]');
        $resourceType = '[RESOURCE_TYPE]';

        export_usage_histories_sample($formattedParent, $resourceType);
    }

### queryForecasts

Returns a list of the forecasts that are in the parent parameter
and match your specified filters.

The async variant is [UsageServiceClient::queryForecastsAsync()](https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.Client.UsageServiceClient#_Google_Cloud_CapacityPlanner_V1beta_Client_UsageServiceClient__queryForecastsAsync__) .

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryForecastsRequest` A request to house fields associated with the call. |
| `callOptions` | `array` Optional. |
| `↳ retrySettings` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html|array` Retry settings to use for this call. Can be a [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) object, or an associative array of retry settings parameters. See the documentation on [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) for example usage. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryForecastsResponse` |   |

**Example**

    use Google\ApiCore\ApiException;
    use Google\Cloud\CapacityPlanner\V1beta\Client\UsageServiceClient;
    use Google\Cloud\CapacityPlanner\V1beta\QueryForecastsRequest;
    use Google\Cloud\CapacityPlanner\V1beta\QueryForecastsResponse;

    /**
     * @param string $formattedParent   The compute engine resource and location for the time series
     *                                  values to return. The format is:
     *
     *                                  projects/{project}/locations/{location} or
     *                                  organizations/{organization}/locations/{location} or
     *                                  folders/{folder}/locations/{location}
     *                                  Please see {@see UsageServiceClient::locationName()} for help formatting this field.
     * @param string $cloudResourceType The resource for the `Forecast` values to return. Possible values
     *                                  include "gce-vcpus", "gce-ram", "gce-local-ssd", "gce-persistent-disk",
     *                                  "gce-gpu" and "gce-tpu". Empty cloud_resource_type will return results
     *                                  matching all resources.
     */
    function query_forecasts_sample(string $formattedParent, string $cloudResourceType): void
    {
        // Create a client.
        $usageServiceClient = new UsageServiceClient();

        // Prepare the request message.
        $request = (new QueryForecastsRequest())
            ->setParent($formattedParent)
            ->setCloudResourceType($cloudResourceType);

        // Call the API and handle any network failures.
        try {
            /** @var QueryForecastsResponse $response */
            $response = $usageServiceClient->queryForecasts($request);
            printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }

    /**
     * Helper to execute the sample.
     *
     * This sample has been automatically generated and should be regarded as a code
     * template only. It will require modifications to work:
     *  - It may require correct/in-range values for request initialization.
     *  - It may require specifying regional endpoints when creating the service client,
     *    please see the apiEndpoint client configuration option for more details.
     */
    function callSample(): void
    {
        $formattedParent = UsageServiceClient::locationName('[PROJECT]', '[LOCATION]');
        $cloudResourceType = '[CLOUD_RESOURCE_TYPE]';

        query_forecasts_sample($formattedParent, $cloudResourceType);
    }

### queryReservations

Returns a list of the reservations that are in the parent parameter
and match your specified filters.

The async variant is [UsageServiceClient::queryReservationsAsync()](https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.Client.UsageServiceClient#_Google_Cloud_CapacityPlanner_V1beta_Client_UsageServiceClient__queryReservationsAsync__) .

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryReservationsRequest` A request to house fields associated with the call. |
| `callOptions` | `array` Optional. |
| `↳ retrySettings` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html|array` Retry settings to use for this call. Can be a [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) object, or an associative array of retry settings parameters. See the documentation on [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) for example usage. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryReservationsResponse` |   |

**Example**

    use Google\ApiCore\ApiException;
    use Google\Cloud\CapacityPlanner\V1beta\Client\UsageServiceClient;
    use Google\Cloud\CapacityPlanner\V1beta\QueryReservationsRequest;
    use Google\Cloud\CapacityPlanner\V1beta\QueryReservationsRequest\ReservationDataLevel;
    use Google\Cloud\CapacityPlanner\V1beta\QueryReservationsRequest\ReservationType;
    use Google\Cloud\CapacityPlanner\V1beta\QueryReservationsResponse;

    /**
     * @param string $formattedParent      The compute engine resource and location for the time series
     *                                     values to return. The format is:
     *
     *                                     projects/{project}/locations/{location} or
     *                                     organizations/{organization}/locations/{location} or
     *                                     folders/{folder}/locations/{location}
     *                                     Please see {@see UsageServiceClient::locationName()} for help formatting this field.
     * @param string $cloudResourceType    The resource for the reserved values to return. Possible values
     *                                     include "gce-vcpus", "gce-ram", "gce-local-ssd", "gce-gpu" and "gce-vm".
     * @param int    $reservationType      The Reservation type for example, future reservation request and
     *                                     allocation. If unspecified, all types are
     *                                     included.
     * @param int    $reservationDataLevel Reservations output data format.
     */
    function query_reservations_sample(
        string $formattedParent,
        string $cloudResourceType,
        int $reservationType,
        int $reservationDataLevel
    ): void {
        // Create a client.
        $usageServiceClient = new UsageServiceClient();

        // Prepare the request message.
        $request = (new QueryReservationsRequest())
            ->setParent($formattedParent)
            ->setCloudResourceType($cloudResourceType)
            ->setReservationType($reservationType)
            ->setReservationDataLevel($reservationDataLevel);

        // Call the API and handle any network failures.
        try {
            /** @var QueryReservationsResponse $response */
            $response = $usageServiceClient->queryReservations($request);
            printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }

    /**
     * Helper to execute the sample.
     *
     * This sample has been automatically generated and should be regarded as a code
     * template only. It will require modifications to work:
     *  - It may require correct/in-range values for request initialization.
     *  - It may require specifying regional endpoints when creating the service client,
     *    please see the apiEndpoint client configuration option for more details.
     */
    function callSample(): void
    {
        $formattedParent = UsageServiceClient::locationName('[PROJECT]', '[LOCATION]');
        $cloudResourceType = '[CLOUD_RESOURCE_TYPE]';
        $reservationType = ReservationType::RESERVATION_TYPE_UNSPECIFIED;
        $reservationDataLevel = ReservationDataLevel::RESERVATION_DATA_LEVEL_UNSPECIFIED;

        query_reservations_sample(
            $formattedParent,
            $cloudResourceType,
            $reservationType,
            $reservationDataLevel
        );
    }

### queryUsageHistories

Returns a list of the usage histories that are in the parent parameter
and match your specified filters.

The async variant is [UsageServiceClient::queryUsageHistoriesAsync()](https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.Client.UsageServiceClient#_Google_Cloud_CapacityPlanner_V1beta_Client_UsageServiceClient__queryUsageHistoriesAsync__) .

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryUsageHistoriesRequest` A request to house fields associated with the call. |
| `callOptions` | `array` Optional. |
| `↳ retrySettings` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html|array` Retry settings to use for this call. Can be a [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) object, or an associative array of retry settings parameters. See the documentation on [Google\\ApiCore\\RetrySettings](https://docs.cloud.google.com/php/docs/reference/gax/latest/RetrySettings.html) for example usage. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryUsageHistoriesResponse` |   |

**Example**

    use Google\ApiCore\ApiException;
    use Google\Cloud\CapacityPlanner\V1beta\Client\UsageServiceClient;
    use Google\Cloud\CapacityPlanner\V1beta\QueryUsageHistoriesRequest;
    use Google\Cloud\CapacityPlanner\V1beta\QueryUsageHistoriesResponse;

    /**
     * @param string $formattedParent   The compute engine resource and location for the time series
     *                                  values to return. The format is:
     *
     *                                  projects/{project}/locations/{location} or
     *                                  organizations/{organization}/locations/{location} or
     *                                  folders/{folder}/locations/{location}
     *                                  Please see {@see UsageServiceClient::locationName()} for help formatting this field.
     * @param string $cloudResourceType The resource for the `UsageHistory` values to return. Possible
     *                                  values include "gce-vcpus", "gce-ram", "gce-local-ssd",
     *                                  "gce-persistent-disk", "gce-gpu" and "gce-tpu". Empty cloud_resource_type
     *                                  will return results matching all resources.
     */
    function query_usage_histories_sample(string $formattedParent, string $cloudResourceType): void
    {
        // Create a client.
        $usageServiceClient = new UsageServiceClient();

        // Prepare the request message.
        $request = (new QueryUsageHistoriesRequest())
            ->setParent($formattedParent)
            ->setCloudResourceType($cloudResourceType);

        // Call the API and handle any network failures.
        try {
            /** @var QueryUsageHistoriesResponse $response */
            $response = $usageServiceClient->queryUsageHistories($request);
            printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }

    /**
     * Helper to execute the sample.
     *
     * This sample has been automatically generated and should be regarded as a code
     * template only. It will require modifications to work:
     *  - It may require correct/in-range values for request initialization.
     *  - It may require specifying regional endpoints when creating the service client,
     *    please see the apiEndpoint client configuration option for more details.
     */
    function callSample(): void
    {
        $formattedParent = UsageServiceClient::locationName('[PROJECT]', '[LOCATION]');
        $cloudResourceType = '[CLOUD_RESOURCE_TYPE]';

        query_usage_histories_sample($formattedParent, $cloudResourceType);
    }

### exportForecastsAsync

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportForecastsRequest` |
| `optionalArgs` | `array` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Promise.Promise.html<https://docs.cloud.google.com/php/docs/reference/gax/latest/OperationResponse.html>` |   |

### exportReservationsUsageAsync

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportReservationsUsageRequest` |
| `optionalArgs` | `array` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Promise.Promise.html<https://docs.cloud.google.com/php/docs/reference/gax/latest/OperationResponse.html>` |   |

### exportUsageHistoriesAsync

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.ExportUsageHistoriesRequest` |
| `optionalArgs` | `array` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Promise.Promise.html<https://docs.cloud.google.com/php/docs/reference/gax/latest/OperationResponse.html>` |   |

### queryForecastsAsync

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryForecastsRequest` |
| `optionalArgs` | `array` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Promise.Promise.html<https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryForecastsResponse>` |   |

### queryReservationsAsync

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryReservationsRequest` |
| `optionalArgs` | `array` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Promise.Promise.html<https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryReservationsResponse>` |   |

### queryUsageHistoriesAsync

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryUsageHistoriesRequest` |
| `optionalArgs` | `array` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Promise.Promise.html<https://docs.cloud.google.com/php/docs/reference/cloud-capacityplanner/latest/V1beta.QueryUsageHistoriesResponse>` |   |

### getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Google\LongRunning\Client\OperationsClient` |   |

### resumeOperation

Resume an existing long running operation that was previously started by a long
running API method. If $methodName is not provided, or does not match a long
running API method, then the operation can still be resumed, but the
OperationResponse object will not deserialize the final response.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `operationName` | `string` The name of the long running operation |
| `methodName` | `string` The name of the method used to start the operation |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/gax/latest/OperationResponse.html` |   |

### static::locationName

Formats a string containing the fully-qualified path to represent a location
resource.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `project` | `string` |
| `location` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` | The formatted location resource. |

### static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported:
Template: Pattern

- location: projects/{project}/locations/{location}

The optional $template argument can be supplied to specify a particular pattern,
and must match one of the templates listed above. If no $template argument is
provided, or if the $template argument does not match one of the templates
listed, then parseName will check each of the supported templates, and return
the first match.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `formattedName` | `string` The formatted name string |
| `template` | `?string` Optional name of template to match |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` | An associative array from name component IDs to component values. |