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...

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.
scripts is not able to add products
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