简体   繁体   English

如何将此 JavaScript 代码添加到 Zapier,以发出第 3 方礼物?

[英]How do I add this JavaScript code to Zapier, to issue a 3rd party gift?

My eCommerce website needs to run JavaScript code so a 3rd party can send the customer a gift.我的电子商务网站需要运行 JavaScript 代码,以便第三方可以向客户发送礼物。 The JavaScript code worked on the Thank You page, but I need to have a few-day delay before the script runs, so I'm trying to do this with Zapier instead. JavaScript 代码在谢谢页面上工作,但我需要在脚本运行前延迟几天,所以我尝试使用 Zapier 来执行此操作。 But Zapier is giving the following error when the same code is used there:但是当在那里使用相同的代码时,Zapier 会出现以下错误:

The run javascript could not be sent to Code by Zapier. Zapier 无法将运行的 javascript 发送到代码。 SyntaxError: Unexpected token <语法错误:意外的标记 <

Zapier Support could not help, and I couldn't find the solution in Zapier's documentation. Zapier 支持无能为力,我在 Zapier 的文档中找不到解决方案。

Can someone please help modify the short code below, so that it can be run by Zapier?有人可以帮忙修改下面的短代码,以便它可以由 Zapier 运行吗?

 <script src="https://members.thirdparty.com/jsapi/fbDE_Voucher.min.js"></script> <script> window.onload = function(){ var fdDE_detail = { "fbDE_sender":'12345-67890', "fbDE_fullname":"'"+inputData.CustName+"'", "fbDE_email":"'"+inputData.CustEmail+"'", "fbDE_amount":inputData.VoucherValue, "fbDE_business":54321, "fbDE_message":'Thank you for your purchase!' } fbDEVoucher(fdDE_detail); } </script>

The variables CustName, CustEmail, and VoucherValue are from prior Zapier steps.变量 CustName、CustEmail 和 VoucherValue 来自之前的 Zapier 步骤。 The first 2 need to be within single quotes, and the third is an integer (not requiring quotes).前 2 个需要在单引号内,第三个是整数(不需要引号)。 Please see image below:请看下图:

JavaScript code for Zapier Zapier 的 JavaScript 代码

Does anyone know how to fix the above error (in bold) so this code runs?有谁知道如何修复上述错误(以粗体显示)以便此代码运行?

Appreciate your help!感谢你的帮助! Thanks.谢谢。

Zapier's code runs in Node.js , which is a different environment than the browser-based JS your code was running in before. Zapier 的代码在Node.js运行,这与您之前运行代码的基于浏览器的 JS 环境不同。

First off, <script> tags aren't available, since that's HTML.首先, <script>标签不可用,因为那是 HTML。 Whatever code comes in through fbDE_Voucher.min.js will need to be loaded separately.通过fbDE_Voucher.min.js任何代码都需要单独加载。 If it's not too long, you can paste it into the code window (but there's a better solution, see below).如果不是太长,您可以将其粘贴到代码窗口中(但有更好的解决方案,请参见下文)。

There's also no window global, but you don't need it anyway.也没有全局window ,但无论如何你都不需要它。 So to get this close to working, it would be something like:所以为了接近工作,它会是这样的:

// doesn't work, fbDEVoucher is undefined
fbDEVoucher({
  fbDE_sender: "12345-67890",
  fbDE_fullname: inputData.CustName, // doesn't need to be re-wrapped in a string
  fbDE_email: inputData.CustEmail,
  fbDE_amount: inputData.VoucherValue,
  fbDE_business: 54321,
  fbDE_message: "Thank you for your purchase!",
});

That's all you would need, assuming your function is already defined.假设您的函数已经定义,这就是您所需要的。


The best option for you here is to create a custom Zapier integration.对您来说最好的选择是创建自定义 Zapier 集成。 This gives you a more full-featured JS environment than a Code by Zapier step, plus dramatically more control.Code by Zapier步骤相比,这为您提供了一个功能更全面的 JS 环境,以及更多的控制。 You can include the aforementioned file and call the function as needed.您可以包含上述文件并根据需要调用该函数。 There's docs about that here: https://platform.zapier.com/有关于这里的文档: https : //platform.zapier.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用emscripten调用第三方JavaScript库? - How do I call a 3rd party javascript library with emscripten? 如何禁用第三方引入的javascript事件处理程序? - How do I disable a javascript event handler introduced by a 3rd party? 如何访问使用LINK标记加载的第三方样式表的源代码? - How do I access the source code of a 3rd party style sheet loaded using a LINK tag? 如何从第三方API提取数据并使用javascript将其显示在我的页面上? - How do I extract data from a 3rd party api and display it on my page with javascript? 逐步为第 3 方 javascript 模块添加类型 - Progressively add types for a 3rd party javascript module 您如何在Meteor.js中包含第三方JavaScript库? - How do you include 3rd party javascript libraries in Meteor.js? 如何使用javascript衡量第三方广告的加载时间? - How do you measure 3rd party ads load time using javascript? 如何通过第三方JavaScript访问容器中的标签列表? - How do you access the list of tags in a container via 3rd party javascript? 我可以将第三方JavaScript沙盒化以保护全局名称空间吗? - Can I sandbox 3rd party JavaScript to protect the global namespace? 试图嵌入使用的第三方Javascript <?js= value ?> ,我怎么能阻止PHP解析“ - Trying to embed 3rd party Javascript that uses <?js= value ?>, how can i stop php from parsing the “<?”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM