My goal is retrieve all the keywords in an adGroup and update the final URL 
the following code (and other similar versions ) give me the error 

TypeNotFound: Type not found: 'finalUrls'




def main(client, adgroup_id):
  # Initialize appropriate service.
  ad_group_criterion_service = client.GetService(
      'AdGroupCriterionService', version='v201802')

  # Construct selector and get all ad group criteria.
  offset = 0
  selector = {
      'fields': ['Id', 'CriteriaType', 'KeywordMatchType', 
'KeywordText','FinalUrls'],
      'predicates': [
          {
              'field': 'AdGroupId',
              'operator': 'EQUALS',
              'values': [adgroup_id]
          },
          {
              'field': 'CriteriaType',
              'operator': 'EQUALS',
              'values': ['KEYWORD'],
          }
      ],
      'paging': {
          'startIndex': str(offset),
          'numberResults': str(PAGE_SIZE)
      },
      'ordering': [{'field': 'KeywordText', 'sortOrder': 'ASCENDING'}]
  }
  more_pages = True
  operations = []
  while more_pages:
    page = ad_group_criterion_service.get(selector)

    # Display results.
    if 'entries' in page:
      for keyword in page['entries']:
        print ('Keyword ID "%s", type "%s", text "%s", and match type '
               '"%s" was found.' % (
                   keyword['criterion']['id'],
                   keyword['criterion']['type'],
                   keyword['criterion']['text'],
                   keyword['criterion']['matchType']))
        pprint(keyword)
        
        trgt={
            'criterion':keyword['criterion'],
            'finalUrls':{"urls":['https://URL.url.url']}
        }
        operations.append({'operator': 'SET', 'operand': trgt  })
      
    else:
      print ('No keywords were found.')
    offset += PAGE_SIZE
    selector['paging']['startIndex'] = str(offset)
    more_pages = offset < int(page['totalNumEntries'])
  ad_group_criteria = ad_group_criterion_service.mutate(operations)['value']
if __name__ == '__main__':
  # Initialize client object.
  CLIENT_ID = '####' 
  CLIENT_SECRET = '####'
  REFRESH_TOKEN = '###'
  # AdWords API information.
  DEVELOPER_TOKEN = '###'
  USER_AGENT = '####' 
  CLIENT_CUSTOMER_ID = '###' 
  oauth2_client = oauth2.GoogleRefreshTokenClient(CLIENT_ID, CLIENT_SECRET, 
REFRESH_TOKEN)
  adwords_client = adwords.AdWordsClient( DEVELOPER_TOKEN, oauth2_client, 
USER_AGENT,client_customer_id=CLIENT_CUSTOMER_ID)
  
adgroupsList=[{'id':54627912232,'nh':'','category':''},{'id':57139439947,'nh':'','category':''},{'id':60015897731,'nh':'','category':''}]
  for adgroup in adgroupsList:
    main(adwords_client, adgroup["id"])


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/f1b37179-ed06-484f-9e76-898c2d39b80c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • Updating Key... Hussein Negm
    • Re: Upd... Hussein Negm
      • Re:... 'Dhanya Sundararaju (AdWords API Team)' via AdWords API Forum

Reply via email to