When setting optional fields 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 field in
the GoogleAdsService.Search
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 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 request:
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)