How can I automate my campaigns with Microsoft Advertising Scripts?

Learn how to automate your account and campaigns with Microsoft Advertising Scripts.

Microsoft Advertising Scripts are pieces of JavaScript code you can use to automatically create, change, or delete items in your account based on custom criteria. You can make hundreds (or thousands!) of changes across your account all at once without needing to make the changes manually.

Here are some examples of using scripts:

  • Schedule campaigns linked to a launch or sale.
  • Have an ad pause automatically when the item it's advertising is out of stock.
  • Make a rule across your account to increase broad match keyword bids by 25% for keywords that generated more than 100 impressions that day.

Using Microsoft Advertising Scripts

Who should use scripts? expando image

Scripts are most helpful for people who manage large campaigns and/or a large number of campaigns. It also helps to have some experience scripting in JavaScript.

It's important to keep in mind that Microsoft Advertising Scripts can make wide-ranging changes to your campaigns and that scripts do not have an "Undo" button. If you find this prospect daunting, then automated rules might be more suitable for you.

Create and run Microsoft Advertising Scripts expando image
  1. From the top menu, select Tools > Scripts.

    If you're using the new Microsoft Advertising navigation, from the navigation menu on the left, select Tools > Bulk actions > Scripts.

    This is the main Scripts page where you will see any scripts you have already created.

  2. Select Create script.
  3. In the script editor, enter in your script.
    1. To see examples of scripts that you can copy, select Examples.
    2. For instructions on scripting, take a look at our Scripts documentation and for more scripts you can copy, check out our scripts code examples.
  4. Select Save.
  5. Select Preview to see a list of all the changes this script will make. Previewing a script is optional, but strongly recommended.
  6. If you want to run the script right away, select Run script now.
  7. If you want to run the script at a certain time or multiple specific times, select Create schedule.
  • If you have multiple accounts and want to run a script across all of them, you'll need to create the script from your manager account. From the top menu, select your account number and then select a manager account (not an ad account). Move through the same steps above and your script will run across all accounts.
  • If you share accounts with other account managers, be aware that only the author of a script will be able to see and run that script.
Manage your scripts expando image

After you run a script, it will appear under Script on the main Scripts page (

From the top menu, select Tools > Scripts.

If you're using the new Microsoft Advertising navigation, from the navigation menu on the left, select Tools > Bulk actions > Scripts.

) Here, you will see when the script ran, how long it took to run, how many changes were made, and how many changes failed. For more information on what the script did:
  1. Select Scripts History > Summary > View details.
  2. In the Log details page, you'll see all the changes the script made.
  3. To see how the script made these changes, as well as any errors encountered and log messages you included with the script, select Logs.

To run a script you have already created:

  1. Find the script in your list of previously-created scripts on the main Scripts page.
  2. Select Run or select Create schedule to have the script run at a certain time or at multiple specific times.
Can I use the scripts that I created in Google Ads? expando image
You can drag any script you created in Google into Microsoft Advertising. When you select Save, we will automatically make some changes to make them compatible with Microsoft Advertising. However, you will need to update the script manually to fix any of the following compatibility issues:
  • If the script calls the budget selector, it returns only shared budgets. To get a campaign's individual budget, you must access it directly from the campaign.
  • If the script includes IDs, you’ll need to turn them into strings by wrapping them in double quotation marks. For example, you’ll need to change .withIds([1234]) to .withIds("1234"]).
  • If the script calls an entity's getStatsFor() method, you’ll need to change the call to getStats() and specify the date range using the selector's forDateRange() method.
  • If the script calls the keyword selector's withIds() method, make sure you pass only an array of keyword IDs. In Microsoft Advertising, keyword IDs are unique, so there’s no need to pass an array of ad group ID and keyword ID pairs.

If the script adds negative keywords with broad match type, Microsoft Advertising converts them to phrase match type when adding them to the account. Microsoft Advertising doesn't support broad match type for negative keywords.

For more information

Visit our documentation site for details on scripting:

See more videos...