Hi, I want Automatically stop the campaign when the daily budget is exceeded. I use the following code:
function main() { var allowedOverdeliveryPercentage = 0.1; // set percentage as decimal, i.e. 20% should be set as 0.2 var labelName = 'pause-campain'; AdWordsApp.createLabel(labelName, 'automatic label needed to reenable campaigns'); var campaigns = AdWordsApp.campaigns() .withCondition('Status = ENABLED') .withCondition('Cost > 0') .forDateRange('TODAY'); var campaignIterator = campaigns.get(); while (campaignIterator.hasNext()) { var campaign = campaignIterator.next(); var campaignName = campaign.getName(); var budgetAmount = campaign.getBudget().getAmount(); var costToday = campaign.getStatsFor('TODAY').getCost(); if(costToday > budgetAmount * (1 + allowedOverdeliveryPercentage)) { Logger.log(campaignName + ' has spent ' + costToday + ' which is more than allowed.'); campaign.applyLabel(labelName); campaign.pause(); } else { Logger.log(campaignName + ' has spent ' + costToday + ' and can continue to run.'); } } } ================= In the first time it seems to run fine, the time after that it shows the error occurred: "You are already using this label name" This error causes the ad campaign that exceeds the daily budget to be unpause and it still works If I change the label name, in the first run it works fine. From the next time it will show the above error What can I do to fix this? -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ 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 "Google Ads API and AdWords 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/fd86d532-fa81-4f18-b78e-adccb57fae7an%40googlegroups.com.