Skip to main content

Hi, I want to do looping of Webhook Array.

 

I read below article also but it is not working for me.

 

I am getting response like below from Webhook Output

 

items
1
status_id
ALLR
id
15
sku
hsbd3trek2
unit
D
name
Down Sleeping Bag Hire I 3 Season Warmth S2S I 500 Fill
start_date
1606309200
end_date
1606654800
qty
2
category_id
6
taxes
0
id
1
name
GST
type
percent
amount
6.27
tax_total
0.00
tax_inc_total
6.27
item_total
69.00
sub_total
69.00
total
69.00
summary
<strong title='Qty - billing'>Qty - billing:</strong> 2 x 1 Day @ $30.00
2 x 1 Day @ $4.50 <em>(Additional days)</em>
2 x 2 Days <em>(Free first and last days)</em>
event
0
3
1
4
2
5
param
qty
qty
2
name
Qty - billing
discount
amount
0.00
2
status_id
ALLR
id
117
sku
hpackprogrammslim
unit
D
name
Program Nylon Hiking Pack Hire I S - M slim harness
start_date
1606309200
end_date
1606654800
qty
2
category_id
4
taxes
0
id
1
name
GST
type
percent
amount
5.44
tax_total
0.00
tax_inc_total
5.44
item_total
29.90
sub_total
59.80
total
59.80
summary
<strong title='Qty - billing'>Qty - billing:</strong> 2 x 1 Day @ $26.00
2 x 1 Day @ $3.90 <em>(Additional days)</em>
2 x 2 Days <em>(Free first and last days)</em>
event
0
3
1
4
2
5
param
qty
qty
2
name
Qty - billing
discount
amount
0.00

 

Continuation from above.

 

Now when i add input in Code By Zapier, than i have to select SKU and quantity for each product. It is not coming as string for eg→ skuofproduct1, skufproduct2

 

 

I think because of i have to select each SKU, i am not able to run code by zapier action which is mentioned above.


Hey there! This will depend on the output that comes from the webhook - whether it’s fixed or variable dependent on the number of items you’re working with.

If it’s fixed like Items: Item 1, Item 2, Item 3 - You can definitely loop over it in a code step

If it’s variable like : 

Item1: Item 1

Item 2: Item 2

Item 3: Item 3 etc…

Then you’ll not have a way to determine which line items to send to a code step, and yes you’re right, it won’t be possible. The way to do this instead would be to make the API call using requests in the code step - That way you can determine the length of the array and use something like map with the returned value. Some more information on this can be found here: 

https://zapier.com/help/doc/how-get-started-code-zapier

https://github.com/node-fetch/node-fetch/tree/32b60634434a63865ea3f79edb33d17e40876c9f#usage

var FormData = require('form-data');
var form = new FormData();
form.append('a', 1);
fetch('http://httpbin.org/post', { method: 'POST', body: form, headers: form.getHeaders() })
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});