When setting [optional fields](https://protobuf.dev/programming-guides/proto3/#field-labels) on an API request, you must
construct the request message object directly and pass it as a single `request`
parameter to the service method.

Optional request fields---such as the
[`validate_only`](https://developers.google.com/google-ads/api/reference/rpc/v26/SearchGoogleAdsRequest.md.txt#validate_only) field in
the [`GoogleAdsService.Search`](https://developers.google.com/google-ads/api/reference/rpc/v26/GoogleAdsService/Search.md.txt)
method---are omitted from flattened method signatures to keep keyword parameters
manageable, so you must set them on the request message instance directly.

To determine whether a request object field is required or optional, refer to
the [Google Ads API protobuf service definitions](https://github.com/googleapis/googleapis/tree/master/google/ads/googleads/v26/services) and look for
fields that contain the annotation `[(google.api.field_behavior) = REQUIRED]`.
Fields without this annotation are optional.

The following example constructs a `SearchGoogleAdsRequest` object and sets the
optional `validate_only` field on a
[`GoogleAdsService.Search`](https://developers.google.com/google-ads/api/reference/rpc/v26/GoogleAdsService/Search.md.txt) request:

```python
from google.ads.googleads.client import GoogleAdsClient

client = GoogleAdsClient.load_from_storage()
googleads_service = client.get_service("GoogleAdsService")

# Initialize the request object and set required fields.
request = client.get_type("SearchGoogleAdsRequest")
request.customer_id = customer_id
request.query = query

# Set the optional validate_only field.
request.validate_only = True

response = googleads_service.search(request=request)
```