Invalid constructor input for mutating - no documentation?

577 views
Skip to first unread message

Rob Montalbine

unread,
Aug 26, 2021, 3:57:59 PM8/26/21
to AdWords API and Google Ads API Forum
I'm trying to simply update keyword bids using v8 of the Google Ads API via AdGroupCriterionService in Python. I've copy/pasted most of the code for this particular operation directly from several google-provided examples and am getting the same error every time:

TypeError: Invalid constructor input for MutateAdGroupCriteriaRequest: [{'operator': 'SET', 'operand': {'adGroupId': '128454119123', 'criterion': {'id': '1410226011123'}, 'status': 'ENABLED', 'biddingStrategyConfiguration': {'bids': [{'xsi_type': 'CpcBid', 'bid': {'microAmount': '1000000'}}]}}}]

This operation was copied directly from Google's documentation,  but is still throwing errors that I can't find a way around, and I can't find any additional guidance on properly formatting these constructor inputs. Can someone please tell me where this is going wrong? I've had nothing but problems and non-functioning code examples since moving to the Google Ads API. Would greatly appreciate a solution. All IDs below are falsified.
------------------------------------------------------------
from googleads import adwords
from google.ads.googleads.client import GoogleAdsClient

AD_GROUP_ID = '128454119123'
CRITERION_ID = '1410226011123'

def main(client, ad_group_id, criterion_id):
  # Initialize appropriate service.
  ad_group_criterion_service = client.get_service(
      'AdGroupCriterionService', version='v8')

  # Construct operations and update bids.

  operations = [{
      'operator': 'SET',
      'operand': {
          #'xsi_type': 'BiddableAdGroupCriterion',
          'adGroupId': ad_group_id,
          'criterion': {
              'id': criterion_id},
              'status': 'ENABLED',
          'biddingStrategyConfiguration': {
              'bids': [
                   {
                       'xsi_type': 'CpcBid',
                       'bid': {
                           'microAmount': '1000000'
                       }
                   }
               ]
           }
       }
  }]
  ad_group_criteria = ad_group_criterion_service.mutate_ad_group_criteria(operations)

  # Display results.
  if 'value' in ad_group_criteria:
    for criterion in ad_group_criteria['value']:
      if criterion['criterion']['Criterion.Type'] == 'Keyword':
        print('Ad group criterion with ad group id "%s" and criterion id '
              '"%s" currently has bids:'
              % (criterion['adGroupId'], criterion['criterion']['id']))
        for bid in criterion['biddingStrategyConfiguration']['bids']:
          print('\tType: "%s", value: %s' %
                (bid['Bids.Type'], bid['bid']['microAmount']))
  else:
    print('No ad group criteria were updated.')


if __name__ == '__main__':
  # Initialize client object.
  credentials = {
    "developer_token": "REDACTED",
    "refresh_token": "REDACTED",
    "client_id": "REDACTED",
    "client_secret": "REDACTED",
    "login_customer_id":"REDACTED"}
    
  adwords_client = GoogleAdsClient.load_from_dict(credentials)

  main(adwords_client, AD_GROUP_ID, CRITERION_ID)

Google Ads API Forum Advisor

unread,
Aug 27, 2021, 2:21:31 AM8/27/21
to rob.mon...@ahs.com, adwor...@googlegroups.com
Hi Rob,

Thank you for reaching out to our API support team.

Regarding your issue with updating your bids, could you confirm if this Python example is what you were referring to?

So that our team may take a closer look, could you enable logging and provide to our team the complete request and response logs, with the request-id, generated when you received the error? 

You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2Mj96c:ref
Reply all
Reply to author
Forward
0 new messages