How to Bid at the Criterion Level using Google Ads Api

207 views
Skip to first unread message

Paul Engel

unread,
Jun 6, 2019, 6:16:15 AM6/6/19
to AdWords API and Google Ads API Forum
I am trying to use the Google Ads API but my understanding of this library is limited.  
I have created a client and am trying to update cpc_bid_micros.  


I am getting the following output and am unable to diagnosis it any further.  Any help would be appreciated.

ad_group_criterion.resource_name customers/5420633870/adGroupCriteria/67392656629~1734040956
ad_group_criterion 0
ad_group_criterion 2560000
Request made: ClientCustomerId: 5420633870, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v1.services.AdGroupCriterionService/MutateAdGroupCriteria, RequestId: rr-awPlHu-PMzNzOJULvOQ, IsFault: True, FaultMessage: Resource was not found.
Request with ID "rr-awPlHu-PMzNzOJULvOQ" failed with status "INVALID_ARGUMENT" and includes the following errors:
        Error with message "Resource was not found.".
                On field: operations
                On field: update
                On field: resource_name



def main(client, customer_id, ad_group_id, criterion_id):
agc_service = client.get_service('AdGroupCriterionService', version='v1')

ad_group_criterion_operation = client.get_type('AdGroupCriterionOperation',
version='v1')


ad_group_criterion = ad_group_criterion_operation.update
ad_group_criterion.resource_name = agc_service.ad_group_criteria_path(
customer_id, ResourceName.format_composite(ad_group_id, criterion_id))
print("ad_group_criterion.resource_name", ad_group_criterion.resource_name)
print('ad_group_criterion', ad_group_criterion.cpc_bid_micros.value)
ad_group_criterion.status = client.get_type('AdGroupCriterionStatusEnum', version='v1').ENABLED
ad_group_criterion.cpc_bid_micros.value = 2560000
print('ad_group_criterion', ad_group_criterion.cpc_bid_micros.value)
fm = protobuf_helpers.field_mask(None, ad_group_criterion)
ad_group_criterion_operation.update_mask.CopyFrom(fm)



try:
#
agc_response = agc_service.mutate_ad_group_criteria(
customer_id, [ad_group_criterion_operation])
except google.ads.google_ads.errors.GoogleAdsException as ex:
print('Request with ID "%s" failed with status "%s" and includes the '
'following errors:' % (ex.request_id, ex.error.code().name))
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print('\t\tOn field: %s' % field_path_element.field_name)
sys.exit(1)

print('Updated keyword %s.' % agc_response.results[0].resource_name)

Google Ads API Forum Advisor Prod

unread,
Jun 6, 2019, 3:58:43 PM6/6/19
to pen...@turo.com, adwor...@googlegroups.com
Hello Paul, 

I was able to set the cpc_bid_micros for the keyword using the Python client library. Please find the code snippet below as a reference. 

ad_group_criterion.ad_group.value = ad_group_service.ad_group_path(customer_id, ad_group_id)
ad_group_criterion.status = client.get_type('AdGroupCriterionStatusEnum').ENABLED
ad_group_criterion.keyword.text.value = keyword
ad_group_criterion.cpc_bid_micros.value = 2560000
ad_group_criterion.keyword.match_type = client.get_type('KeywordMatchTypeEnum').EXACT

Could you please share the complete request and response logs which will help us troubleshoot the issue? Could you please share details of the Python client library version that you're using?

Thanks,
Bharani, Google Ads API Team

ref:_00D1U1174p._5001UBloxd:ref

Rubens Maria

unread,
Oct 28, 2019, 2:34:09 PM10/28/19
to AdWords API and Google Ads API Forum

Hello Paul, 

Your code helped me a lot to make mine. 
So i will add how i did one code to bid at ad group level.

Thanks for this tread.


ad_group_criterion_service = client.get_service('AdGroupCriterionService', version='v2')

ad_group_criterion_operation = client.get_type('AdGroupCriterionOperation', version='v2')

ad_group_criterion = ad_group_criterion_operation.update
ad_group_criterion.resource_name = ad_group_criterion_service.ad_group_criteria_path(
customer_id, ResourceName.format_composite(ad_group_id, criteria_id))

ad_group_criterion.bid_modifier.value = 3

fm = protobuf_helpers.field_mask(None, ad_group_criterion)
ad_group_criterion_operation.update_mask.CopyFrom(fm)

ad_group_criterion_service.mutate_ad_group_criteria(customer_id, [ad_group_criterion_operation])
Reply all
Reply to author
Forward
0 new messages