我有一个内部应用程序,它使用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;
}
我知道合并逻辑很好,但似乎custom_fields
和updated_custom_fields
数组不存在于bundle.request.data对象中。有人知道如何在脚本中访问它们吗?
答案 0 :(得分:0)
您似乎应该使用update_custom_fields_by_name_catch_hook
来捕获传入的静态webhook数据(而不是_pre_write
)。如果您使用它,则可以在bundle.cleaned_request.custom_fields
和bundle.cleaned_request.updated_custom_fields
。