2) Is there something wrong with the documentation on (CampaignCriterionStatusEnum and CampaignCriterion resource) as the following commands do not work (i.e. CampaignCriterionStatusEnum does not seem to exist and the CampaignCriterion resource does not have a status field as cited in the Google Ads API documentation:
criterion_status_enum = client.get_type('CampaignCriterionStatusEnum', version='v1')
op_c.status = getattr(criterion_status_enum, 'PAUSED')
Any advice/feedback on these issues would be greatly appreciated. Thanks!
Logging Output
Response
-------
Headers: {
"google.ads.googleads.v1.errors.googleadsfailure-bin": "\n^\n\u0002\b\u0005\u0012FMutate operations must have 'create', 'update', or 'remove' specified.\"\u0010\u0012\u000e\n\noperations\u0012\u0000",
"grpc-status-details-bin": "\b\u0003\u0012%Request contains an invalid argument.\u001a\u0001\nCtype.googleapis.com/google.ads.googleads.v1.errors.GoogleAdsFailure\u0012`\n^\n\u0002\b\u0005\u0012FMutate operations must have 'create', 'update', or 'remove' specified.\"\u0010\u0012\u000e\n\noperations\u0012\u0000",
"request-id": "WlST6n-W6Xb6ns6DiJR2Iw"
}
Fault: {
"errors": [
{
"errorCode": {
"requestError": "OPERATION_REQUIRED"
},
"message": "Mutate operations must have 'create', 'update', or 'remove' specified.",
"location": {
"fieldPathElements": [
{
"fieldName": "operations",
"index": "0"
}
]
}
}
]
}
def campaign_criterion_service(customer_id, campaign_id, params):
"""Function to add/create modifiers (location, device etc.) for a given campaign."""
logging.basicConfig(level=logging.INFO, format='[%(asctime)s - %(levelname)s] %(message).5000s')
logging.getLogger('./google.ads.google_ads.client').setLevel(logging.INFO)
client = google.ads.google_ads.client.GoogleAdsClient.load_from_storage()
op_c = client.get_type('CampaignCriterionOperation', version='v1').create
op_c.campaign.value = client.get_service('CampaignService', version='v1').campaign_path(customer_id, campaign_id)
criterion_type_enum = client.get_type('CriterionTypeEnum', version='v1')
# NOTE: Two following lines error out where enum does not exist and status is not part of CampaignCriterion
#criterion_status_enum = client.get_type('CampaignCriterionStatusEnum' , version='v1')
#op_c.status = getattr(criterion_status_enum, 'PAUSED')
op_c.type = getattr(criterion_type_enum, params['criterion_type'].upper())
if params['criterion_type'] == 'device':
device_enum = client.get_type('DeviceEnum', version='v1')
op_c.criterion_id.value = getattr(device_enum, params['device_type'].upper())
op_c.criterion.negative = False
try:
response = client.get_service('CampaignCriterionService', version='v1').mutate_campaign_criteria(customer_id, [client.get_type('CampaignCriterionOperation', version='v1')])
except google.ads.google_ads.errors.GoogleAdsException as ex:
error_statement(ex)
print('Created %s bid modifier: %s.'
% (name, response.results[0].resource_name))