# Can't loop post product array to woocommerce REST API

**URL:** <https://community.postman.com/t/cant-loop-post-product-array-to-woocommerce-rest-api/33809>\
**Category:** Help Hub\
**Created:** [March 24, 2022, 8:54am UTC](https://community.postman.com/t/cant-loop-post-product-array-to-woocommerce-rest-api/33809 "2022-03-24T08:54:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![idunited](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@idunited](https://community.postman.com/u/idunited)\
**Post date:** [March 24, 2022, 8:54am UTC](https://community.postman.com/t/cant-loop-post-product-array-to-woocommerce-rest-api/33809/1 "2022-03-24T08:54:03Z")

</div>

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 :

 ![1648035979689blob](https://us1.discourse-cdn.com/getpostman/original/2X/3/304a2da751f0ae679ba6f939e13a53de87acfb22.png)  
 ![1648036619070blob](https://us1.discourse-cdn.com/getpostman/original/2X/1/1ae4e829b2fbb3bb8e4469b192643ae10271c9a2.png)  
 ![1648036928483blob](https://us1.discourse-cdn.com/getpostman/original/3X/f/e/fe1f65706d84443443edf62a523578e55b1c874a.png)

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

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

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [April 2, 2022, 7:02pm UTC](https://community.postman.com/t/cant-loop-post-product-array-to-woocommerce-rest-api/33809/2 "2022-04-02T19:02:42Z")

</div>

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;

```auto
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 …
