AdsApp.negativeKeywordLists() not adding to list

74 views
Skip to first unread message

Dennis Kreeft

unread,
Jun 7, 2023, 10:49:26 AM6/7/23
to Google Ads Scripts Forum
Hi, I have a script which is designed to fetch an array of keywords, and add them to an account level negatives list. 

The script runs fine, but doesn't actually make any changes to the shared list.

Snippet using a fixed string for keywords:

   if(account.getName() == 'XYZ'){
    var keywords = ["planes", "trains"]
    var list = AdsApp.negativeKeywordLists().withCondition("Name CONTAINS 'list_name'").get();
      while (list.hasNext()){
        var ex_list = list.next();
              ex_list.addNegativeKeywords(keywords);
   }
  }

Is this an issue with my script or the AdsApp.negativeKeywordLists()  ?

Thanks,
Dennis

Sigurd Fabrin

unread,
Jun 8, 2023, 7:02:56 AM6/8/23
to Google Ads Scripts Forum
Hi Dennis,

Try adding the keywords one by one

Like this:
    var listName = 'Some list';
    var newNegativeKeyWords = ['broad kw','"phrase kw"','[exact kw]'];
    var listIter = AdsApp.negativeKeywordLists()
      .withCondition('Name = "' +listName+ '"')
      .get();  
    if (listIter.totalNumEntities() == 0) { // list doesn't exist, create it and add keywords
    var createList = AdsApp.newNegativeKeywordListBuilder().withName(listName).build();
      if (createList.isSuccessful()) {
        var list = createList.getResult();  
        list.addNegativeKeywords(newNegativeKeyWords) // add array of keywords in one go as suggested in the documentation
      }
    }
    else { // list already exists, add keywords to it
      while (listIter.hasNext()) {
        var list = listIter.next();
        for (j in newNegativeKeyWords) {
        list.addNegativeKeyword(newNegativeKeyWords[j]) // add keywords one at a time - Cannot find this in the documentation
        }
      }
    }



Sigurd

Google Ads Scripts Forum Advisor

unread,
Jun 13, 2023, 4:06:43 AM6/13/23
to adwords...@googlegroups.com

Hello Dennis,

Thanks for reaching out to the Google Ads Scripts team.

It appears that I was able to make changes to a negative keyword list at the MCC level, as per my testing. Could you please try to run your script at the MCC level (without selecting/accessing any sub accounts) and see if that solves your issue? If the issue would persist, please provide us with the following information for us to investigate further:

  • Script Name
  • Google Ads account ID or CID
  • Screenshot of the Changes made by your script 
This message is in relation to case "ref:_00D1U1174p._5004Q2mARB1:ref"

Thanks,
 
Google Logo Google Ads Scripts Team


Reply all
Reply to author
Forward
0 new messages