Check out the recipe bot template, it does exactly...
# đź’»developers
a
Check out the recipe bot template, it does exactly this. Here's what the code is:
Copy code
js
const url = 'https://api.spoonacular.com/recipes/complexSearch'
const params = {
  query: workflow.baseQuery,
  diet: workflow.dietType,
  apiKey: env.apiKey,
  number: '3',
  ignorePantry: 'false',
  sort: 'popularity',
  sortDirection: 'asc',
  addRecipeInformation: 'true',
  addRecipeNutrition: 'false'
}

try {
  const response = await axios.get(url, { params })
  if (response.status === 200) {
    workflow.recipeInfo = response.data.results
  }
} catch (error) {
  console.error(error)
}

workflow.recipes = []
const myCards = workflow.recipeInfo.map((recipe) => {
  workflow.recipes.push({
    title: recipe.title,
    vegetarian: recipe.vegetarian,
    vegan: recipe.vegan,
    glutenFree: recipe.glutenFree,
    dairyFree: recipe.dairyFree,
    veryHealthy: recipe.veryHealthy,
    cheap: recipe.cheap,
    veryPopular: recipe.veryPopular,
    readyInMinutes: recipe.readyInMinutes,
    servings: recipe.servings,
    summary: recipe.summary
  })
  // create the card object
  return {
    type: 'card',
    title: {
      dynamicValue: `${recipe.title}`,
      valueType: 'dynamic'
    },
    subtitle: {
      dynamicValue: '',
      valueType: 'dynamic'
    },
    imageUrl: {
      dynamicValue: `${recipe.image}`,
      valueType: 'dynamic'
    },
    actions: [
      {
        action: 'url',
        label: 'View Recipe',
        value: `${recipe.sourceUrl}`
      }
    ]
  }
})
workflow.cards = []
for (var card of myCards) {
  workflow.cards.push({
    //in order to render a card, we only need these three fields
    title: card.title,
    imageUrl: card.imageUrl,
    actions: card.actions[0]
  })
}
You'll need to adapt it to your API of course, but it is a good start
2 Views