How to clear array sub property "conversion_actions"

172 views
Skip to first unread message

Sergiy Kovalchuk

unread,
Dec 16, 2019, 3:26:58 PM12/16/19
to AdWords API and Google Ads API Forum
Hello,
I have a campaign with the following properties:

  "selectiveOptimization": {
    "conversionActions": [
      "customers/xxx/conversionActions/yyy"
    ]
  }

I am trying to clear the "conversionActions" list so it is either empty or completely absent from the properties, but not sure how it can be done. Can't find any examples in the python library.

Here is how it was added in the first place:
GA_CLIENT = GoogleAdsClient.load_from_storage('/path/')
api_service = GA_CLIENT.get_service('CampaignService', version='v2')
operation = GA_CLIENT.get_type('CampaignOperation', version='v2')

campaign_data = operation.update
campaign_data.resource_name = 'customers/xxx/campaigns/yyy'

conversion_actions = campaign_data.selective_optimization.conversion_actions.add()
conversion_actions.value = 'customers/xxx/conversionActions/yyy'

operation.update_mask.CopyFrom(protobuf_helpers.field_mask(None, operation.update))

api_service.mutate_campaigns('<account_id>', [operation])

I tried doing something like:
campaign_data.selective_optimization.conversion_actions.remove('customers/xxx/conversionActions/yyy')

But it says "Item to delete not in list".

Thank you.

Google Ads API Forum Advisor Prod

unread,
Dec 17, 2019, 2:55:56 PM12/17/19
to ser...@gmail.com, adwor...@googlegroups.com

Hi Serigy,

Thank you for reaching out. We are still looking into this and will get back to you shortly.

Regards,
Nikisha Patel, Google Ads API Team



ref:_00D1U1174p._5001UOEfuS:ref

Google Ads API Forum Advisor Prod

unread,
Dec 18, 2019, 12:20:55 PM12/18/19
to ser...@gmail.com, adwor...@googlegroups.com

Hi Sergiy,

Thank you for your patience. I was trying to remove the selective optimization field for the campaigns within my account and was successfully able to achieve that using mutate method of CampaignService via API. Please find below the code snippet used (in Java) to achieve this via API for your reference. Also, please refer to this code sample used to update the campaigns. You need to use the Field Mask in Python to specify the fields that you want to update via API and update the selective optimization with new empty value. This way you will be able to set the 'selective_optimization' field to blank by removing the old value while updating the campaign. Let us know if you need any additional information.

// Creates a Campaign object with the proper resource name and any other changes.

Campaign campaign = Campaign.newBuilder()
                                     .setResourceName(ResourceNames.campaign(customerId, campaignId))
                                     .setSelectiveOptimization(SelectiveOptimization.newBuilder().build())
                                     .build();
FieldMask fieldMask = FieldMask.newBuilder()
                                       .addPaths("selective_optimization.conversion_actions")
                                       .build();
CampaignOperation operation = CampaignOperation.newBuilder()
                                                     .setUpdate(campaign)
                                                     .setUpdateMask(fieldMask)
                                                     .build();



Regards,
Nikisha Patel, Google Ads API Team



ref:_00D1U1174p._5001UOEfuS:ref

Sergiy Kovalchuk

unread,
Dec 18, 2019, 1:02:50 PM12/18/19
to AdWords API and Google Ads API Forum
Hello,
Thank you, it worked. Here is the corresponding python version if anyone is interested:

GA_CLIENT = GoogleAdsClient.load_from_storage('/path/')
api_service = GA_CLIENT.get_service('CampaignService', version='v2')
operation = GA_CLIENT.get_type('CampaignOperation', version='v2')

campaign_data = operation.update
campaign_data.resource_name = 'customers/xxx/campaigns/yyy'

operation.update_mask.CopyFrom(protobuf_helpers.field_mask(None, operation.update))

operation.update_mask.paths.append('selective_optimization.conversion_actions')

api_service.mutate_campaigns('<account_id>', [operation])
Reply all
Reply to author
Forward
0 new messages