【问题标题】:Modify Zapier request url in Scripting在 Scripting 中修改 Zapier 请求 url
【发布时间】:2017-11-25 16:35:27
【问题描述】:

我正在尝试将 action_fields 中的数据作为查询字符串添加到 bundle.request.url。这是原始捆绑数据

{
  "auth_fields": {
    "sub_domain": "abc", 
    "apiKey": "1234"
  }, 
  "request": {
    "files": {}, 
    "url": "https://abc.my.workfront.com/attask/api/v7.0/project?&method=post", 
    "headers": {
      "Content-Type": "application/json; charset=utf-8", 
      "Accept": "application/json"
    }, 
    "params": {
      "apiKey": "1234"
    }, 
    "data": "{\"status\": \"PLN\", \"name\": \"Test 2\"}", 
    "method": "POST"
  }, 
  "action_fields": {
    "status": "PLN", 
    "name": "Test 2"
  }, 
  "action_fields_full": {
    "status": "PLN", 
    "name": "Test 2"
  }, 
  "meta": {
    "frontend": false
  }, 
  "action_fields_raw": {
    "status": "PLN", 
    "name": "Test 2"
  }, 
  "url_raw": "https://{{sub_domain}}.my.workfront.com/attask/api/v7.0/project?&method=post", 
  "zap": {}
}

我正在研究 Zapier 提供的示例并想出了这个

'use strict';

var Zap = {
    project_pre_write: function(bundle) {
       // bundle.request.method = "POST";
        console.log(bundle.request.action_fields["status"]);
        bundle.request.url = "http://abc.my.workfront.com/attask/api/v8.0/project?method=post";
        bundle.request.params = $.param(bundle.request.action_fields);
        console.log(bundle.request.params);

        return bundle.request;
    }

};  

但是我抛出了这个错误

TypeError: Cannot read property 'jquery' of undefined:

我不是 Javascript 专家(甚至几乎不是用户),所以任何想法都将不胜感激。最终结果应该是这样的

http://abc.my.wrokfront.com/attask/api/v7.0/project?method=post&name=Test%202&status=PLN&apiKey=1234

【问题讨论】:

    标签: javascript zapier


    【解决方案1】:

    试试这个:

    bundle.request.url += '&' + jQuery.param(bundle.action_fields);

    【讨论】:

    • 这似乎可以解决问题。我只需要替换 jQuery 术语,所以它看起来像这样 bundle.request.url += '&' + $.param(bundle.action_fields); 现在如果我可以让这个 302 响应消失,我会被设置
    猜你喜欢
    • 2015-02-07
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 2014-08-24
    • 2011-03-06
    • 1970-01-01
    相关资源
    最近更新 更多