{
  "info": {
    "_postman_id": "46feec9e-d289-4a9d-9f53-ec933116b04a",
    "name": "sangmalingh4y hack3r \u2014 Find Rp 0 Products",
    "description": "Single-purpose collection: discover every sangmalingh4y hack3r product priced Rp 0.\n\nRun in order:\n  1) Sign in  -> captures {{token}}.\n  2) Scan for Rp 0 products -> GET /product/v1/category, then every product group,\n     keeping items whose basic_price is \"0\". Results land in {{zero_items}} / {{zero_count}}.\n  3) Print results -> show the stored list.\n  4) Add all found to cart (optional).\n\nSet collection variables `phone`, `pin`, `store_code` first (store_code picks the store).\nFor account +6285282137890 use pin 123456; for +6285156181078 use pin 130905.\nVerified result: 19 Rp 0 products (16 genuinely orderable; the 3 Oden/FG096 lines come back empty).",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "10561723"
  },
  "item": [
    {
      "name": "1. Sign in",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Capture the access JWT into the {{token}} collection variable.",
              "let j = pm.response.json();",
              "if (j.data && j.data.access && j.data.access.token) {",
              "    pm.collectionVariables.set('token', j.data.access.token);",
              "    console.log('[+] token captured');",
              "}",
              "pm.test('signin 200', () => pm.response.to.have.status(200));"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "X-FamiApp-Store-Code",
            "value": "{{store_code}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"username\": \"+{{phone}}\",\n  \"password\": \"{{pin}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{base_url}}/account/v1/auth/signin",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "account",
            "v1",
            "auth",
            "signin"
          ]
        },
        "description": "Username is country_code+phone; keep the leading '+' if the account needs it (otherwise also try without)."
      },
      "response": []
    },
    {
      "name": "2. Scan for Rp 0 products",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "// === FamiGO: find every product with basic_price \"0\" ===",
              "// Scans GET /product/v1/category -> every product group -> every item,",
              "// and keeps the ones whose basic_price is \"0\". Results go to {{zero_items}}.",
              "const base  = pm.collectionVariables.get('base_url');",
              "const store = pm.collectionVariables.get('store_code');",
              "const token = pm.collectionVariables.get('token');",
              "const H = { 'Authorization': 'Bearer ' + token, 'X-FamiApp-Store-Code': store };",
              "",
              "if (!token) { console.error('No token - run \"Sign in\" first.'); return; }",
              "",
              "pm.sendRequest({ url: base + '/product/v1/category', method: 'GET', header: H }, (err, res) => {",
              "    if (err) { console.error(err); return; }",
              "    pm.test('category 200', () => pm.expect(res.code).to.eql(200));",
              "",
              "    const groups = [];",
              "    const cats = (res.json().data) || [];",
              "    cats.forEach(c => (c.product_group || []).forEach(g => groups.push({",
              "        code: g.product_group_code, name: g.product_group_name, listing_type: g.listing_type",
              "    })));",
              "    console.log('scanning', groups.length, 'product groups @ store', store);",
              "",
              "    const found = [];",
              "    let i = 0;",
              "    const step = () => {",
              "        if (i >= groups.length) {",
              "            found.sort((a, b) => a.group.localeCompare(b.group));",
              "            pm.collectionVariables.set('zero_items', JSON.stringify(found));",
              "            pm.collectionVariables.set('zero_count', String(found.length));",
              "            console.log('=== Rp 0 products found: ' + found.length + ' ===');",
              "            console.log(JSON.stringify(found.map(x => ({ barcode: x.barcode, group: x.group, listing: x.listing_type, price: x.basic_price, oos: x.is_oos, name: x.name })), null, 2));",
              "            pm.test('found at least one Rp 0 product', () => pm.expect(found.length).to.be.above(0));",
              "            return;",
              "        }",
              "        const g = groups[i++];",
              "        pm.sendRequest({ url: base + '/product/v1/product-group/' + g.code, method: 'GET', header: H }, (e2, r2) => {",
              "            if (!e2 && r2.code === 200) {",
              "                let d = null; try { d = r2.json().data; } catch (_) {}",
              "                if (d && Array.isArray(d.product_group_item)) {",
              "                    d.product_group_item.forEach(it => {",
              "                        if (String(it.basic_price) === '0') found.push({",
              "                            barcode: it.barcode,",
              "                            group: d.product_group_code || g.code,",
              "                            group_name: d.product_group_name || g.name,",
              "                            listing_type: d.listing_type || g.listing_type,",
              "                            name: it.item_desc_short || it.item_desc_long || '',",
              "                            basic_price: it.basic_price,",
              "                            is_oos: it.is_oos",
              "                        });",
              "                    });",
              "                }",
              "            }",
              "            step();",
              "        });",
              "    };",
              "    step();",
              "});"
            ],
            "type": "text/javascript",
            "packages": {},
            "requests": {}
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{token}}"
          },
          {
            "key": "X-FamiApp-Store-Code",
            "value": "{{store_code}}"
          }
        ],
        "url": {
          "raw": "{{base_url}}/product/v1/category",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "product",
            "v1",
            "category"
          ]
        },
        "description": "The test script enumerates all product groups via pm.sendRequest and collects items with basic_price == \"0\"."
      },
      "response": []
    },
    {
      "name": "3. Print results",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "const found = JSON.parse(pm.collectionVariables.get('zero_items') || '[]');",
              "const rows = found.map(x => ({",
              "  barcode: x.barcode,",
              "  group: x.group,",
              "  listing: x.listing_type,",
              "  name: x.name",
              "}));",
              "",
              "console.log('Stored Rp 0 products:', found.length);",
              "console.log('Rp 0 products:', rows);",
              "",
              "pm.test('results stored', () => {",
              "  pm.expect(found.length).to.be.above(0);",
              "});"
            ],
            "type": "text/javascript",
            "packages": {},
            "requests": {}
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{token}}"
          },
          {
            "key": "X-FamiApp-Store-Code",
            "value": "{{store_code}}"
          }
        ],
        "url": {
          "raw": "{{base_url}}/product/v1/category",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "product",
            "v1",
            "category"
          ]
        },
        "description": "Prints the {{zero_items}} list captured by the scan."
      },
      "response": []
    },
    {
      "name": "4. Add all found to cart (optional)",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Add every product found by the scan to the cart (one POST per item).",
              "const base  = pm.collectionVariables.get('base_url');",
              "const store = pm.collectionVariables.get('store_code');",
              "const token = pm.collectionVariables.get('token');",
              "const H = { 'Authorization': 'Bearer ' + token, 'X-FamiApp-Store-Code': store, 'Content-Type': 'application/json' };",
              "const items = JSON.parse(pm.collectionVariables.get('zero_items') || '[]');",
              "",
              "if (!items.length) { console.error('Run the scan first (zero_items is empty).'); return; }",
              "// Oden group FG096 needs the variant-group code; other groups use their own code.",
              "const ODEN = { '2710001211968': 'SPICY_EOMUK', '2710001211982': 'HOTBAR_CHEESE', '2710001211975': 'PREMIUM_SAUSAGE_ROLL' };",
              "",
              "let i = 0, ok = 0;",
              "const step = () => {",
              "    if (i >= items.length) {",
              "        console.log('[+] added ' + ok + '/' + items.length + ' free items');",
              "        pm.test('all adds accepted', () => pm.expect(ok).to.eql(items.length));",
              "        return;",
              "    }",
              "    const it = items[i++];",
              "    const pgc = it.group === 'FG096' ? 'ODEN_ALA_CARTE' : it.group;",
              "    pm.sendRequest({",
              "        url: base + '/order/v1/cart/item', method: 'POST', header: H,",
              "        body: { mode: 'raw', raw: JSON.stringify({",
              "            store_code: store, product_group_code: pgc, listing_type: it.listing_type,",
              "            items: [{ barcode: it.barcode, qty: 1, type_product: ODEN[it.barcode] || '', options: [], addons: [] }]",
              "        })}",
              "    }, (e, r) => { if (!e && r.code === 200) ok++; step(); });",
              "};",
              "step();"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{token}}"
          },
          {
            "key": "X-FamiApp-Store-Code",
            "value": "{{store_code}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"store_code\": \"{{store_code}}\",\n  \"product_group_code\": \"BG014\",\n  \"listing_type\": \"BEV\",\n  \"items\": [{\"barcode\": \"{{zero_barcode}}\", \"qty\": 1, \"type_product\": \"\", \"options\": [], \"addons\": []}]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{base_url}}/order/v1/cart/item",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "order",
            "v1",
            "cart",
            "item"
          ]
        },
        "description": "The test script loops over {{zero_items}} and POSTs each barcode. (No paid item is added here - add one before checkout.)"
      },
      "response": []
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Nothing global; each request manages its own state."
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "base_url",
      "value": "https://famigo.familymartindonesia.com"
    },
    {
      "key": "token",
      "value": ""
    },
    {
      "key": "store_code",
      "value": "0000000487"
    },
    {
      "key": "phone",
      "value": "6281234567890"
    },
    {
      "key": "pin",
      "value": "123456"
    },
    {
      "key": "zero_items",
      "value": "[]"
    },
    {
      "key": "zero_count",
      "value": "0"
    }
  ]
}