Stay organized with collections
Save and categorize content based on your preferences.
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:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eWhen using optional fields in Google Ads API requests, construct the request message separately and pass it as a single parameter to the method.\u003c/p\u003e\n"],["\u003cp\u003eOptional request headers like \u003ccode\u003evalidate_only\u003c/code\u003e are set directly on the request message, not as keyword parameters in the method signature.\u003c/p\u003e\n"],["\u003cp\u003eYou can identify required or optional request fields by checking the protobuf definitions and looking for the \u003ccode\u003e[(google.api.field_behavior) = REQUIRED]\u003c/code\u003e annotation.\u003c/p\u003e\n"],["\u003cp\u003eTo 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.\u003c/p\u003e\n"]]],[],null,["When using any\n[optional fields](//protobuf.dev/programming-guides/proto3/#field-labels) on a\nrequest method, the request message must be constructed outside of the\nmethod and passed in as a single parameter.\n\nOptional request headers, for example the\n[`validate_only`](/google-ads/api/reference/rpc/v20/SearchGoogleAdsRequest#validate_only) header in\nthe [`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v20/GoogleAdsService#search) method,\nare not present in the method signature as keyword parameters, so they must be\nset on the request message directly.\n\nTo determine if a request object field is required or optional, you can\nreference the [protobuf definitions for\nservices](//github.com/googleapis/googleapis/tree/master/google/ads/googleads/v20/services)\nand look for fields that contain the annotation `[(google.api.field_behavior) =\nREQUIRED]`.\n\nHere's an example that sets the optional `validate_only` field\non a [`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v20/GoogleAdsService#search) request: \n\n request = client.get_type(\"SearchGoogleAdsRequest\")\n request.customer_id = customer_id\n request.query = query\n request.validate_only = True\n\n response = googleads_service.search(request=request)"]]