· 6 years ago · Oct 07, 2019, 02:52 PM
1module.exports = {
2 key: 'recipe',
3
4 // You'll want to provide some helpful display labels and descriptions
5 // for users. Zapier will put them into the UX.
6 noun: 'Recipe',
7 display: {
8 label: 'Find a Recipe',
9 description: 'Search for recipe by cuisine style.'
10 },
11
12 // `operation` is where we make the call to your API to do the search
13 operation: {
14 // This search only has one search field. Your searches might have just one, or many
15 // search fields.
16 inputFields: [
17 {
18 key: 'style',
19 type: 'string',
20 label: 'Style',
21 helpText: 'Cuisine style to limit to the search to (i.e. mediterranean or italian).'
22 }
23 ],
24
25 perform: (z, bundle) => {
26 const url = 'https://auth-json-server.zapier.ninja/recipes';
27
28 // Put the search value in a query param. The details of how to build
29 // a search URL will depend on how your API works.
30 const options = {
31 params: {
32 style: bundle.inputData.style
33 }
34 };
35
36 return z.request(url, options)
37 .then(response => JSON.parse(response.content));
38 },
39
40 // In cases where Zapier needs to show an example record to the user, but we are unable to get a live example
41 // from the API, Zapier will fallback to this hard-coded sample. It should reflect the data structure of
42 // returned records, and have obviously dummy values that we can show to any user.
43 sample: {
44 id: 1,
45 createdAt: 1472069465,
46 name: 'Best Spagetti Ever',
47 authorId: 1,
48 directions: '1. Boil Noodles\n2.Serve with sauce',
49 style: 'italian'
50 },
51
52 // If the resource can have fields that are custom on a per-user basis, define a function to fetch the custom
53 // field definitions. The result will be used to augment the sample.
54 // outputFields: () => { return []; }
55 // Alternatively, a static field definition should be provided, to specify labels for the fields
56 outputFields: [
57 {key: 'id', label: 'ID'},
58 {key: 'createdAt', label: 'Created At'},
59 {key: 'name', label: 'Name'},
60 {key: 'directions', label: 'Directions'},
61 {key: 'authorId', label: 'Author ID'},
62 {key: 'style', label: 'Style'}
63 ]
64 }
65};