MenuFacile

Quickstart in 60 secondiDEV

Dalla prima chiamata al menu sul tuo sito, in tre passi.

1. Prima chiamata (senza token)

Gli endpoint di lettura (/menu, /categories, /items, /restaurant, /theme, /allergens) sono pubblici: per mostrare il menu su un sito non serve nessun token.

Apri un terminale e prova:

curl https://<ristorante>.menufacile.it/api/v1/menu/it

Risposta (estratto):

{
  "success": true,
  "data": {
    "settings": {
      "name": "CIP Osteria Pennuta",
      "logo_url": "https://<ristorante>.menufacile.it/storage/branding/01JC8Y7K2M.png",
      "default_locale": "it",
      "supported_locales": ["it", "en"]
    },
    "theme": {
      "primary_color": "#C0AD8A",
      "background_color": "#2B3C37",
      "font_family": "Playfair Display"
    },
    "sections": [
      {
        "id": 1,
        "name": "Antipasti",
        "menu_type": "standard",
        "show_subcategories": false,
        "items": [
          {
            "id": 1,
            "type_id": null,
            "name": "Code di gambero croccanti",
            "description": "Coda di gambero con salsa BBQ",
            "price": 18,
            "allergens": ["crostacei"],
            "is_recommended": false
          }
        ],
        "types": []
      }
    ]
  },
  "meta": { "generated_at": "2026-11-16T10:00:00+00:00", "locale": "it" }
}

La lingua nel percorso (/menu/it, /menu/en…) sceglie la lingua dei testi. Senza lingua vale quella principale del ristorante.

2. Leggere bene una sezione

Una sezione può avere sottocategorie (types, per esempio "Pizze rosse" e "Pizze bianche" dentro "Pizze"). In quel caso lo stesso piatto compare due volte nella risposta:

Se stampi entrambe le liste, i piatti con sottocategoria escono doppi. Il modo giusto, lo stesso del menu Menu Facile:

function pianoSezione(section) {
  // Sezione semplice: basta items.
  if (!section.show_subcategories || section.types.length === 0) {
    return [{ title: null, items: section.items }];
  }
  // Sezione con sottocategorie: prima ogni sottocategoria con i suoi piatti...
  const groups = section.types.map(type => ({
    title: type.is_visible ? type.name : null, // is_visible=false: titolo nascosto, piatti visibili
    items: type.items,
  }));
  // ...poi i piatti della sezione che non hanno sottocategoria.
  const loose = section.items.filter(item => item.type_id === null);
  if (loose.length) groups.push({ title: null, items: loose });
  return groups;
}

Questa è la forma della risposta e non cambierà: leggila sempre così.

3. Mostra il menu sul sito

JavaScript (vanilla)

<div id="menu"></div>
<script>
  const esc = s => String(s ?? '').replace(/[&<>"']/g, c =>
    ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
  const euro = n => '€ ' + Number(n).toFixed(2).replace('.', ',');

  function pianoSezione(section) {
    if (!section.show_subcategories || section.types.length === 0) {
      return [{ title: null, items: section.items }];
    }
    const groups = section.types.map(t => ({ title: t.is_visible ? t.name : null, items: t.items }));
    const loose = section.items.filter(i => i.type_id === null);
    if (loose.length) groups.push({ title: null, items: loose });
    return groups;
  }

  fetch('https://<ristorante>.menufacile.it/api/v1/menu/it')
    .then(r => r.json())
    .then(({ success, data }) => {
      if (!success) throw new Error('Menu non disponibile');
      document.getElementById('menu').innerHTML = data.sections.map(sec => `
        <section>
          <h2>${esc(sec.name)}</h2>
          ${pianoSezione(sec).map(g => `
            ${g.title ? `<h3>${esc(g.title)}</h3>` : ''}
            <ul>
              ${g.items.map(item => `
                <li>
                  <strong>${esc(item.name)}</strong> — ${euro(item.price)}
                  ${item.description ? `<p>${esc(item.description)}</p>` : ''}
                </li>`).join('')}
            </ul>`).join('')}
        </section>`).join('');
    })
    .catch(() => { document.getElementById('menu').textContent = 'Menu temporaneamente non disponibile.'; });
</script>

WordPress

Per WordPress c'è una ricetta completa, con cache, sottocategorie ed etichette degli allergeni: Shortcode WordPress.

Quando serve un token

Solo per gli endpoint admin (/api/v1/admin/...: modificare il menu, leggere le statistiche). Si crea dal pannello del ristorante:

  1. Apri https://<ristorante>.menufacile.it/admin/api-tokens (menu Impostazioni → Token API)
  2. Clicca Genera nuovo token
  3. Scrivi il Nome del token (es. "Sito agenzia X")
  4. Scegli i Permessi: è già spuntato menu:read (lettura menu); aggiungi menu:write per modificare il menu o analytics:read per le statistiche
  5. Clicca Genera: il token compare in un riquadro. Copialo subito, non sarà più visibile

Il token ha la forma 12|abc...xyz. Dettagli in Autenticazione.

Cosa puoi fare adesso

Hai bisogno di aiuto?

Scrivi a supporto@studio121.it.