Skip to main content

I believe I nearly have this script working. I have two zap events, the first is a Catch Raw Hook event that successfully captures raw JSON from a webhook, the second is a Run Javascript event. The script works as intended, but I believe I am not correctly defining inputData at the beginning of the script, hence the error. This may be something simple I am overlooking, any guidance is appreciated!

The JSON being output from the Catch Raw Hook Event is as follows:

>{"testJSON":{"testfield1":"test","testfield2":"test","testfield3":"test","testfield4":1,"testfield5":"0","testfield6":"0","testfield7":"test","zipCode":"90210","city":"testfield8","testfield9":"test","testfield10":"testfield10","testfield11":"test","testfield12":"test","testfield13":"test"},"events":"2021-10-04\nPage visit 09:50:00\n - URL: google.com/testing123\nPage visit 09:55:50\n - URL: google.com/testing456\nPage visit 09:52:03\n - URL: google.com/testing789\n\n2021-11-04\nPage visit 13:40:03\n - URL: google.com/blah\n\n"}]

The Javascript being run in the second zap event is as follows, with “inputData” as the name set for the incoming data from the Catch Raw Hook event in the Run Javascript event:

const text = inputDatat0].events;
const p1 = /(\d{4}-\d{2}-\d{2})~(.*?)~~/g;
let vals = l...text.replaceAll("\n", "~").matchAll(p1)];

const p2 = /page visit\s+(t^~]*)~\s+-\s+url:\s+(:^~]*)/ig;
let buffer = e];

vals.forEach(v=>{
  let t = v 1];
  let parsed = r...v=2].matchAll(p2)];
  parsed.forEach(p=>{
    buffer.push({dt: t, time: pt1], url: p12]});  
  });
});

output = {buffer};

 

Hi @so-zap101 

Check out the available help articles: https://zapier.com/apps/code/help

Can you post screenshots with how your Code step is configured?

 


Thank you!

I can, please see below:

 

 


@so-zap101 

Change this from “inputData” to “events”

 

Change this to: const text = inputData.events;

 


This does resolve the original error, which is all I can ask for given the scope of the question (thank you!). Hitting a minor “not a function” snag on text.replaceAll, but I can take a look at that. This code block is a little odd in that it runs successfully in other environments but runs into issues in Zapier.


@so-zap101 

See the warning under the Code input: