def main(client, adgroup_id, ad_id):
  # Initialize appropriate service.
  adgroup_ad_service = client.GetService('AdGroupAdService', version='v201603')

  selector = {
      'fields': ['Id', 'Url'],
      'predicates': [
          {
              'field': 'AdGroupId',
              'operator': 'EQUALS',
              'values': [adgroup_id]
          },
          {
              'field': 'Id',
              'operator': 'EQUALS',
              'values': [ad_id]
          }
      ]
  }

  page = adgroup_ad_service.get(selector)

  adgroup_ad = page['entries'][0] if page['entries'] else None

  if not adgroup_ad:
    raise errors.GoogleAdsError('Ad not found.')

  ad_url_upgrade = {
      'adId': adgroup_ad['ad']['id'],
      'finalUrl': adgroup_ad['ad']['url']
  }

  adgroup_ad = adgroup_ad_service.upgradeUrl([ad_url_upgrade])[0]

  if adgroup_ad:
    print ('AdGroupAd with ID %s and destination URL \'%s\' was upgraded.'
           % (adgroup_ad['id'], adgroup_ad['finalUrls'][0]))
  else:
    raise errors.GoogleAdsError('Failed to create AdGroupAd.')
dataset/ETHPy150Open googleads/googleads-python-lib/examples/adwords/v201603/migration/upgrade_ad_url.py/main/original