Keyword IDs Error - Each id must be a 2-element array.

341 views
Skip to first unread message

Jae Han

unread,
Nov 21, 2016, 12:36:11 PM11/21/16
to AdWords Scripts Forum
Hello,


I am not sure why I am receiving this error, and I have been checking my logs to ensure that I am using nested arrays (i.e. [[123456, 34567]]) but I am still getting this error: 
Each id must be a 2-element array. (line 22)
Log:
adgroups finished loading into adgroupIDs array
accessing all keywords and putting in bids js object as bids [ keyword ] = [cpc, adgroupname]
[[27xxxx3, 510xxx75], [2718xxx4493, 4369xx753], [2718xxxx4613, 9863xxx44], [27xxxx733, 169xx619], [27xxxx14853, 43xx042], ... [27xxxx293, 751xxxxx39]]
Each id must be a 2-element array. (line 22)


I added Xs to protect privacy.

Anybody know why I am still receiving these errors?


var kwIterator = AdWordsApp.keywords().withCondition("LabelNames CONTAINS_ALL ['Some LABEL']").get();
  
  while (kwIterator.hasNext()){
   var kw = kwIterator.next();
   var kwag=kw.getAdGroup().getId();
   kwIDs.push([ + kwag + ', ' + kw.getId()]);
  };
  
var keywords = AdWordsApp.keywords().withIds(kwIDs).get();
  
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    // Store their bidding info in a JS object.
    bids[keyword.getText()] = [keyword.bidding().getCpc(), keyword.getId()];
  }


Thanks as always,
J

Tyler Sidell (AdWords Scripts Team)

unread,
Nov 21, 2016, 4:41:12 PM11/21/16
to AdWords Scripts Forum
Hi Jae,

Thanks for providing your code.  There is an issue in your code where you are setting the comma as a string thus is not returning a 2 dimensional array. The code kwIDs.push([ + kwag + ', ' + kw.getId()]); is converting each item to a string so each item that is getting added is actually one item.  You would need to modify your script as follows:

function main() {
var kwIDs = [];

var kwIterator = AdWordsApp.keywords().withCondition("LabelNames CONTAINS_ALL ['Some LABEL']").get();
 
 
while (kwIterator.hasNext()){
   
var kw = kwIterator.next();
   
var kwag=kw.getAdGroup().getId();

   kwIDs
.push([kwag,kw.getId()]);
 
};
Logger.log(kwIDs);  
var keywords = AdWordsApp.keywords().withIds(kwIDs).get();

while (keywords.hasNext()) {
   
var keyword = keywords.next();
   
// Store their bidding info in a JS object.
    bids
[keyword.getText()] = [keyword.bidding().getCpc(), keyword.getId()];
 
}
}

Regards,
Tyler Sidell
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages