0

In Zapier I am building a zap that grabs a new webhook from quickbooks, compares it to a database and sends it to a website if it exists. Everything works except for one part.The bit of JavaScript that pulls a unique ID from a payload only takes the last result from a payload and does not process as separate values.

inputData.cleanID = webhookInputBodyHere //this is the input from zapier that gives the webhook body


if(inputData.cleanID == null){
  var listArray = [];
  } else{
   var listArray = inputData.cleanID.split("},{"); 
  }
var output = [];
var arrayNos = listArray.length;
var i = 0;
do{
  var thisItem = new String(listArray[i]);
  var thisItemObj = {};
  var getEachId = thisItemObj.record = thisItem;
  output.push({getEachId});
  i++;
}
while (i < arrayNos);

Payload example 1 (multi-item hook)

{"eventNotifications":[{"realmId":"SOMEID","dataChangeEvent":{"entities":[ {"name":"Estimate","id":"34371","operation":"Update","lastUpdated":"2019-10-09T13:04:27.000Z"}, {"name":"Estimate","id":"34369","operation":"Update","lastUpdated":"2019-10-09T13:04:06.000Z"}, {"name":"Estimate","id":"34370","operation":"Update","lastUpdated":"2019-10-09T13:04:18.000Z"}]}}]}

Payload example 2 (single hook):

{"eventNotifications":[{"realmId":"315179876","dataChangeEvent":{"entities":[ {"name":"Estimate","id":"34370","operation":"Update","lastUpdated":"2019-10-09T13:04:18.000Z"}]}}]}

I contacted support and they suggested picking off the child key "entities" or "entities.id" both of which failed to do the job. I also tried using this option from the stacks and it didn't work anymore.

For non-zapier users you can create a free account to get an idea of what I'm talking about here by creating a new zap and choosing "zapier webhook" as trigger and "zapier code" as an action.

Hook time in quickbooks developer set to minimum which is 1 minute, if I could change that it would fix everything, but that doesn't seem to be an option.

So to summarize:

  1. My webhook pulls a payload of 1 or more entities - TRIGGER

    ----See example 1 or 2----

  2. Zapier processes the payload all together as a single value - ISSUE

    ----If example 1 is the payload my code would result in example 2 only----

  3. I need each "entities" processed separately - DESIRED OUTPUT

    ----example 1 should output 3 seperate entities for to be processed in the zap----

  4. I then want the zap to run for each separate entities.ID - FINAL RESULT

littlecoder
  • 356
  • 2
  • 15

1 Answers1

0

Zapier has removed the ability to return each loop item for each additional action in the zap. Therefore you have to be a bit creative in getting around it by using TWO ZAPS. Here is a solution I got to work:

ZAP 1:

Action (after payload in question is sent) Run Zapier Code JS

const myData = JSON.parse(inputData.cleanID);
return myData.eventNotifications.map(item => { return item; });

Thanks to user Kenny for this bit of code that helped parse the data out

Action

Create Spreadsheet Row(s) in Google Sheets

You will need to create a spreadsheet in google drive (or any zap that allows multiple items).

Choose the option which allows for multiple rows and choose your ID output as a column (and whatever else you may need) like so:

enter image description here

End the Zap.



ZAP 2:

TRIGGER: New Spreadsheet Row in Google Sheets

Connect to the sheet and ID

ACTION: Whatever you wanted

End Zap

This is the best solution I could find for this issue at the time. I wanted to use MySQL but zapier doesn't have a solution for that yet. It does cause you to have to use 2 more tasks per run than the original JS code option but it's really all that we can do for now until zapier provides us something.

Community
  • 1
  • 1
littlecoder
  • 356
  • 2
  • 15