def main(client, customer_id, campaign_id):
campaign_service = client.get_service("CampaignService", version="v5")
# Create campaign operation.
campaign_operation = client.get_type("CampaignOperation", version="v5")
campaign = campaign_operation.update
campaign.resource_name = campaign_service.campaign_path(
customer_id, campaign_id
)
campaign.status = client.get_type("CampaignStatusEnum", version="v5").PAUSED
campaign.manual_cpc.enhanced_cpc_enabled = False
fm = protobuf_helpers.field_mask(None, campaign)
campaign_operation.update_mask.CopyFrom(fm)
# Update the campaign.
try:
campaign_response = campaign_service.mutate_campaigns(
customer_id, [campaign_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 campaign %s." % campaign_response.results[0].resource_name)