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 page_size and validate_only headers 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 page_size and validate_only fields on a GoogleAdsService.Search request:

request = client.get_type("SearchGoogleAdsRequest")
request.customer_id = customer_id
request.query = query
request.page_size = 10000
request.validate_only = True

response = googleads_service.search(request=request)