Skip to content
View in the app

A better way to browse. Learn more.

Loyverse Town

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How can I get data 'Category' and 'Modifiers applied' with API key

Featured Replies

I have try a lot of different way to get data from Receipts by Item with google sheet script every column of my data went fine expect "Categoty Name" and "Modifier Applied (Option Name)"

here is my sample code that's function
 

function getLoyverseData_Fixed() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  let sheet = ss.getSheetByName(SHEET_NAME) || ss.insertSheet(SHEET_NAME);
  sheet.clear();

  const headers = [
    "Date", "Receipt #", "Item Name", "Category Name", 
    "Modifier Applied (Option Name)", "Modifier ID", "Status"
  ];
  sheet.appendRow(headers);

  const categoriesMap = fetchCategoriesMap();
  
  const todayStart = new Date();
  todayStart.setHours(0, 0, 0, 0);

  const url = `https://api.loyverse.com/v1.0/receipts?created_at_min=${todayStart.toISOString()}&limit=250`;
  const options = { 'headers': { 'Authorization': 'Bearer ' + LOYVERSE_TOKEN }, 'muteHttpExceptions': true };
  const response = UrlFetchApp.fetch(url, options);
  const json = JSON.parse(response.getContentText());

  if (!json.receipts) {
    Logger.log("Failed");
    return;
  }

  let rows = [];
  json.receipts.forEach(r => {
    r.line_items.forEach(item => {
      let catName = item.category_name || categoriesMap[item.category_id] || "No Category";

      let modOptions = [];
      let modIds = [];
      if (item.modifiers) {
        item.modifiers.forEach(m => {
          modOptions.push(m.option_name || m.name); // ดึง Option Name ตามภาพ
          modIds.push(m.modifier_id);
        });
      }

      rows.push([
        r.created_at,
        r.receipt_number,
        item.item_name,
        catName,
        modOptions.join(", ") || "-", // คอลัมน์ U
        modIds.join(", ") || "-",     // คอลัมน์ V
        r.receipt_type
      ]);
    });
  });

  if (rows.length > 0) {
    sheet.getRange(2, 1, rows.length, headers.length).setValues(rows);
    sheet.autoResizeColumns(1, headers.length);
    Logger.log("Done checking at" + SHEET_NAME);
  }
}

function fetchCategoriesMap() {
  let catMap = {};
  try {
    const res = UrlFetchApp.fetch('https://api.loyverse.com/v1.0/categories?limit=250', {
      'headers': { 'Authorization': 'Bearer ' + LOYVERSE_TOKEN }
    });
    const json = JSON.parse(res.getContentText());
    if (json.categories) {
      json.categories.forEach(c => { catMap[c.id] = c.name; });
    }
  } catch(e) { Logger.log("Failed"); }
  return catMap;
}

result is Category and Modifiers return blank and I can't use this data to run around powerBI with sheet sources to visualize for my team.
By far I'm not sure if I call a wrong data name or I just can't get these both data. I'm not really developer just a marketing so if anyone can help me fixed this please.
 

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.