Get Started With Microsoft Advertising Scripts

Accessing your Microsoft Advertising data with Scripts is easy. Just follow these instructions and you'll be accessing your data in no time.

  1. Sign in to Microsoft Advertising or Microsoft Advertising Sandbox.

  2. From the global menu at the top of the page, select Tools > Scripts.

  3. Select Create script.

  4. Replace "Untitled script" with your script's name.

  5. Copy and paste the following code into the code editor. This script gets the 15 keywords that generated the least impressions over the last week. This script won't make any changes to your campaign data.

    function main() {
        var iterator = AdsApp.keywords()
            .orderBy("Impressions ASC")
            .withLimit(15)  // up to 15
        Logger.log("15 keywords with the least impressions over the last week");
        while (iterator.hasNext()) {
            var keyword =;
                ${keyword.getStats().getImpressions()} impressions`);  //writes the number of impressions
  6. To execute the script in preview mode (recommended), select Preview.

  7. To see the output after the script or preview has run, select Logs.

The difference between Preview and Run script now is that preview gives you the chance to see how the script would affect your data without actually committing the changes. If the script modifies data, you should run it in preview mode first. For limitations of preview mode, see Running scripts in Preview mode.

For multi-account scripts, access the Scripts editor from a manager account. To get an account that you manage, use the AccountsApp object. After getting the managed account, use the AdsApp object to access its entities. Read more.

Next steps