Can't loop post product array to woocommerce REST API

Hello everyone !
I am new to postman and api creations in general , and i have a problem that i cannot find a solution , so i posted this topic!

I am trying to make a collection that gets products from a woocommerce shop via its REST API and then posts them to a different site. So i get the products , save the response to a string , map through the JSON and take the stuff i need into variables and then when i try to loop and use the shift function to remove the first item from the array so it posts a different product . My problem is that when i loop , it creates the first product and then it tries to post the same product instead of shifting to the next , i havent created the if statement that checks if the arrays are empty . i just wanted to create the 5 products that i get , and then run out of data to see how to stop the loop here are some screenshots :



(i have more screenshots but i cant embed them because i am a new member :slight_smile: )

i dont know what i am doing wrong , i have seen some videos and followed some documentations and forum topics but i still cant find what i am doing wrong , Thanks again in advance!!

Hi @idunited

I think for your .shift to work you would need it inside a for each so it can work its way through the array.

Example;

let fruits = ["Banana", "Orange", "Apple", "Mango"];
console.log(fruits);

for (let i = 0; i < fruits.length + 3; i++){
  console.log(fruits.length);
  console.log(fruits.shift());
}

Not sure why the condition needed the β€˜+ 3’ but I played with it in JSFiddle and that’s what worked …