Search code examples
javascriptgoogle-ads-apiaccount

"AdwordsApp" is not defined


As the title says I'm getting the error "AdwordsApp" is not defined when running my Adwords Script. I'm new to Adwords Script and can't figure out what's wrong. I'm running the script in a single account but this account is in a MCC-account. Can that be the reason?

My code looks like this:

var spreadUrl = "xxxxxxx"

function main(){
    var total = 0;

    var campaignSelector = AdwordsApp.campaigns()
        .forDateRange("LAST_MONTH");

    var campaignIterator = campaignSelector.get();

    while(campaignIterator.hasNext()) {
        var campaign = campaignIterator.next();
        var budget = campaign.adGroups.getBudget();
        var budgetAmount = budget.getAmount();
        total += budgetAmount;
    }
}

The code is far from ready...

Thanks


Solution

  • Looking at the AdWords Script docs found here, I think the issue is on the following line of code.

    var campaignSelector = AdwordsApp.campaigns()
    

    AdwordsApp should be AdWordsApp, note the casing of the w. Changing that line of code so that it reads:

    var campaignSelector = AdWordsApp.campaigns()
    

    should fix your problem.