I'm getting to Google Ads scripts. I managed to execute this script that pauses a specific campaign but I couldn't apply this to multiple campaigns. Here is what I tried, but it only pauses the first campaign in ("Name IN ['test1', 'test2']"). Could someone help me to achieve this?

function main () {   var campaignIterator = AdsApp.campaigns()     .withCondition("Name IN ['test1', 'test2']").get();   if (campaignIterator.hasNext()) {     var campaign = campaignIterator.next();     campaign.pause();   } }

Tag:google-ads-api, javascript, google-apps-script

Only one comment.

  1. aindriu

    You just need to change from if to while as in the example below to iterate through all campaigns.

    function main () { var campaignIterator = AdsApp.campaigns() .withCondition("Name IN ['test1', 'test2']").get(); while (campaignIterator.hasNext()) { var campaign = campaignIterator.next(); campaign.pause(); } }Run code snippet

    Hide resultsExpand snippet

Add a new comment.