Content API for Shopping product limit?

401 views
Skip to first unread message

Roy Steves

unread,
May 26, 2016, 2:14:41 PM5/26/16
to AdWords Scripts Forum
As per another thread, I finally got my connection to the Merchant Center data working with this:
 
 
var products = ShoppingContent.Products.list(123456789);
 
if (products.resources) {
   
Logger.log("Found " + products.resources.length + " products");  
 
}

I've verified that this Merchant Center ID is correct, and the products returned here are totally correct--except there are only 25 of them, when I know there are actually almost two million products active in this Merchant Center, and in the associated Shopping Campaign.



Considering this is a combination of Scripts, the Content API, and Merchant Center, I don't even know who to ask--can you help point me in the right direction again?  I'm sooo close to getting this working!  :)

Roy Steves

unread,
May 26, 2016, 2:23:16 PM5/26/16
to AdWords Scripts Forum
Found it!

While the documentation of the Scripts interface to the API is... well, I couldn't find any, I did figure out that the API has a maxResults option:

That worked, so I poked around at the Scripts editor, and it revealed that there was a version of the list() function that accepted optional arguments struct.  Hoping for the best, I tried:

  var products = ShoppingContent.Products.list(merchantId, {maxResults:100});

And it worked!  We'll see if it will put up with the kind of abuse I'm about to try with that 1.9MM list, but at least I'm on my way.

Alexander Wang

unread,
May 26, 2016, 2:25:35 PM5/26/16
to AdWords Scripts Forum
Hey Roy,

I think the API is just returning the first 25 products. I think if it sent you 2M products in a single response something would blow up :). The response should have a page token that you can use to fetch the next page of products. Also, I think you can specify the page size by setting "maxResults":

I haven't tested this, but try something like:
// Fetch initial page
var products = ShoppingContent.Products.list(123456789, {maxResults:100});
// Keep fetching things if there are more products
while (products.resources && products.resources.length > 0) {
 
// Iterate over the current page of products
 
for (var i = 0; i < products.resources; i++) {
   
var product = products.resources[i];
   
...
 
}
 
// Fetch the next page of products
 
var nextPage = products.nextPageToken;
  products
= ShoppingContent.Products.list(123456789, {nextPageToken: nextPage, maxResults:100});
}

Cheers,
Alex

On Thursday, May 26, 2016 at 11:14:41 AM UTC-7, Roy Steves wrote:

Roy Steves

unread,
May 26, 2016, 2:27:36 PM5/26/16
to AdWords Scripts Forum
Great point!  If the API parameters are valid from this call, then I can totally use the pagination by passing both into the options.

This is so much fun.  :)

Roy Steves

unread,
May 26, 2016, 2:29:00 PM5/26/16
to AdWords Scripts Forum
Yep, and the highest allowed value for maxResults is 250, according to the error I just got thrown.  ;)
Reply all
Reply to author
Forward
0 new messages