function main() { // Get all the accounts var accountIterator = AccountsApp.accounts().get(); // Iterate through all the accounts in the results while (accountIterator.hasNext()) { // Get one of the accounts from the list of all accounts var account = accountIterator.next(); // Select the account to update AccountsApp.select(account); // Retrieve all the keywords that have greater than 2% conversion last week // and are in Ad group with names that contain 'sale' var keywordIterator = BingAdsApp.keywords() .withCondition("AdGroupName CONTAINS_IGNORE_CASE 'sale'") .withCondition("ClickConversionRate > 2") .forDateRange("LAST_WEEK") .get(); // Iterate through all ads in the results while (keywordIterator.hasNext()){ var keyword = keywordIterator.next(); // Get current bid var currentBid = keyword.bidding().getCpc(); // Set new bid with 5% increment keyword.bidding().setCpc(currentBid * 1.05); } // Retrieve all the keywords that have less than or equal to 2% conversion last week // and are in Ad group with names that contain 'sale' var keywordIterator = BingAdsApp.keywords() .withCondition("AdGroupName CONTAINS_IGNORE_CASE 'sale'") .withCondition("ClickConversionRate <= 2") .forDateRange("LAST_WEEK") .get(); // Iterate through all ads in the results while (keywordIterator.hasNext()){ var keyword = keywordIterator.next(); // Get current bid var currentBid = keyword.bidding().getCpc(); // Set new bid with 5% decrement keyword.bidding().setCpc(currentBid * 0.95); } } }