Best answer

Using moment.js in a new integration using code mode in the visual builder

  • 21 December 2021
  • 4 replies
  • 34 views

Userlevel 1

Is there a way to use moment.js in a new integration using code mode in the visual builder?  The documentation seems to imply that it is available (see here), but I get an error when I try to test my trigger.  The error says: “moment is not defined”.  My code looks like:

const today = moment();

Thanks in advance.

-Mark

icon

Best answer by Zane 21 December 2021, 23:32

View original

4 replies

Userlevel 7
Badge +9

To use a 3rd party library, you’ll need to move your project from the UI tool to the Zapier CLI. From there you can import moment from npm, import it and use it.

 

Instructions on exporting a UI-based project and continuing work in the CLI: https://platform.zapier.com/docs/export

Key differences in capabilities between the (current) Platform UI tool and the CLI: https://platform.zapier.com/docs/vs

 

https://zapier.com/developer/documentation/v2/scripting/#available-libraries is actually documentation for the legacy Web Builder tool/platform. It’s a common source of confusion. As we’re about a month away from retiring the legacy tool, we’re looking forward to removing that section of content. 

Userlevel 1

Got it, thanks!  For the future, where is the documentation for the scripting capabilities usable in code mode in the Platform UI tool?

Userlevel 7
Badge +9

You’ll see discussion of “code mode” topics sprinkled throughout the docs for the Platform UI. https://platform.zapier.com/docs/zapier-intro

But the best definitive reference for writing code in the UI is actually the CLI docs. https://zapier.github.io/zapier-platform/

The cool thing about the modern Platform UI is that you’re building something that runs on the same platform as the CLI. You’re creating an app definition that follows the same schema as an integration created in the CLI.  (Presently the UI is compatible with core version 9.x)

Not all features described in the CLI docs are available in, or relevant to, the UI. But the CLI docs are the best source to go deeper into writing JavaScript code to use the request API, customize response data, handle special errors, etc. 

We’ll be reworking docs over the next couple months with an eye toward presenting the information in a more unified way that’s easier to navigate, no matter which tool you’re working in. 

Userlevel 1

Thanks, @Zane!

Reply