API calls
# 🤝help
h
I have a third party tool which I'd like to connect with where the API would ping the third party tool/ databasa based off a questions asked in the bot. For example if it asked how many more vacations days do I have, I want to build a call. I have access to the integration later and API to make this call but I'm not sure how to build this out on the botpress side. Any insight would be great.
a
hey @handsome-doctor-46275, here's some sample code for how to call an API from botpress. put this in an execute code card where needed:
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)
}
3 Views