Please post an exemple script for adding products

118 views
Skip to first unread message

Allaire Jean-Francois

unread,
Sep 18, 2019, 12:04:07 PM9/18/19
to Google Ads Scripts Forum

I always get the following errors when adding products, but they are not consistent. Some products generate the errors but some don`t. Even though they all go through the same loop...


errors.png


I'm guessing one step or structure is obvious to you guys and I'm not doing the right thing about it...


If someone could please post a sample script that uses product groups organised by product types. Here's an example of what I mean:


All Products > Shoes > Sport Shoes > Basketball shoes


So


a) how to create the product groups (as shown above)

b) add products (pretend you have ~ two hundreds products to add)


I know you guys mean well when you ask to take a look, but my script is very long and complicated and you always end up telling me to read the documentation instead. Which, at least to me, is not helpful. Because I truly believe, I'm doing everything "by the book" (obviously, it must not be the case).


I'm pretty sure it will help a lot of people...


Thanks in advance.



Google Ads Scripts Forum Advisor

unread,
Sep 18, 2019, 3:40:00 PM9/18/19
to adwords-scripts+apn2wqf5r1cw-4uk...@googlegroups.com, adwords-scripts+apn2wqf5r1cw-4uk...@googlegroups.co, adwords...@googlegroups.com
Hi Allaire,

While scripts is not able to add products (it can add product ads, not products), it can create a product group hierarchy. Please see the sample script below regarding your first need:

  var shoppingAdGroup = AdsApp.shoppingAdGroups().withCondition("CampaignName CONTAINS 'SAMPLE_CAMPAIGN'").withCondition("Name CONTAINS 'SAMPLE_ADGROUP'").get();
  
  if(shoppingAdGroup.hasNext()) {
  
    var adGroup = shoppingAdGroup.next();    
    var rootProductGroup = adGroup.rootProductGroup();
    
    //Build hierarchy: All Products > Shoes > Sport Shoes > Basketball shoes, all values are samples
    var shoesGroup = rootProductGroup.newChild().productTypeBuilder().withBid(1).withValue('Shoes').build().getResult();
    var sportsShoesGroup = shoesGroup.newChild().productTypeBuilder().withBid(1).withValue('Shoes > Sports').build().getResult();
    var basketballShoesGroup = sportsShoesGroup.newChild().productTypeBuilder().withBid(1).withValue('Shoes > Sports > Basketball').build().getResult();  
  }

There is a similar sample in the docs as well. 

Regards,
Matt 
Google Ads Scripts Team

ref:_00D1U1174p._5001UHHE4g:ref

Allaire Jean-Francois

unread,
Sep 18, 2019, 3:54:33 PM9/18/19
to Google Ads Scripts Forum
Hello Matt and thank you for your answer!

scripts is not able to add products
 
So what does the itemIdBuilder do then?

Because I am spending an awful lot of time making sure its parent is a product type and then adding these itemIds...

Also, how come the result is that my Product Ads are shown and clicked on?

One final question, what is the benefit of obtaining a list of products from merchant center if we are not supposed to be able to add them to our Campaigns?

Google Ads Scripts Forum Advisor

unread,
Sep 18, 2019, 5:37:53 PM9/18/19
to adwords-scripts+apn2wqf5r1cw-4uk...@googlegroups.com, adwords-scripts+apn2wqf5r1cw-4uk...@googlegroups.co, adwords...@googlegroups.com
Hi Allaire,

The item ID builder creates an item ID, but not the product itself. Using the item ID builder will create a new subdivision, which is what the other product builder spaces will do. Products need to be added in the merchant center. Can you please clarify your last two questions:
  • Also, how come the result is that my Product Ads are shown and clicked on?
  • One final question, what is the benefit of obtaining a list of products from merchant center if we are not supposed to be able to add them to our Campaigns?

Allaire Jean-Francois

unread,
Sep 19, 2019, 7:33:25 AM9/19/19
to Google Ads Scripts Forum
Thank you again,

All in all, what I would very much like to know is if there something that is required before using the item Id builder. Because it feels like every time I get errors it's during that operation (though not every use of it generate errors)...

Google Ads Scripts Forum Advisor

unread,
Sep 19, 2019, 2:29:40 PM9/19/19
to adwords-scripts+apn2wqf5r1cw-4uk...@googlegroups.com, adwords-scripts+apn2wqf5r1cw-4uk...@googlegroups.co, adwords...@googlegroups.com
Hi Allaire,

If that subdivision already exists, then you will get an error, 'product partition already exists'. For example, if you run the below script twice in a row, you will get that same error:

function main() {
  var shoppingAdGroup = AdsApp.shoppingAdGroups().withCondition("CampaignName CONTAINS 'test campaign'").withCondition("Name CONTAINS 'test ag'").get();
  
  if(shoppingAdGroup.hasNext()) {
    var ag = shoppingAdGroup.next();
    Logger.log(ag.getName());
    
    if(ag.rootProductGroup()) {
      var root = ag.rootProductGroup();
      var newItemId = root.newChild().itemIdBuilder().withBid(.5).withValue('SKU12345').build().getResult(); // item ID builder called with the same value twice

Allaire Jean-Francois

unread,
Oct 8, 2019, 3:15:20 PM10/8/19
to Google Ads Scripts Forum
Ok so what can cause these errors?

productBuilder / processOp: RPM Rive-Sud: Operation failed for 133136

productBuilder / 000 processOp / errors / 133136: PRODUCT_PARTITION_DOES_NOT_EXIST : AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST : criterion.parentCriterionId


In your exemple, you are building item ids straight from the root product group, I'm guessing I can build intermediate product groups and then build item ids from the last one (last product group)...

But then what is a parentCriterion? and what do product partitions correspond to?

I'm sorry for my lack of enthusiasm, but the only thing as complicated as your structures is getting help about it

Allaire Jean-Francois

unread,
Oct 8, 2019, 3:54:04 PM10/8/19
to Google Ads Scripts Forum
Completely OFF the Adwords Scripts help site, (again...  How are we to know...)

I found this:

==============================================

Criteria are not assigned IDs until the mutate request that creates them is processed by the server. However, a ProductPartition is invalid until it is complete, so whenever you create a subdivision you must also create at least one of its children in the same operation.

To allow you to set the parentCriterionId for the child nodes, you can use temporary criterion IDs. These are locally unique (rather than globally unique) identifiers that apply only within the context of a single mutate request. Any negative integer can be used as a temporary ID. In the sample code above, the ID of the root ProductPartition is set to -1.

When the request is processed, each Criterion is assigned a positive global ID as usual.

==============================================


I'm guessing it has something to do with my problem...


More likely than me calling the same function twice with hard coded values

Google Ads Scripts Forum Advisor

unread,
Oct 9, 2019, 5:45:05 AM10/9/19
to adwords...@googlegroups.com
Hi Allaire,

My apologies for the inconvenience and back and forth.

I am a colleague of Matt and let me continue to provide support to your issue.

So that I can investigate the cause of error below, could you provide the customer ID and the name of the script where you encountered this error via Reply privately to author option? Also, if your script is using spreadsheet, please provide access to it so I can check it as well.

productBuilder / 000 processOp / errors / 133136: PRODUCT_PARTITION_DOES_NOT_EXIST : AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST : criterion.parentCriterionId

Regards,
Ejay

Google Ads Scripts Team

ref:_00D1U1174p._5001UKMcq3:ref

Allaire Jean-Francois

unread,
Oct 9, 2019, 8:25:13 AM10/9/19
to Google Ads Scripts Forum
Thank you Ejay

Look, been there, done that... This script is pretty complicated... awfully long because, among other things, I have to double check every single assumption about the structure. It seems no matter what one does, The $%??$/"/$% partition problems are there to stay.

Because the script is long, the last person who requested "THE ID" ended up referring me to the Ads Script Help site home page. (email available)

Please take the time to read and understand the following

Here is my structure: (example, fake types)

Shopping Campaign (Shoes)
    Ad Group
        Root Product Group
            Product Type Level 1 (home)
                Product Type Level 2 (shoes)
                    Product Type Level 3 (sports shoes)
                        Product Type Level 4 (tennis shoes)
                            Product Item Id X (product)
                            Product Item Id Y (product)
                            Product Item Id Z (product)

I'm trying to add my products from the last Product Type (tennis shoes in the example). Before I do so, I check (and double check) that the entity I'm using is effectively a product group that is used as a product type. (So where do the /$%"/ partition problems come from???)

Then as suggested by the Ads Script help site. I build all the products (item Ids) and put them aside in an array. When this is done I go through the array and "get results"... what bugs me is that these problems only happen when I run my script for the first time after I just built the structure (up to the last product group, tennis shoes). Then if I run my script again a second time, without changing anything, everything runs fine... well, very high % (99) of the times...

For the record: the rest of the times, my algorithm for adding and removing item ids (based on if they are present in the last product group) IS WORKING FINE. I want to make it clear, I'm not trying to remove products (item ids) that are not there are add products (item ids) that are already there. So pretty please, stop assuming that this what is happening here...

I would just like it very much, if this notion of criterion.parentCriterionId or product partition could be clearly explained once and for all... what IS the relationship between the tools we can use (product groups as product types etc) and product partitions? We only hear about that monster in error logs!!!

I truly believe the extract from the Google Ads API is accurate (my previous post in this conversation)... How come this is not documented on the Ads script web site? (for the ads script context) How are we suppose to work around that?

Google Ads Scripts Forum Advisor

unread,
Oct 17, 2019, 6:03:13 AM10/17/19
to adwords...@googlegroups.com
Hi Allaire,

My apologies for the delayed response as I discussed your issue with my team.

The PRODUCT_PARTITION_DOES_NOT_EXIST error usually encountered when you are referencing product partition that is not existing in your ad group. So, in order to investigate the error and to address it, we really need your customer ID and the name of the script via Reply privately to author option. If the script is using Google spreadsheet, please provide access as well.

Also, with regard to this one "In your exemple, you are building item ids straight from the root product group, I'm guessing I can build intermediate product groups and then build item ids from the last one (last product group)...
But then what is a parentCriterion? and what do product partitions correspond to
?".

For Google Ads Scripts, a lot of the complexity that is exposed in the AdWords API is hidden. So as an example, given a hierarchy like:
Root
> Product Type Level 1 (shoes)
> Other

If you are getting a hold of the product group "Product Type Level 1" and wants to add a child (via productGroup.newChild().itemIdBuilder().withValue('some id').withBid(1.23).build()), then scripts will automatically issue 4 operations:
1. Delete "Product Type Level 1 (shoes)" (because it is currently a UNIT and not a SUBDIVISION so it cannot have children)
2. Add "Product Type Level 1 (shoes)" (this time as a SUBDIVISION)
3. Add "Product Item Id (some id)" (as a UNIT with a bid of $1.23)
4. Add an "Other" product group at the same level as the product item id.

So the end result is:
Root
> Product Type Level 1 (shoes)
>> Product Item Id (some id)
>> Other
> Other

Things like parentCriterionId and caseValue are set under the covers by the Google Ads Scripts infrastructure. This mimics what the UI does (i.e. you don't have to change a product group from UNIT -> SUBDIVISION in order to add a child product group, they just select the parent product group and then fill out details for the child).

In general, I would suggest to build all the products (item Ids) and put them aside in an array. When this is done, go through the array and try calling 'getResult()' after each product group is built.
Reply all
Reply to author
Forward
0 new messages