0

我有一个内部应用程序,它使用 webhook 侦听器和一些脚本来操作输入数据。我将其发布到它:

curl -X POST -d '{
    "assignment_id": 12345,
    "updated_custom_fields": [{
        "name": "RNVIDAYEBB",
        "value": "updated!"
      },
      {
        "name": "QUFTXSIBYA",
        "value": "and me too"
      }
    ],
    "custom_fields": [{
        "id": 981,
        "name": "RDEXDPVKRD",
        "fields": [
          {
            "id": 4096,
            "name": "RNVIDAYEBB",
            "default": "EDJEAJICYW",
            "required": true,
            "value": "Blah"
          },
          {
            "id": 4097,
            "name": "QUFTXSIBYA",
            "default": "",
            "required": true,
            "value": ""
          }]
     }]
}' "https://hooks.zapier.com/hooks/catch/......"

我的脚本如下:

update_custom_fields_by_name_pre_write: function(bundle) {
    var updatedFields = _.map(bundle.request.data.custom_fields, function(group) {
        return _.map(group.fields, function(field) {
            return _.extend(field, _.findWhere(bundle.request.data.updated_custom_fields, { name: field.name} ));
        });
    });
    bundle.request.data = updatedFields;
    return bundle.request;  
}

我知道合并逻辑很好,但是bundle.request.data 对象中似乎不存在custom_fieldsand数组。updated_custom_fields任何人都知道如何在脚本中访问它们?

4

1 回答 1

0

您似乎应该使用update_custom_fields_by_name_catch_hook来捕获传入的静态 webhook 数据(而不是_pre_write)。如果您使用它,您可以在bundle.cleaned_request.custom_fields和中捕获数据bundle.cleaned_request.updated_custom_fields

于 2016-09-01T15:57:31.330 回答