Skip to content

Instantly share code, notes, and snippets.

@ctrl-freak
Created April 25, 2022 12:44
Show Gist options
  • Save ctrl-freak/6249b2130b8a9c6da36ca8c4f3f5999b to your computer and use it in GitHub Desktop.
Save ctrl-freak/6249b2130b8a9c6da36ca8c4f3f5999b to your computer and use it in GitHub Desktop.
Reformat Marley Spoon API Recipe for insert to Mealie via n8n
var recipe = {};
recipe.name = item.name_with_subtitle;
recipe.recipe_yield = '4 Servings';
var ingredients = [];
item.ingredients.forEach((ingredient) => {
ingredients.push(ingredient.name_with_quantity);
});
item.assumed_ingredients.forEach((ingredient) => {
ingredients.push(ingredient.name);
});
recipe.recipeIngredient = ingredients;
var tags = [];
item.meal_attributes.forEach((tag) => {
tags.push((tag.charAt(0).toUpperCase() + tag.slice(1)).replaceAll('_',' '));
});
recipe.tags = tags;
recipe.recipe_category = [
(item.meal_type.charAt(0).toUpperCase() + item.meal_type.slice(1)).replaceAll('_',' '),
(item.product_type.charAt(0).toUpperCase() + item.product_type.slice(1)).replaceAll('_',' ')
];
var steps = [];
item.steps.forEach((step) => {
steps.push({
title: step.title,
text: step.description
})
});
recipe.recipeInstructions = steps;
recipe.nutrition = {
calories: item.nutrition.calories.replace(/[^\d.-]/g, ''),
carbohydrateTotal: item.nutrition.carbs.replace(/[^\d.-]/g, ''),
fatContent: item.nutrition.fat.replace(/[^\d.-]/g, ''),
proteinContent: item.nutrition.proteins.replace(/[^\d.-]/g, '')
};
var tools = [];
item.assumed_cooking_utilities.forEach((tool) => {
tools.push(tool.name);
});
recipe.tools = tools;
if (item.cooking_tip) {
recipe.notes = [{
title: 'Cooking Tip',
text: item.cooking_tip
}];
};
recipe.org_url = item.recipe_card_url;
recipe.image = item.image.large;
recipe.slug = item.slug.replace(item.id+'-','');
return recipe;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment