我们有一个Zapier应用,它有一个“createContact”动作。我已经通过inputFields
数组定义了我们的用户将在Zapier的UI中看到的字段。这包括嵌套在字段中的一些字段。
我的代码生成了所需的UI,但是当我创建一个zap并对其进行测试时,我收到的数据的格式不同。嵌套字段会添加两次。
这是导出的对象:
module.exports = {
key: 'contact',
noun: 'Contact',
create: {
display: {
label: 'Create Contact',
description: 'Creates a new contact.'
},
operation: {
inputFields: [
{key: 'firstName', required: true},
{key: 'lastName', required: true},
{key: 'middleNames', required: false},
{key: 'address', required: false},
{key: 'phoneNumbers', required: false},
{key: 'emails', required: false},
{key: 'tags', required: false},
{key: 'links', required: false},
{
key: 'education', children: [
{key: 'school', required: false},
{key: 'degree', required: false},
{key: 'program', required: false, label: 'Field of Study'},
{key: 'grade', required: false},
{key: 'startDate', required: false, type: 'datetime' },
{key: 'endDate', required: false, type: 'datetime' },
]
}
],
perform: createContact
},
},
sample: {
id: 1,
firstName: 'Test first name',
lastName: 'Test last name'
},
outputFields: [
{key: 'id', label: 'ID'},
{key: 'firstName', label: 'First Name'},
{key: 'lastName', label: 'Last Name'},
]
};
注意:我在Field Schema上关注了Zapier的文档,这表明这是必需的格式:
{ key: 'abc', children: [ { key: 'abc' } ] }
通过将z.console.log(bundle.inputData)
放在createContact函数中,您可以看到children数组中的键(即startDate,school等)已添加到2个位置:
== Log
inputData 2 { startDate: '15/01/2017',
school: 'ABC School',
endDate: '16/01/2017',
degree: 'Test degree',
firstName: 'Joe',
grade: '1st',
lastName: 'Bloggs',
program: 'Test program',
education:
[ { startDate: '2017-01-15T00:00:00+00:00',
school: 'ABC School',
endDate: '2017-01-16T00:00:00+00:00',
degree: 'Test degree',
grade: '1st',
program: 'Test program' } ],
emails: 'test@test.com' }
== Version
1.0.0
== Step
7f944f0f-fd96-4ad3-bbc2-1d11b9b15c6f
== Timestamp
2018-01-15T12:09:56-06:00
bundle.inputData
是用户提供的触发/搜索/创建特定运行的数据,由inputFields定义。
所以我希望bundle.inputData与inputFields的格式相同。有什么想法我怎么能让bundle.inputData采用我在inputFields中定义的格式?
谢谢:)
答案 0 :(得分:1)
bundle.inputData用于存储数据。 你需要在你的表演部分添加这个:
firstname: bundle.inputData.firstname
每当用户提供' firstname:'它将使用bundle.inputData
存储在名字中。