Interested in sharing your feedback about the Google Ads API?
Sign up to be invited to participate in user research!
Optional request headers
When using any
optional fields on a
request method, the request message must be constructed outside of the
method and passed in as a single parameter.
Optional request headers, for example the
validate_only
header in
the GoogleAdsService.Search
method,
are not present in the method signature as keyword parameters, so they must be
set on the request message directly.
To determine if a request object field is required or optional, you can
reference the protobuf definitions for
services
and look for fields that contain the annotation [(google.api.field_behavior) =
REQUIRED]
.
Here's an example that sets the optional validate_only
field
on a GoogleAdsService.Search
request:
request = client.get_type("SearchGoogleAdsRequest")
request.customer_id = customer_id
request.query = query
request.validate_only = True
response = googleads_service.search(request=request)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-03-03 UTC.
[null,null,["Last updated 2025-03-03 UTC."],[[["When using optional fields in Google Ads API requests, construct the request message separately and pass it as a single parameter to the method."],["Optional request headers like `validate_only` are set directly on the request message, not as keyword parameters in the method signature."],["You can identify required or optional request fields by checking the protobuf definitions and looking for the `[(google.api.field_behavior) = REQUIRED]` annotation."],["To use optional fields, create an instance of the request message type, populate its fields including the optional ones, and then pass it to the API method."]]],[]]