RE: How to use google ads api python to update keyword text value?

2020-03-17 Thread Google Ads API Forum Advisor Prod
Hi Rukeith,

The Keyword object's text is immutable once it is created. If you need to 
modify the text you would have to remove the existing Keyword and then add a 
new Keyword with the new text. It is not necessary that updating a keyword 
means you can update all the fields related to a keyword.

Thanks and regards,
Xiaoming, Google Ads API Team
ref:_00D1U1174p._5001UXVAp7:ref

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/3AvrZ0Q7COXB00r3mbq0odTzmBAXe8GfIc0g%40sfdc.net.


Re: How to use google ads api python to update keyword text value?

2020-03-16 Thread Rukeith Tseng
Hi David,
The ad type which I try to update is ExpandedTextAd

On Monday, 16 March 2020 19:29:22 UTC+8, David Wihl wrote:
>
> What type of ad are you trying to mutate? The list of ad types can be 
> found at: https://developers.google.com/google-ads/api/docs/ads/ad-types  
> The third column, Mutable, tells you whether you can mutate that specific 
> ad type. For example a TextAd is not mutable but a ExpandedTextAd is.
>
> -David
>
> On Sunday, March 15, 2020 at 11:30:30 PM UTC-4, Rukeith Tseng wrote:
>>
>> I am trying to update keyword text value via google ads api python sdk.
>> Here is my sample code
>>
>> import argparse
>> import sys
>>
>> from google.api_core import protobuf_helpers
>> from google.ads.google_ads.client import GoogleAdsClient
>> from google.ads.google_ads.util import ResourceName
>>
>>
>> def main(client, customer_id, ad_group_id, criterion_id):
>>agc_service = client.get_service('AdGroupCriterionService', version=
>> 'v3')
>>
>> ad_group_criterion_operation = client.get_type(
>> 'AdGroupCriterionOperation',
>>   version='v3')
>>
>> 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))
>>
>> // update here
>> ad_group_criterion.keyword.text.value = 'test-keyword'
>>
>>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)
>>
>>
>> if __name__ == '__main__':
>># GoogleAdsClient will read the google-ads.yaml configuration file in 
>> the
>># home directory if none is specified.
>>google_ads_client = GoogleAdsClient.load_from_storage()
>>parser = argparse.ArgumentParser(
>>description=('Pauses an ad in the specified customer\'s ad group.'
>> ))
>># The following argument(s) should be provided to run the example.
>>parser.add_argument('-c', '--customer_id', type=str,
>>required=True, help='The Google Ads customer ID.')
>>parser.add_argument('-a', '--ad_group_id', type=str,
>>required=True, help='The ad group ID.')
>>parser.add_argument('-k', '--criterion_id', type=str,
>>required=True, help='The criterion ID, or keyword 
>> ID.')
>>args = parser.parse_args()
>>
>> main(google_ads_client, args.customer_id, args.ad_group_id,
>> args.criterion_id)
>>
>>
>>
>> But I got an error like this:
>>
>> error_code {
>>request_error: IMMUTABLE_FIELD
>>  }
>>  message: "Field \'keyword.text\' cannot be modified by \'UPDATE\' 
>> operation."
>>  location {
>>field_path_elements {
>>  field_name: "operations"
>>  index {
>>  }
>>}
>>field_path_elements {
>>  field_name: "update"
>>}
>>field_path_elements {
>>  field_name: "keyword"
>>}
>>field_path_elements {
>>  field_name: "text"
>>}
>>  }
>> }
>> , 'OEhB_4KnhzMQaXAX0pvB2Q')
>>
>>
>>
>> I found that update expanded text ads will need to use AdService to 
>> update rather than AdGroupAdService.
>> Is that keyword need to use another service to update text value rather 
>> than AdGroupCriterionService?
>>
>>
>>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/c39a4c15-b676-451c-9d82-2ba902fbf6a6%40googlegro

RE: How to use google ads api python to update keyword text value?

2020-03-16 Thread Google Ads API Forum Advisor Prod
Hi Rukeith,

Thank you for reaching out. You encountered the issue as you tried to mutate 
the ad whose type is not mutable. Please refer to this guide on types of ads 
that are mutable. Please let me know if you have any further concerns.

Thanks and regards,
Xiaoming, Google Ads API Team
ref:_00D1U1174p._5001UXVAp7:ref

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/z2GWN0Q7AU9K00zXA9_3WJTvKWx-IMEITv6A%40sfdc.net.


Re: How to use google ads api python to update keyword text value?

2020-03-16 Thread 'David Wihl' via AdWords API and Google Ads API Forum
What type of ad are you trying to mutate? The list of ad types can be found 
at: https://developers.google.com/google-ads/api/docs/ads/ad-types  The 
third column, Mutable, tells you whether you can mutate that specific ad 
type. For example a TextAd is not mutable but a ExpandedTextAd is.

-David

On Sunday, March 15, 2020 at 11:30:30 PM UTC-4, Rukeith Tseng wrote:
>
> I am trying to update keyword text value via google ads api python sdk.
> Here is my sample code
>
> import argparse
> import sys
>
> from google.api_core import protobuf_helpers
> from google.ads.google_ads.client import GoogleAdsClient
> from google.ads.google_ads.util import ResourceName
>
>
> def main(client, customer_id, ad_group_id, criterion_id):
>agc_service = client.get_service('AdGroupCriterionService', version=
> 'v3')
>
> ad_group_criterion_operation = client.get_type(
> 'AdGroupCriterionOperation',
>   version='v3')
>
> 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))
>
> // update here
> ad_group_criterion.keyword.text.value = 'test-keyword'
>
>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)
>
>
> if __name__ == '__main__':
># GoogleAdsClient will read the google-ads.yaml configuration file in 
> the
># home directory if none is specified.
>google_ads_client = GoogleAdsClient.load_from_storage()
>parser = argparse.ArgumentParser(
>description=('Pauses an ad in the specified customer\'s ad group.'
> ))
># The following argument(s) should be provided to run the example.
>parser.add_argument('-c', '--customer_id', type=str,
>required=True, help='The Google Ads customer ID.')
>parser.add_argument('-a', '--ad_group_id', type=str,
>required=True, help='The ad group ID.')
>parser.add_argument('-k', '--criterion_id', type=str,
>required=True, help='The criterion ID, or keyword 
> ID.')
>args = parser.parse_args()
>
> main(google_ads_client, args.customer_id, args.ad_group_id,
> args.criterion_id)
>
>
>
> But I got an error like this:
>
> error_code {
>request_error: IMMUTABLE_FIELD
>  }
>  message: "Field \'keyword.text\' cannot be modified by \'UPDATE\' 
> operation."
>  location {
>field_path_elements {
>  field_name: "operations"
>  index {
>  }
>}
>field_path_elements {
>  field_name: "update"
>}
>field_path_elements {
>  field_name: "keyword"
>}
>field_path_elements {
>  field_name: "text"
>}
>  }
> }
> , 'OEhB_4KnhzMQaXAX0pvB2Q')
>
>
>
> I found that update expanded text ads will need to use AdService to update 
> rather than AdGroupAdService.
> Is that keyword need to use another service to update text value rather 
> than AdGroupCriterionService?
>
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/4720e2a9-b32a-48d2-be3d-3617783fd030%40googlegroups.com.


How to use google ads api python to update keyword text value?

2020-03-15 Thread Rukeith Tseng
I am trying to update keyword text value via google ads api python sdk.
Here is my sample code

import argparse
import sys

from google.api_core import protobuf_helpers
from google.ads.google_ads.client import GoogleAdsClient
from google.ads.google_ads.util import ResourceName


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

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

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))

// update here
ad_group_criterion.keyword.text.value = 'test-keyword'

   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)


if __name__ == '__main__':
   # GoogleAdsClient will read the google-ads.yaml configuration file in the
   # home directory if none is specified.
   google_ads_client = GoogleAdsClient.load_from_storage()
   parser = argparse.ArgumentParser(
   description=('Pauses an ad in the specified customer\'s ad group.'))
   # The following argument(s) should be provided to run the example.
   parser.add_argument('-c', '--customer_id', type=str,
   required=True, help='The Google Ads customer ID.')
   parser.add_argument('-a', '--ad_group_id', type=str,
   required=True, help='The ad group ID.')
   parser.add_argument('-k', '--criterion_id', type=str,
   required=True, help='The criterion ID, or keyword 
ID.')
   args = parser.parse_args()

main(google_ads_client, args.customer_id, args.ad_group_id,
args.criterion_id)



But I got an error like this:

error_code {
   request_error: IMMUTABLE_FIELD
 }
 message: "Field \'keyword.text\' cannot be modified by \'UPDATE\' 
operation."
 location {
   field_path_elements {
 field_name: "operations"
 index {
 }
   }
   field_path_elements {
 field_name: "update"
   }
   field_path_elements {
 field_name: "keyword"
   }
   field_path_elements {
 field_name: "text"
   }
 }
}
, 'OEhB_4KnhzMQaXAX0pvB2Q')



I found that update expanded text ads will need to use AdService to update 
rather than AdGroupAdService.
Is that keyword need to use another service to update text value rather 
than AdGroupCriterionService?


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/a160a664-be0a-46b4-9ab5-be262e765b89%40googlegroups.com.