And used FETCH instead of GET
# 🌎general
f
And used FETCH instead of GET
a
Hi Maurice! Care to share the working code with the community, so we have a workaround until the axios issue is resolved? 🙂
f
Sure
const url = 'https://api.spoonacular.com/recipes/complexSearch'; const query = workflow.baseQuery; const diet = workflow.dietType; const apiKey = env.apiKey; const number = '3'; const ignorePantry = 'false'; const sort = 'popularity'; const sortDirection = 'asc'; const addRecipeInformation = 'true'; const addRecipeNutrition = 'false'; const apiUrl = `${url}?query=${query}&diet=${diet}&apiKey=${apiKey}&number=${number}&ignorePantry=${ignorePantry}&sort=${sort}&sortDirection=${sortDirection}&addRecipeInformation=${addRecipeInformation}&addRecipeNutrition=${addRecipeNutrition}`; async function fetchData() { try { const response = await fetch(apiUrl); if (response.status === 200) { const data = await response.json(); workflow.recipeInfo = data.results; } else { console.log('Request failed with status:', response.status); } } catch (error) { console.log('Error:', error); } } await fetchData();
I used this code to call the api^
. . . . .
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] }) }
And used this code to process the api call
Here @acceptable-gold-88171
q
@freezing-eve-60762 , do you have to import fetch or is it in-built like Axios ?
f
It's part of the Javascript language so it's built in
f
it's not @freezing-eve-60762
f
Well I might be wrong but the code above worked for me
a
thanks so much Marice!! On another positive note, it looks like the issue was solve!
2 Views