1 |
|
2 | const perform = async (z, bundle) => {
|
3 | const response = await z.request({
|
4 | method: 'POST',
|
5 | url: 'https://jsonplaceholder.typicode.com/posts',
|
6 |
|
7 |
|
8 | body: {
|
9 | name: bundle.inputData.name
|
10 | }
|
11 | });
|
12 |
|
13 | return response.data;
|
14 | };
|
15 |
|
16 | module.exports = {
|
17 |
|
18 |
|
19 | key: '<%= KEY %>',
|
20 | noun: '<%= NOUN %>',
|
21 |
|
22 | display: {
|
23 | label: 'Create <%= NOUN %>',
|
24 | description: 'Creates a new <%= LOWER_NOUN %>, probably with input from previous steps.'
|
25 | },
|
26 |
|
27 | operation: {
|
28 | perform,
|
29 |
|
30 | <%= INCLUDE_INTRO_COMMENTS ? [
|
31 | '// `inputFields` defines the fields a user could provide',
|
32 | '// Zapier will pass them in as `bundle.inputData` later. They\'re optional.',
|
33 | '// End-users will map data into these fields. In general, they should have any fields that the API can accept. Be sure to accurately mark which fields are required!'
|
34 | ].join('\n ') : '' %>
|
35 | inputFields: [
|
36 | {key: 'name', required: true},
|
37 | {key: 'fave_meal', label: 'Favorite Meal', required: false}
|
38 | ],
|
39 |
|
40 | <%= INCLUDE_INTRO_COMMENTS ? [
|
41 | '// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example',
|
42 | '// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of',
|
43 | '// returned records, and have obvious placeholder values that we can show to any user.'
|
44 | ].join('\n ') : '' %>
|
45 | sample: {
|
46 | id: 1,
|
47 | name: 'Test'
|
48 | },
|
49 |
|
50 | <%= INCLUDE_INTRO_COMMENTS ? [
|
51 | '// If fields are custom to each user (like spreadsheet columns), `outputFields` can create human labels',
|
52 | '// For a more complete example of using dynamic fields see',
|
53 | '// https://github.com/zapier/zapier-platform/tree/master/packages/cli#customdynamic-fields',
|
54 | '// Alternatively, a static field definition can be provided, to specify labels for the fields'
|
55 | ].join('\n ') : '' %>
|
56 | outputFields: [
|
57 |
|
58 |
|
59 |
|
60 | ]
|
61 | }
|
62 | };
|