Step 16: Make an API call to get ingredients

Our users should be able to ask about the item ingredients with voice and text commands. To do this, we will make a call to the Spoonacular food API using the built-in axios HTTP client.

  1. Sign up to Spoonacular food API.

  2. Upon confirming your account, log in to the Spoonacular API console and navigate to the Profile page.

  3. Copy the API key for your account.

  4. To the dialog script in Alan AI Studio, add the following command:

    Dialog script
    let ingredients = [];
    let itemId = "";
    const appId = "fe1888f12c2942c6b9b354cdf5425421";
    intent(`What are the $(ITEM ${itemList}) ingredients?`, p => {
        let itemName = p.ITEM.value;
        switch(p.ITEM.value) {
            case 'pepperoni':
                itemId = 776505;
            case 'margherita':
                itemId = 636954;
            case 'burger':
                itemId = 663050;
            case 'taco':
                itemId = 662744;
            case 'burrito':
                itemId = 637999;
            case 'apple pie':
                itemId = 632580;
                console.log('Could not get ingredients');
        let SERVICE_URL = `${itemId}/ingredientWidget.json`;
        const request_url = `${SERVICE_URL}?apiKey=${appId}`;
            .then((response) => {
                let data =;
                data.ingredients.forEach(element => {
  `The ${p.ITEM.value} ingredients are: ${ingredients}`);
            .catch((error) => {
  'Could not get ingredients');
        ingredients = [];

    Web page source | Dialog script

  5. In appId, provide your own API key.

Here is how this command works: when the user asks about the ingredients of a specific item, Alan AI forms a URL based on the item name captured with p.ITEM.value and sends a request to the food API by this URL. It then gets only the ingredients values from the response object and pushes them to the ingredients array. Once this is done, the list in the ingredients array is played back to the user.

Try the command in the Debugging Chat with different item names.