Google Cloud Retail V2 Client - Class ProductServiceClient (1.4.2)

Reference documentation and code samples for the Google Cloud Retail V2 Client class ProductServiceClient.

Service Description: Service for ingesting Product information of the customer's website.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

$productServiceClient = new ProductServiceClient();
try {
    $formattedProduct = $productServiceClient->productName('[PROJECT]', '[LOCATION]', '[CATALOG]', '[BRANCH]', '[PRODUCT]');
    $type = 'type';
    $placeIds = [];
    $operationResponse = $productServiceClient->addFulfillmentPlaces($formattedProduct, $type, $placeIds);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $productServiceClient->addFulfillmentPlaces($formattedProduct, $type, $placeIds);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $productServiceClient->resumeOperation($operationName, 'addFulfillmentPlaces');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
    // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $productServiceClient->close();
}

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.

This service has a new (beta) implementation. See Google\Cloud\Retail\V2\Client\ProductServiceClient to use the new surface.

Namespace

Google \ Cloud \ Retail \ V2

Methods

__construct

Constructor.

Parameters
NameDescription
options array

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 string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ 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() .

↳ 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|TransportInterface

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 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() and 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.

addFulfillmentPlaces

It is recommended to use the ProductService.AddLocalInventories method instead of ProductService.AddFulfillmentPlaces.

ProductService.AddLocalInventories achieves the same results but provides more fine-grained control over ingesting local inventory data.

Incrementally adds place IDs to Product.fulfillment_info.place_ids.

This process is asynchronous and does not require the Product to exist before updating fulfillment information. If the request is valid, the update will be enqueued and processed downstream. As a consequence, when a response is returned, the added place IDs are not immediately manifested in the Product queried by ProductService.GetProduct or ProductService.ListProducts.

The returned Operations will be obsolete after 1 day, and GetOperation API will return NOT_FOUND afterwards.

If conflicting updates are issued, the Operations associated with the stale updates will not be marked as done until being obsolete.

Parameters
NameDescription
product string

Required. Full resource name of Product, such as projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id.

If the caller does not have permission to access the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

type string

Required. The fulfillment type, including commonly used types (such as pickup in store and same day delivery), and custom types.

Supported values:

  • "pickup-in-store"
  • "ship-to-store"
  • "same-day-delivery"
  • "next-day-delivery"
  • "custom-type-1"
  • "custom-type-2"
  • "custom-type-3"
  • "custom-type-4"
  • "custom-type-5"

If this field is set to an invalid value other than these, an INVALID_ARGUMENT error is returned.

This field directly corresponds to Product.fulfillment_info.type.

placeIds string[]

Required. The IDs for this type, such as the store IDs for "pickup-in-store" or the region IDs for "same-day-delivery" to be added for this type. Duplicate IDs will be automatically ignored.

At least 1 value is required, and a maximum of 2000 values are allowed. Each value must be a string with a length limit of 10 characters, matching the pattern [a-zA-Z0-9_-]+, such as "store1" or "REGION-2". Otherwise, an INVALID_ARGUMENT error is returned.

If the total number of place IDs exceeds 2000 for this type after adding, then the update will be rejected.

optionalArgs array

Optional.

↳ addTime Timestamp

The time when the fulfillment updates are issued, used to prevent out-of-order updates on fulfillment information. If not provided, the internal system time will be used.

↳ allowMissing bool

If set to true, and the Product is not found, the fulfillment information will still be processed and retained for at most 1 day and processed once the Product is created. If set to false, a NOT_FOUND error is returned if the Product is not found.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Retail\V2\AddFulfillmentPlacesResponse;
use Google\Cloud\Retail\V2\ProductServiceClient;
use Google\Rpc\Status;

/**
 * @param string $formattedProduct Full resource name of [Product][google.cloud.retail.v2.Product],
 *                                 such as
 *                                 `projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id`.
 *
 *                                 If the caller does not have permission to access the
 *                                 [Product][google.cloud.retail.v2.Product], regardless of whether or not it
 *                                 exists, a PERMISSION_DENIED error is returned. Please see
 *                                 {@see ProductServiceClient::productName()} for help formatting this field.
 * @param string $type             The fulfillment type, including commonly used types (such as
 *                                 pickup in store and same day delivery), and custom types.
 *
 *                                 Supported values:
 *
 *                                 * "pickup-in-store"
 *                                 * "ship-to-store"
 *                                 * "same-day-delivery"
 *                                 * "next-day-delivery"
 *                                 * "custom-type-1"
 *                                 * "custom-type-2"
 *                                 * "custom-type-3"
 *                                 * "custom-type-4"
 *                                 * "custom-type-5"
 *
 *                                 If this field is set to an invalid value other than these, an
 *                                 INVALID_ARGUMENT error is returned.
 *
 *                                 This field directly corresponds to
 *                                 [Product.fulfillment_info.type][google.cloud.retail.v2.FulfillmentInfo.type].
 * @param string $placeIdsElement  The IDs for this
 *                                 [type][google.cloud.retail.v2.AddFulfillmentPlacesRequest.type], such as
 *                                 the store IDs for "pickup-in-store" or the region IDs for
 *                                 "same-day-delivery" to be added for this
 *                                 [type][google.cloud.retail.v2.AddFulfillmentPlacesRequest.type]. Duplicate
 *                                 IDs will be automatically ignored.
 *
 *                                 At least 1 value is required, and a maximum of 2000 values are allowed.
 *                                 Each value must be a string with a length limit of 10 characters, matching
 *                                 the pattern `[a-zA-Z0-9_-]+`, such as "store1" or "REGION-2". Otherwise, an
 *                                 INVALID_ARGUMENT error is returned.
 *
 *                                 If the total number of place IDs exceeds 2000 for this
 *                                 [type][google.cloud.retail.v2.AddFulfillmentPlacesRequest.type] after
 *                                 adding, then the update will be rejected.
 */
function add_fulfillment_places_sample(
    string $formattedProduct,
    string $type,
    string $placeIdsElement
): void {
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $placeIds = [$placeIdsElement,];

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $productServiceClient->addFulfillmentPlaces($formattedProduct, $type, $placeIds);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var AddFulfillmentPlacesResponse $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
{
    $formattedProduct = ProductServiceClient::productName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]',
        '[PRODUCT]'
    );
    $type = '[TYPE]';
    $placeIdsElement = '[PLACE_IDS]';

    add_fulfillment_places_sample($formattedProduct, $type, $placeIdsElement);
}

addLocalInventories

Updates local inventory information for a Product at a list of places, while respecting the last update timestamps of each inventory field.

This process is asynchronous and does not require the Product to exist before updating inventory information. If the request is valid, the update will be enqueued and processed downstream. As a consequence, when a response is returned, updates are not immediately manifested in the Product queried by ProductService.GetProduct or ProductService.ListProducts.

Local inventory information can only be modified using this method. ProductService.CreateProduct and ProductService.UpdateProduct has no effect on local inventories.

The returned Operations will be obsolete after 1 day, and GetOperation API will return NOT_FOUND afterwards.

If conflicting updates are issued, the Operations associated with the stale updates will not be marked as done until being obsolete.

Parameters
NameDescription
product string

Required. Full resource name of Product, such as projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id.

If the caller does not have permission to access the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

localInventories array<Google\Cloud\Retail\V2\LocalInventory>

Required. A list of inventory information at difference places. Each place is identified by its place ID. At most 3000 inventories are allowed per request.

optionalArgs array

Optional.

↳ addMask FieldMask

Indicates which inventory fields in the provided list of LocalInventory to update. The field is updated to the provided value. If a field is set while the place does not have a previous local inventory, the local inventory at that store is created. If a field is set while the value of that field is not provided, the original field value, if it exists, is deleted. If the mask is not set or set with empty paths, all inventory fields will be updated. If an unsupported or unknown field is provided, an INVALID_ARGUMENT error is returned and the entire update will be ignored.

↳ addTime Timestamp

The time when the inventory updates are issued. Used to prevent out-of-order updates on local inventory fields. If not provided, the internal system time will be used.

↳ allowMissing bool

If set to true, and the Product is not found, the local inventory will still be processed and retained for at most 1 day and processed once the Product is created. If set to false, a NOT_FOUND error is returned if the Product is not found.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Retail\V2\AddLocalInventoriesResponse;
use Google\Cloud\Retail\V2\LocalInventory;
use Google\Cloud\Retail\V2\ProductServiceClient;
use Google\Rpc\Status;

/**
 * @param string $formattedProduct Full resource name of [Product][google.cloud.retail.v2.Product],
 *                                 such as
 *                                 `projects/&#42;/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id`.
 *
 *                                 If the caller does not have permission to access the
 *                                 [Product][google.cloud.retail.v2.Product], regardless of whether or not it
 *                                 exists, a PERMISSION_DENIED error is returned. Please see
 *                                 {@see ProductServiceClient::productName()} for help formatting this field.
 */
function add_local_inventories_sample(string $formattedProduct): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $localInventories = [new LocalInventory()];

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $productServiceClient->addLocalInventories($formattedProduct, $localInventories);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var AddLocalInventoriesResponse $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
{
    $formattedProduct = ProductServiceClient::productName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]',
        '[PRODUCT]'
    );

    add_local_inventories_sample($formattedProduct);
}

createProduct

Creates a Product.

Parameters
NameDescription
parent string

Required. The parent catalog resource name, such as projects/*/locations/global/catalogs/default_catalog/branches/default_branch.

product Google\Cloud\Retail\V2\Product

Required. The Product to create.

productId string

Required. The ID to use for the Product, which will become the final component of the Product.name.

If the caller does not have permission to create the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

This field must be unique among all Products with the same parent. Otherwise, an ALREADY_EXISTS error is returned.

This field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Retail\V2\Product
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Retail\V2\Product;
use Google\Cloud\Retail\V2\ProductServiceClient;

/**
 * @param string $formattedParent The parent catalog resource name, such as
 *                                `projects/&#42;/locations/global/catalogs/default_catalog/branches/default_branch`. Please see
 *                                {@see ProductServiceClient::branchName()} for help formatting this field.
 * @param string $productTitle    Product title.
 *
 *                                This field must be a UTF-8 encoded string with a length limit of 1,000
 *                                characters. Otherwise, an INVALID_ARGUMENT error is returned.
 *
 *                                Corresponding properties: Google Merchant Center property
 *                                [title](https://support.google.com/merchants/answer/6324415). Schema.org
 *                                property [Product.name](https://schema.org/name).
 * @param string $productId       The ID to use for the [Product][google.cloud.retail.v2.Product],
 *                                which will become the final component of the
 *                                [Product.name][google.cloud.retail.v2.Product.name].
 *
 *                                If the caller does not have permission to create the
 *                                [Product][google.cloud.retail.v2.Product], regardless of whether or not it
 *                                exists, a PERMISSION_DENIED error is returned.
 *
 *                                This field must be unique among all
 *                                [Product][google.cloud.retail.v2.Product]s with the same
 *                                [parent][google.cloud.retail.v2.CreateProductRequest.parent]. Otherwise, an
 *                                ALREADY_EXISTS error is returned.
 *
 *                                This field must be a UTF-8 encoded string with a length limit of 128
 *                                characters. Otherwise, an INVALID_ARGUMENT error is returned.
 */
function create_product_sample(
    string $formattedParent,
    string $productTitle,
    string $productId
): void {
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $product = (new Product())
        ->setTitle($productTitle);

    // Call the API and handle any network failures.
    try {
        /** @var Product $response */
        $response = $productServiceClient->createProduct($formattedParent, $product, $productId);
        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 = ProductServiceClient::branchName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]'
    );
    $productTitle = '[TITLE]';
    $productId = '[PRODUCT_ID]';

    create_product_sample($formattedParent, $productTitle, $productId);
}

deleteProduct

Deletes a Product.

Parameters
NameDescription
name string

Required. Full resource name of Product, such as projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id.

If the caller does not have permission to delete the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

If the Product to delete does not exist, a NOT_FOUND error is returned.

The Product to delete can neither be a Product.Type.COLLECTION Product member nor a Product.Type.PRIMARY Product with more than one variants. Otherwise, an INVALID_ARGUMENT error is returned.

All inventory information for the named Product will be deleted.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\ApiCore\ApiException;
use Google\Cloud\Retail\V2\ProductServiceClient;

/**
 * @param string $formattedName Full resource name of [Product][google.cloud.retail.v2.Product],
 *                              such as
 *                              `projects/&#42;/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id`.
 *
 *                              If the caller does not have permission to delete the
 *                              [Product][google.cloud.retail.v2.Product], regardless of whether or not it
 *                              exists, a PERMISSION_DENIED error is returned.
 *
 *                              If the [Product][google.cloud.retail.v2.Product] to delete does not exist,
 *                              a NOT_FOUND error is returned.
 *
 *                              The [Product][google.cloud.retail.v2.Product] to delete can neither be a
 *                              [Product.Type.COLLECTION][google.cloud.retail.v2.Product.Type.COLLECTION]
 *                              [Product][google.cloud.retail.v2.Product] member nor a
 *                              [Product.Type.PRIMARY][google.cloud.retail.v2.Product.Type.PRIMARY]
 *                              [Product][google.cloud.retail.v2.Product] with more than one
 *                              [variants][google.cloud.retail.v2.Product.Type.VARIANT]. Otherwise, an
 *                              INVALID_ARGUMENT error is returned.
 *
 *                              All inventory information for the named
 *                              [Product][google.cloud.retail.v2.Product] will be deleted. Please see
 *                              {@see ProductServiceClient::productName()} for help formatting this field.
 */
function delete_product_sample(string $formattedName): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Call the API and handle any network failures.
    try {
        $productServiceClient->deleteProduct($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } 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
{
    $formattedName = ProductServiceClient::productName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]',
        '[PRODUCT]'
    );

    delete_product_sample($formattedName);
}

getProduct

Gets a Product.

Parameters
NameDescription
name string

Required. Full resource name of Product, such as projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id.

If the caller does not have permission to access the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

If the requested Product does not exist, a NOT_FOUND error is returned.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Retail\V2\Product
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Retail\V2\Product;
use Google\Cloud\Retail\V2\ProductServiceClient;

/**
 * @param string $formattedName Full resource name of [Product][google.cloud.retail.v2.Product],
 *                              such as
 *                              `projects/&#42;/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id`.
 *
 *                              If the caller does not have permission to access the
 *                              [Product][google.cloud.retail.v2.Product], regardless of whether or not it
 *                              exists, a PERMISSION_DENIED error is returned.
 *
 *                              If the requested [Product][google.cloud.retail.v2.Product] does not exist,
 *                              a NOT_FOUND error is returned. Please see
 *                              {@see ProductServiceClient::productName()} for help formatting this field.
 */
function get_product_sample(string $formattedName): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var Product $response */
        $response = $productServiceClient->getProduct($formattedName);
        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
{
    $formattedName = ProductServiceClient::productName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]',
        '[PRODUCT]'
    );

    get_product_sample($formattedName);
}

importProducts

Bulk import of multiple Products.

Request processing may be synchronous. Non-existing items are created.

Note that it is possible for a subset of the Products to be successfully updated.

Parameters
NameDescription
parent string

Required. projects/1234/locations/global/catalogs/default_catalog/branches/default_branch

If no updateMask is specified, requires products.create permission. If updateMask is specified, requires products.update permission.

inputConfig Google\Cloud\Retail\V2\ProductInputConfig

Required. The desired input location of the data.

optionalArgs array

Optional.

↳ requestId string

Deprecated. This field has no effect.

↳ errorsConfig ImportErrorsConfig

The desired location of errors incurred during the Import.

↳ updateMask FieldMask

Indicates which fields in the provided imported products to update. If not set, all fields are updated.

↳ reconciliationMode int

The mode of reconciliation between existing products and the products to be imported. Defaults to ReconciliationMode.INCREMENTAL. For allowed values, use constants defined on Google\Cloud\Retail\V2\ImportProductsRequest\ReconciliationMode

↳ notificationPubsubTopic string

Full Pub/Sub topic name for receiving notification. If this field is set, when the import is finished, a notification is sent to specified Pub/Sub topic. The message data is JSON string of a Operation. Format of the Pub/Sub topic is projects/{project}/topics/{topic}. It has to be within the same project as ImportProductsRequest.parent. Make sure that service-<project number>@gcp-sa-retail.iam.gserviceaccount.com has the pubsub.topics.publish IAM permission on the topic.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Retail\V2\ImportProductsResponse;
use Google\Cloud\Retail\V2\ProductInputConfig;
use Google\Cloud\Retail\V2\ProductServiceClient;
use Google\Rpc\Status;

/**
 * @param string $formattedParent Required.
 *                                `projects/1234/locations/global/catalogs/default_catalog/branches/default_branch`
 *
 *                                If no updateMask is specified, requires products.create permission.
 *                                If updateMask is specified, requires products.update permission. Please see
 *                                {@see ProductServiceClient::branchName()} for help formatting this field.
 */
function import_products_sample(string $formattedParent): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $inputConfig = new ProductInputConfig();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $productServiceClient->importProducts($formattedParent, $inputConfig);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var ImportProductsResponse $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 = ProductServiceClient::branchName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]'
    );

    import_products_sample($formattedParent);
}

listProducts

Gets a list of Products.

Parameters
NameDescription
parent string

Required. The parent branch resource name, such as projects/*/locations/global/catalogs/default_catalog/branches/0. Use default_branch as the branch ID, to list products under the default branch.

If the caller does not have permission to list Products under this branch, regardless of whether or not this branch exists, a PERMISSION_DENIED error is returned.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ filter string

A filter to apply on the list results. Supported features: * List all the products under the parent branch if filter is unset. * List Product.Type.VARIANT Products sharing the same Product.Type.PRIMARY Product. For example: primary_product_id = "some_product_id" * List Products bundled in a Product.Type.COLLECTION Product. For example: collection_product_id = "some_product_id" * List Products with a partibular type. For example: type = "PRIMARY" type = "VARIANT" type = "COLLECTION" If the field is unrecognizable, an INVALID_ARGUMENT error is returned. If the specified Product.Type.PRIMARY Product or Product.Type.COLLECTION Product does not exist, a NOT_FOUND error is returned.

↳ readMask FieldMask

The fields of Product to return in the responses. If not set or empty, the following fields are returned: * Product.name * Product.id * Product.title * Product.uri * Product.images * Product.price_info * Product.brands If "*" is provided, all fields are returned. Product.name is always returned no matter what mask is set. If an unsupported or unknown field is provided, an INVALID_ARGUMENT error is returned.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Retail\V2\Product;
use Google\Cloud\Retail\V2\ProductServiceClient;

/**
 * @param string $formattedParent The parent branch resource name, such as
 *                                `projects/&#42;/locations/global/catalogs/default_catalog/branches/0`. Use
 *                                `default_branch` as the branch ID, to list products under the default
 *                                branch.
 *
 *                                If the caller does not have permission to list
 *                                [Product][google.cloud.retail.v2.Product]s under this branch, regardless of
 *                                whether or not this branch exists, a PERMISSION_DENIED error is returned. Please see
 *                                {@see ProductServiceClient::branchName()} for help formatting this field.
 */
function list_products_sample(string $formattedParent): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $productServiceClient->listProducts($formattedParent);

        /** @var Product $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->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 = ProductServiceClient::branchName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]'
    );

    list_products_sample($formattedParent);
}

removeFulfillmentPlaces

It is recommended to use the ProductService.RemoveLocalInventories method instead of ProductService.RemoveFulfillmentPlaces.

ProductService.RemoveLocalInventories achieves the same results but provides more fine-grained control over ingesting local inventory data.

Incrementally removes place IDs from a Product.fulfillment_info.place_ids.

This process is asynchronous and does not require the Product to exist before updating fulfillment information. If the request is valid, the update will be enqueued and processed downstream. As a consequence, when a response is returned, the removed place IDs are not immediately manifested in the Product queried by ProductService.GetProduct or ProductService.ListProducts.

The returned Operations will be obsolete after 1 day, and GetOperation API will return NOT_FOUND afterwards.

If conflicting updates are issued, the Operations associated with the stale updates will not be marked as done until being obsolete.

Parameters
NameDescription
product string

Required. Full resource name of Product, such as projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id.

If the caller does not have permission to access the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

type string

Required. The fulfillment type, including commonly used types (such as pickup in store and same day delivery), and custom types.

Supported values:

  • "pickup-in-store"
  • "ship-to-store"
  • "same-day-delivery"
  • "next-day-delivery"
  • "custom-type-1"
  • "custom-type-2"
  • "custom-type-3"
  • "custom-type-4"
  • "custom-type-5"

If this field is set to an invalid value other than these, an INVALID_ARGUMENT error is returned.

This field directly corresponds to Product.fulfillment_info.type.

placeIds string[]

Required. The IDs for this type, such as the store IDs for "pickup-in-store" or the region IDs for "same-day-delivery", to be removed for this type.

At least 1 value is required, and a maximum of 2000 values are allowed. Each value must be a string with a length limit of 10 characters, matching the pattern [a-zA-Z0-9_-]+, such as "store1" or "REGION-2". Otherwise, an INVALID_ARGUMENT error is returned.

optionalArgs array

Optional.

↳ removeTime Timestamp

The time when the fulfillment updates are issued, used to prevent out-of-order updates on fulfillment information. If not provided, the internal system time will be used.

↳ allowMissing bool

If set to true, and the Product is not found, the fulfillment information will still be processed and retained for at most 1 day and processed once the Product is created. If set to false, a NOT_FOUND error is returned if the Product is not found.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Retail\V2\ProductServiceClient;
use Google\Cloud\Retail\V2\RemoveFulfillmentPlacesResponse;
use Google\Rpc\Status;

/**
 * @param string $formattedProduct Full resource name of [Product][google.cloud.retail.v2.Product],
 *                                 such as
 *                                 `projects/&#42;/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id`.
 *
 *                                 If the caller does not have permission to access the
 *                                 [Product][google.cloud.retail.v2.Product], regardless of whether or not it
 *                                 exists, a PERMISSION_DENIED error is returned. Please see
 *                                 {@see ProductServiceClient::productName()} for help formatting this field.
 * @param string $type             The fulfillment type, including commonly used types (such as
 *                                 pickup in store and same day delivery), and custom types.
 *
 *                                 Supported values:
 *
 *                                 * "pickup-in-store"
 *                                 * "ship-to-store"
 *                                 * "same-day-delivery"
 *                                 * "next-day-delivery"
 *                                 * "custom-type-1"
 *                                 * "custom-type-2"
 *                                 * "custom-type-3"
 *                                 * "custom-type-4"
 *                                 * "custom-type-5"
 *
 *                                 If this field is set to an invalid value other than these, an
 *                                 INVALID_ARGUMENT error is returned.
 *
 *                                 This field directly corresponds to
 *                                 [Product.fulfillment_info.type][google.cloud.retail.v2.FulfillmentInfo.type].
 * @param string $placeIdsElement  The IDs for this
 *                                 [type][google.cloud.retail.v2.RemoveFulfillmentPlacesRequest.type], such as
 *                                 the store IDs for "pickup-in-store" or the region IDs for
 *                                 "same-day-delivery", to be removed for this
 *                                 [type][google.cloud.retail.v2.RemoveFulfillmentPlacesRequest.type].
 *
 *                                 At least 1 value is required, and a maximum of 2000 values are allowed.
 *                                 Each value must be a string with a length limit of 10 characters, matching
 *                                 the pattern `[a-zA-Z0-9_-]+`, such as "store1" or "REGION-2". Otherwise, an
 *                                 INVALID_ARGUMENT error is returned.
 */
function remove_fulfillment_places_sample(
    string $formattedProduct,
    string $type,
    string $placeIdsElement
): void {
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $placeIds = [$placeIdsElement,];

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $productServiceClient->removeFulfillmentPlaces($formattedProduct, $type, $placeIds);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var RemoveFulfillmentPlacesResponse $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
{
    $formattedProduct = ProductServiceClient::productName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]',
        '[PRODUCT]'
    );
    $type = '[TYPE]';
    $placeIdsElement = '[PLACE_IDS]';

    remove_fulfillment_places_sample($formattedProduct, $type, $placeIdsElement);
}

removeLocalInventories

Remove local inventory information for a Product at a list of places at a removal timestamp.

This process is asynchronous. If the request is valid, the removal will be enqueued and processed downstream. As a consequence, when a response is returned, removals are not immediately manifested in the Product queried by ProductService.GetProduct or ProductService.ListProducts.

Local inventory information can only be removed using this method. ProductService.CreateProduct and ProductService.UpdateProduct has no effect on local inventories.

The returned Operations will be obsolete after 1 day, and GetOperation API will return NOT_FOUND afterwards.

If conflicting updates are issued, the Operations associated with the stale updates will not be marked as done until being obsolete.

Parameters
NameDescription
product string

Required. Full resource name of Product, such as projects/*/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id.

If the caller does not have permission to access the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

placeIds string[]

Required. A list of place IDs to have their inventory deleted. At most 3000 place IDs are allowed per request.

optionalArgs array

Optional.

↳ removeTime Timestamp

The time when the inventory deletions are issued. Used to prevent out-of-order updates and deletions on local inventory fields. If not provided, the internal system time will be used.

↳ allowMissing bool

If set to true, and the Product is not found, the local inventory removal request will still be processed and retained for at most 1 day and processed once the Product is created. If set to false, a NOT_FOUND error is returned if the Product is not found.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Retail\V2\ProductServiceClient;
use Google\Cloud\Retail\V2\RemoveLocalInventoriesResponse;
use Google\Rpc\Status;

/**
 * @param string $formattedProduct Full resource name of [Product][google.cloud.retail.v2.Product],
 *                                 such as
 *                                 `projects/&#42;/locations/global/catalogs/default_catalog/branches/default_branch/products/some_product_id`.
 *
 *                                 If the caller does not have permission to access the
 *                                 [Product][google.cloud.retail.v2.Product], regardless of whether or not it
 *                                 exists, a PERMISSION_DENIED error is returned. Please see
 *                                 {@see ProductServiceClient::productName()} for help formatting this field.
 * @param string $placeIdsElement  A list of place IDs to have their inventory deleted.
 *                                 At most 3000 place IDs are allowed per request.
 */
function remove_local_inventories_sample(string $formattedProduct, string $placeIdsElement): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $placeIds = [$placeIdsElement,];

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $productServiceClient->removeLocalInventories($formattedProduct, $placeIds);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var RemoveLocalInventoriesResponse $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
{
    $formattedProduct = ProductServiceClient::productName(
        '[PROJECT]',
        '[LOCATION]',
        '[CATALOG]',
        '[BRANCH]',
        '[PRODUCT]'
    );
    $placeIdsElement = '[PLACE_IDS]';

    remove_local_inventories_sample($formattedProduct, $placeIdsElement);
}

setInventory

Updates inventory information for a Product while respecting the last update timestamps of each inventory field.

This process is asynchronous and does not require the Product to exist before updating fulfillment information. If the request is valid, the update is enqueued and processed downstream. As a consequence, when a response is returned, updates are not immediately manifested in the Product queried by ProductService.GetProduct or ProductService.ListProducts.

When inventory is updated with ProductService.CreateProduct and ProductService.UpdateProduct, the specified inventory field value(s) overwrite any existing value(s) while ignoring the last update time for this field. Furthermore, the last update times for the specified inventory fields are overwritten by the times of the ProductService.CreateProduct or ProductService.UpdateProduct request.

If no inventory fields are set in CreateProductRequest.product, then any pre-existing inventory information for this product is used.

If no inventory fields are set in SetInventoryRequest.set_mask, then any existing inventory information is preserved.

Pre-existing inventory information can only be updated with ProductService.SetInventory, ProductService.AddFulfillmentPlaces, and ProductService.RemoveFulfillmentPlaces.

The returned Operations is obsolete after one day, and the GetOperation API returns NOT_FOUND afterwards.

If conflicting updates are issued, the Operations associated with the stale updates are not marked as done until they are obsolete.

Parameters
NameDescription
inventory Google\Cloud\Retail\V2\Product

Required. The inventory information to update. The allowable fields to update are:

If SetInventoryRequest.inventory.name is empty or invalid, an INVALID_ARGUMENT error is returned.

If the caller does not have permission to update the Product named in Product.name, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

If the Product to update does not have existing inventory information, the provided inventory information will be inserted.

If the Product to update has existing inventory information, the provided inventory information will be merged while respecting the last update time for each inventory field, using the provided or default value for SetInventoryRequest.set_time.

The caller can replace place IDs for a subset of fulfillment types in the following ways:

The caller can clear all place IDs from a subset of fulfillment types in the following ways:

The last update time is recorded for the following inventory fields:

If a full overwrite of inventory information while ignoring timestamps is needed, ProductService.UpdateProduct should be invoked instead.

optionalArgs array

Optional.

↳ setMask FieldMask

Indicates which inventory fields in the provided Product to update. At least one field must be provided. If an unsupported or unknown field is provided, an INVALID_ARGUMENT error is returned and the entire update will be ignored.

↳ setTime Timestamp

The time when the request is issued, used to prevent out-of-order updates on inventory fields with the last update time recorded. If not provided, the internal system time will be used.

↳ allowMissing bool

If set to true, and the Product with name Product.name is not found, the inventory update will still be processed and retained for at most 1 day until the Product is created. If set to false, a NOT_FOUND error is returned if the Product is not found.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Retail\V2\Product;
use Google\Cloud\Retail\V2\ProductServiceClient;
use Google\Cloud\Retail\V2\SetInventoryResponse;
use Google\Rpc\Status;

/**
 * @param string $inventoryTitle Product title.
 *
 *                               This field must be a UTF-8 encoded string with a length limit of 1,000
 *                               characters. Otherwise, an INVALID_ARGUMENT error is returned.
 *
 *                               Corresponding properties: Google Merchant Center property
 *                               [title](https://support.google.com/merchants/answer/6324415). Schema.org
 *                               property [Product.name](https://schema.org/name).
 */
function set_inventory_sample(string $inventoryTitle): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $inventory = (new Product())
        ->setTitle($inventoryTitle);

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

        if ($response->operationSucceeded()) {
            /** @var SetInventoryResponse $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
{
    $inventoryTitle = '[TITLE]';

    set_inventory_sample($inventoryTitle);
}

updateProduct

Updates a Product.

Parameters
NameDescription
product Google\Cloud\Retail\V2\Product

Required. The product to update/create.

If the caller does not have permission to update the Product, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

If the Product to update does not exist and allow_missing is not set, a NOT_FOUND error is returned.

optionalArgs array

Optional.

↳ updateMask FieldMask

Indicates which fields in the provided Product to update. The immutable and output only fields are NOT supported. If not set, all supported fields (the fields that are neither immutable nor output only) are updated. If an unsupported or unknown field is provided, an INVALID_ARGUMENT error is returned. The attribute key can be updated by setting the mask path as "attributes.${key_name}". If a key name is present in the mask but not in the patching product from the request, this key will be deleted after the update.

↳ allowMissing bool

If set to true, and the Product is not found, a new Product will be created. In this situation, update_mask is ignored.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Retail\V2\Product
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Retail\V2\Product;
use Google\Cloud\Retail\V2\ProductServiceClient;

/**
 * @param string $productTitle Product title.
 *
 *                             This field must be a UTF-8 encoded string with a length limit of 1,000
 *                             characters. Otherwise, an INVALID_ARGUMENT error is returned.
 *
 *                             Corresponding properties: Google Merchant Center property
 *                             [title](https://support.google.com/merchants/answer/6324415). Schema.org
 *                             property [Product.name](https://schema.org/name).
 */
function update_product_sample(string $productTitle): void
{
    // Create a client.
    $productServiceClient = new ProductServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $product = (new Product())
        ->setTitle($productTitle);

    // Call the API and handle any network failures.
    try {
        /** @var Product $response */
        $response = $productServiceClient->updateProduct($product);
        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
{
    $productTitle = '[TITLE]';

    update_product_sample($productTitle);
}

getOperationsClient

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

Returns
TypeDescription
Google\ApiCore\LongRunning\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
NameDescription
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
TypeDescription
Google\ApiCore\OperationResponse

static::branchName

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

Parameters
NameDescription
project string
location string
catalog string
branch string
Returns
TypeDescription
stringThe formatted branch resource.

static::productName

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

Parameters
NameDescription
project string
location string
catalog string
branch string
product string
Returns
TypeDescription
stringThe formatted product 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

  • branch: projects/{project}/locations/{location}/catalogs/{catalog}/branches/{branch}
  • product: projects/{project}/locations/{location}/catalogs/{catalog}/branches/{branch}/products/{product}

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
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

Constants

SERVICE_NAME

Value: 'google.cloud.retail.v2.ProductService'

The name of the service.

SERVICE_ADDRESS

Value: 'retail.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.