Early last year I bought a new camera. I’d been a casual shutterbug at various times before, but always wound up quitting within a few weeks or months. This time, though, was different. This time, the perfectionism and anxiousness and preordained sense of defeat that clung to every previous snap of the shutter were gone. This time, I wasn’t shooting to prove to some unseen force that I had intrinsic worth. This time, I was shooting just to shoot.
Debugging and testing custom code in Zapier, however, takes a little getting used to, especially if you’re accustomed to more traditional programming tools. Here are three immediate things to keep in mind as you get started:
- The above behavior seems counterintuitive (I mean, why wouldn’t someone expect to see the full output of their array in a test?), until you consider this: any subsequent action after your code will process each item in the returned array individually. For instance, if your code returns an array with four items, and the following action is Zapier’s stock text formatter to transform all upper case letters to lower case letters, then the text formatter will loop through all four, acting on each in order. So, when the test in Zapier shows you only the first item in your multi-item array, it’s showing you the data that will be immediately passed to the next action, which is the most relevant thing when chaining actions together in your zap. It takes a minute to wrap your head around, but when you get it everything falls into place.
- Logging to the console is your friend. Drop in a console.log(your-array-variable-here) within your code action to confirm the full contents of your array during testing. The output of console.log will show in the test output under the logs key.