UNPKG

2.5 kBJavaScriptView Raw
1// create a particular <%= LOWER_NOUN %> by name
2const perform = async (z, bundle) => {
3 const response = await z.request({
4 method: 'POST',
5 url: 'https://jsonplaceholder.typicode.com/posts',
6 // if `body` is an object, it'll automatically get run through JSON.stringify
7 // if you don't want to send JSON, pass a string in your chosen format here instead
8 body: {
9 name: bundle.inputData.name
10 }
11 });
12 // this should return a single object
13 return response.data;
14};
15
16module.exports = {
17 // see here for a full list of available properties:
18 // https://github.com/zapier/zapier-platform/blob/master/packages/schema/docs/build/schema.md#createschema
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 // these are placeholders to match the example `perform` above
58 // {key: 'id', label: 'Person ID'},
59 // {key: 'name', label: 'Person Name'}
60 ]
61 }
62};