Skip to content

Three tips for testing and debugging javascript in Zapier code actions

Johnathon Williams
Johnathon Williams
2 min read
Three tips for testing and debugging javascript in Zapier code actions

Zapier is bar none the handiest utility in existence for automating online workflows and connecting different online services. This was true even before the introduction of custom code actions, which allow you to drop in blocks of javascript and python code to manipulate data in your zaps, and it’s doubly true now.

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:

  1. Javascript code actions must return either an object or an array of objects. This is all well and good, but if you expect your code to return an array when testing your action within Zapier, you may find yourself confused when the test outputs only the first item of your array. You may then find yourself checking your code, over and over again, then your input, over and over again, then your favorite swear words, then your sanity. But the truth is your code is working fine, and Zapier is working fine: testing a code action will output only the first object in an array, no matter how many objects are actually in the array. This is only true of testing your zap; when the zap actually runs, the full array will be processed.
  2. 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.
  3. 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.
automationcodejavascriptzapier

Related Posts

Members Public

How to use Zapier to extract all URLs from a text source

Here’s a nifty trick for pulling all of the URLs out of text with a Zapier javascript code action. Using this, you can extract URLs from any Zapier text input. For instance, you could use the Zapier email trigger to pull all of the URLs from an email message,

Members Public

Should you enable automatic updates in WordPress?

One of the headline features in the recent release of WordPress 5.5 was the ability to enable automatic plugin and theme updates. This follows the inclusion of automatic core updates in WP 3.7. On paper, the arguments for automatic updates are compelling. They’re the fastest and most

Should you enable automatic updates in WordPress?
Members Public

Auto tweet new WordPress posts with categories as hashtags in Zapier

Automatically sending tweets for new posts on your WordPress site is a simple task with Zapier. Recently, though, I wanted to add hashtags for each category assigned to the WordPress post and include that in the tweet as well. Can Zapier accommodate this? Yes, it can, although it turned out

Auto tweet new WordPress posts with categories as hashtags in Zapier