UNPKG

2.14 kBJavaScriptView Raw
1// find a particular <%= LOWER_NOUN %> by name
2const perform = async (z, bundle) => {
3 const response = await z.request({
4 url: 'https://jsonplaceholder.typicode.com/posts',
5 params: {
6 name: bundle.inputData.name
7 }
8 });
9 // this should return an array of objects (but only the first will be used)
10 return response.data
11};
12
13module.exports = {
14 // see here for a full list of available properties:
15 // https://github.com/zapier/zapier-platform/blob/master/packages/schema/docs/build/schema.md#searchschema
16 key: '<%= KEY %>',
17 noun: '<%= NOUN %>',
18
19 display: {
20 label: 'Find <%= NOUN %>',
21 description: 'Finds a <%= LOWER_NOUN %> based on name.'
22 },
23
24 operation: {
25 perform,
26
27 <%= INCLUDE_INTRO_COMMENTS ? [
28 '// `inputFields` defines the fields a user could provide',
29 '// Zapier will pass them in as `bundle.inputData` later. Searches need at least one `inputField`.'
30 ].join('\n ') : '' %>
31 inputFields: [
32 {key: 'name', required: true, helpText: 'Find the <%= NOUN %> with this name.'}
33 ],
34
35 <%= INCLUDE_INTRO_COMMENTS ? [
36 '// In cases where Zapier needs to show an example record to the user, but we are unable to get a live example',
37 '// from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of',
38 '// returned records, and have obvious placeholder values that we can show to any user.'
39 ].join('\n ') : '' %>
40 sample: {
41 id: 1,
42 name: 'Test'
43 },
44
45 <%= INCLUDE_INTRO_COMMENTS ? [
46 '// If fields are custom to each user (like spreadsheet columns), `outputFields` can create human labels',
47 '// For a more complete example of using dynamic fields see',
48 '// https://github.com/zapier/zapier-platform/tree/master/packages/cli#customdynamic-fields',
49 '// Alternatively, a static field definition can be provided, to specify labels for the fields'
50 ].join('\n ') : '' %>
51 outputFields: [
52 // these are placeholders to match the example `perform` above
53 // {key: 'id', label: 'Person ID'},
54 // {key: 'name', label: 'Person Name'}
55 ]
56 }
57};