Merging data into one bundle

hello

This has turned out to be trickier and more complex than I thought, so I come here searching for your advice and suggetsions. Thanks much in advance, mates.

I have this input from a Custom API:

[
{
    "cve_art": "BUNDLE-00012",
    "cve_prod": "PRODUCT-200318",
    "porcen": 0,
    "cantidad": 1
},
{
    "cve_art": "BUNDLE-00012",
    "cve_prod": "PRODUCT-200204",
    "porcen": 0,
    "cantidad": 1
},
{
    "cve_art": "BUNDLE-00017",
    "cve_prod": "PRODUCT-PSA331",
    "porcen": 0,
    "cantidad": 1
},
{
    "cve_art": "BUNDLE-00017",
    "cve_prod": "PRODUCT-GMA553",
    "porcen": 0,
    "cantidad": 1
},
{
    "cve_art": "BUNDLE-00016",
    "cve_prod": "PRODUCT-PSA331",
    "porcen": 0,
    "cantidad": 1
},
{
    "cve_art": "BUNDLE-00016",
    "cve_prod": "PRODUCT-PSA331",
    "porcen": 0,
    "cantidad": 1
},
{
    "cve_art": "BUNDLE-00016",
    "cve_prod": "PRODUCT-PSA556",
    "porcen": 0,
    "cantidad": 5
}
]

Context:

The cve_art refers the sku of a bundle, or a group of products sold together.
The cve_prod refers to the sku of a unique product included in the bundle
The value in “cantidad” means “quantity”. The amount of such SKU that should be included in the bundle. Some bundles have 2 different items and others have 3 or more.

Now what I want to do is consolidate this data , one per each bundle sku.
For example :

"cve_art": "BUNDLE-00016",
"cve_prod1": "PRODUCT-PSA331",
 "cantidad1": 1
"cve_prod2": "PRODUCT-PSA331",
"cantidad2": 1
"cve_prod3": "PRODUCT-PSA556",
"cantidad3": 5

so I can query now the products in stock and see how many bundles I can make up.

I am trying to achieve this with the Merge node, or the itemLists node, but been unsuccesful.
Do you have any ideas on how to achieve this?
Thanks in advance.

Hey @th3liam, I think this would require a bit of custom code from the looks of it because you’re looking to create properties (like cve_prod1) that don’t exist yet and which will have different names depending on the number of items you have.

I’ll try to have a go at this today.

1 Like

Here’s a function that should output what you need:

2 Likes