- [HTTP request](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.HTTP_TEMPLATE)
- [Path parameters](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.PATH_PARAMETERS)
- [Query parameters](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.QUERY_PARAMETERS)
- [Request body](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.request_body)
- [Response body](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.response_body)
  - [JSON representation](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.CompleteQueryResponse.SCHEMA_REPRESENTATION)
- [Authorization scopes](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.aspect)
- [IAM Permissions](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#body.aspect_1)
- [CompletionResult](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#CompletionResult)
  - [JSON representation](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#CompletionResult.SCHEMA_REPRESENTATION)
- [RecentSearchResult](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#RecentSearchResult)
  - [JSON representation](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#RecentSearchResult.SCHEMA_REPRESENTATION)
- [AttributeResult](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#AttributeResult)
  - [JSON representation](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#AttributeResult.SCHEMA_REPRESENTATION)
- [Try it!](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs/completeQuery.md.txt#try-it)

Completes the specified prefix with keyword suggestions.

This feature is only available for users who have Retail Search enabled. Enable Retail Search on Cloud Console before using this feature.

### HTTP request

`GET https://retail.googleapis.com/v2/{catalog=projects/*/locations/*/catalogs/*}:completeQuery`

The URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.

### Path parameters

| Parameters ||
|---|---|
| `catalog` | `string` Required. Catalog for which the completion is performed. Full resource name of catalog, such as `projects/*/locations/global/catalogs/default_catalog`. |

### Query parameters

| Parameters ||
|---|---|
| `query` | `string` Required. The query used to generate suggestions. The maximum number of allowed characters is 255. |
| `visitorId` | `string` Recommended field. A unique identifier for tracking visitors. For example, this could be implemented with an HTTP cookie, which should be able to uniquely identify a visitor on a single device. This unique identifier should not change if the visitor logs in or out of the website. The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned. |
| `languageCodes[]` | `string` Note that this field applies for `user-data` dataset only. For requests with `cloud-retail` dataset, setting this field has no effect. The language filters applied to the output suggestions. If set, it should contain the language of the query. If not set, suggestions are returned without considering language restrictions. This is the BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see [Tags for Identifying Languages](https://tools.ietf.org/html/bcp47). The maximum number of language codes is 3. |
| `deviceType` | `string` The device type context for completion suggestions. We recommend that you leave this field empty. It can apply different suggestions on different device types, e.g. `DESKTOP`, `MOBILE`. If it is empty, the suggestions are across all device types. Supported formats: - `UNKNOWN_DEVICE_TYPE` - `DESKTOP` - `MOBILE` - A customized string starts with `OTHER_`, e.g. `OTHER_IPHONE`. |
| `dataset` | `string` Determines which dataset to use for fetching completion. "user-data" will use the dataset imported through `CompletionService.ImportCompletionData`. `cloud-retail` will use the dataset generated by Cloud Retail based on user events. If left empty, completions will be fetched from the `user-data` dataset. Current supported values: - user-data - cloud-retail: This option requires enabling auto-learning function first. See [guidelines](https://cloud.google.com/retail/docs/completion-overview#generated-completion-dataset). |
| `maxSuggestions` | `integer` Completion max suggestions. If left unset or set to 0, then will fallback to the configured value `CompletionConfig.max_suggestions`. The maximum allowed max suggestions is 20. If it is set higher, it will be capped by 20. |
| `enableAttributeSuggestions` | `boolean` If true, attribute suggestions are enabled and provided in the response. This field is only available for the `cloud-retail` dataset. |
| `entity` | `string` The entity for customers who run multiple entities, domains, sites, or regions, for example, `Google US`, `Google Ads`, `Waymo`, `google.com`, `youtube.com`, etc. If this is set, it must be an exact match with `UserEvent.entity` to get per-entity autocomplete results. This field will be applied to `completionResults` only. It has no effect on the `attributeResults`. Also, this entity should be limited to 256 characters, if too long, it will be truncated to 256 characters in both generation and serving time, and may lead to mis-match. To ensure it works, please set the entity with string within 256 characters. |

### Request body

The request body must be empty.

### Response body

Response of the autocomplete query.

If successful, the response body contains data with the following structure:

| JSON representation |
|---|
| ``` { "completionResults": [ { object (`CompletionResult`) } ], "attributionToken": string, "recentSearchResults": [ { object (`RecentSearchResult`) } ], "attributeResults": { string: { object (`AttributeResult`) }, ... } } ``` |

| Fields ||
|---|---|
| `completionResults[]` | ``object (`CompletionResult`)`` Results of the matching suggestions. The result list is ordered and the first result is top suggestion. |
| `attributionToken` | `string` A unique complete token. This should be included in the `UserEvent.completion_detail` for search events resulting from this completion, which enables accurate attribution of complete model performance. |
| `recentSearchResults[] (deprecated)` | ``object (`RecentSearchResult`)`` > [!WARNING] > This item is deprecated! Deprecated. Matched recent searches of this user. The maximum number of recent searches is 10. This field is a restricted feature. If you want to enable it, contact Retail Search support. This feature is only available when `CompleteQueryRequest.visitor_id` field is set and `UserEvent` is imported. The recent searches satisfy the follow rules: - They are ordered from latest to oldest. - They are matched with `CompleteQueryRequest.query` case insensitively. - They are transformed to lower case. - They are UTF-8 safe. Recent searches are deduplicated. More recent searches will be reserved when duplication happens. |
| `attributeResults` | ``map (key: string, value: object (`AttributeResult`))`` A map of matched attribute suggestions. This field is only available for `cloud-retail` dataset. Current supported keys: - `brands` - `categories` |

### Authorization scopes

Requires the following OAuth scope:

- `https://www.googleapis.com/auth/cloud-platform`

For more information, see the [Authentication Overview](https://docs.cloud.google.com/docs/authentication.md.txt#authorization-gcp).

### IAM Permissions

Requires the following [IAM](https://cloud.google.com/iam/docs) permission on the `catalog` resource:

- `retail.catalogs.completeQuery`

For more information, see the [IAM documentation](https://cloud.google.com/iam/docs).

## CompletionResult

Resource that represents completion results.

| JSON representation |
|---|
| ``` { "suggestion": string, "attributes": { string: { "text": [ string ], "numbers": [ number ], "searchable": boolean, "indexable": boolean }, ... } } ``` |

| Fields ||
|---|---|
| `suggestion` | `string` The suggestion for the query. |
| `attributes` | `map (key: string, value: object)` Custom attributes for the suggestion term. - For `user-data`, the attributes are additional custom attributes ingested through BigQuery. - For `cloud-retail`, the attributes are product attributes generated by Cloud Retail. It requires `UserEvent.product_details` is imported properly. |
| `attributes.text[]` | `string` The textual values of this custom attribute. For example, `["yellow", "green"]` when the key is "color". Empty string is not allowed. Otherwise, an INVALID_ARGUMENT error is returned. Exactly one of `text` or `numbers` should be set. Otherwise, an INVALID_ARGUMENT error is returned. |
| `attributes.numbers[]` | `number` The numerical values of this custom attribute. For example, `[2.3, 15.4]` when the key is "lengths_cm". Exactly one of `text` or `numbers` should be set. Otherwise, an INVALID_ARGUMENT error is returned. |
| `attributes.searchable (deprecated)` | `boolean` This field is normally ignored unless `AttributesConfig.attribute_config_level` of the `Catalog` is set to the deprecated 'PRODUCT_LEVEL_ATTRIBUTE_CONFIG' mode. For information about product-level attribute configuration, see [Configuration modes](https://cloud.google.com/retail/docs/attribute-config#config-modes). If true, custom attribute values are searchable by text queries in `SearchService.Search`. This field is ignored in a `UserEvent`. Only set if type `text` is set. Otherwise, a INVALID_ARGUMENT error is returned. |
| `attributes.indexable (deprecated)` | `boolean` This field is normally ignored unless `AttributesConfig.attribute_config_level` of the `Catalog` is set to the deprecated 'PRODUCT_LEVEL_ATTRIBUTE_CONFIG' mode. For information about product-level attribute configuration, see [Configuration modes](https://cloud.google.com/retail/docs/attribute-config#config-modes). If true, custom attribute values are indexed, so that they can be filtered, faceted or boosted in `SearchService.Search`. This field is ignored in a `UserEvent`. See `SearchRequest.filter`, `SearchRequest.facet_specs` and `SearchRequest.boost_spec` for more details. |

## RecentSearchResult

> [!WARNING]
> This item is deprecated!

Deprecated: Recent search of this user.

| JSON representation |
|---|
| ``` { "recentSearch": string } ``` |

| Fields ||
|---|---|
| `recentSearch` | `string` The recent search query. |

## AttributeResult

Resource that represents attribute results.

| JSON representation |
|---|
| ``` { "suggestions": [ string ] } ``` |

| Fields ||
|---|---|
| `suggestions[]` | `string` The list of suggestions for the attribute. |