Ok so I had a few more trials until I got it to work. I will post the final code hoping it would help someone in the future
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']: operations.append({ 'operator': 'SET', 'operand': { 'xsi_type': 'BiddableAdGroupCriterion', 'adGroupId': adgroup_id, 'criterion': { 'id': keyword['criterion']['id'], }, 'finalUrls':{'urls':'https://just.a.url'} } }) 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) 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"]) #ideas(adwords_client, adgroup["id"]) On Wednesday, April 18, 2018 at 2:35:29 PM UTC+4, Hussein Negm wrote: > > 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/81026982-e756-4cb8-9069-7c67c36e3e0e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.