{
  "info": {
    "name": "BaZaaRDan Partner API v1.0.7",
    "description": "BaZaaRDan Open Partner API Postman collection. Uses X-BZ-CLIENT-ID, X-BZ-TIMESTAMP and X-BZ-SIGNATURE HMAC authentication. v1.0.7 includes XML Feeds endpoints.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "noauth"
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "",
          "const clientId = pm.environment.get(\"client_id\") || \"\";",
          "const clientSecret = pm.environment.get(\"client_secret\") || \"\";",
          "",
          "if (!clientId || !clientSecret) {",
          "  throw new Error(\"client_id/client_secret environment içinde yok.\");",
          "}",
          "",
          "const timestamp = Math.floor(Date.now() / 1000).toString();",
          "const method = pm.request.method.toUpperCase();",
          "",
          "const url = pm.request.url;",
          "",
          "// Full path normalde: /api/partner/v1/orders.php",
          "let fullPath = \"/\" + (url.path || []).map(function (p) {",
          "  return pm.variables.replaceIn(String(p));",
          "}).join(\"/\");",
          "",
          "// PHP SDK base_url'den sonrasını imzalıyor: /orders.php?... ",
          "let apiPath = fullPath.replace(/^\\/api\\/partner\\/v1/, \"\");",
          "if (!apiPath.startsWith(\"/\")) {",
          "  apiPath = \"/\" + apiPath;",
          "}",
          "",
          "// Query string'i aktif parametrelerden sırayla ekle.",
          "let queryParts = [];",
          "if (url.query && url.query.all) {",
          "  url.query.all().forEach(function (q) {",
          "    if (!q.disabled && q.key) {",
          "      const key = encodeURIComponent(pm.variables.replaceIn(String(q.key)));",
          "      const value = encodeURIComponent(pm.variables.replaceIn(String(q.value || \"\")));",
          "      queryParts.push(key + \"=\" + value);",
          "    }",
          "  });",
          "}",
          "",
          "if (queryParts.length > 0) {",
          "  apiPath += \"?\" + queryParts.join(\"&\");",
          "}",
          "",
          "let body = \"\";",
          "if (method !== \"GET\" && pm.request.body && pm.request.body.raw) {",
          "  body = pm.variables.replaceIn(pm.request.body.raw);",
          "}",
          "",
          "// PHP SDK v1.0.5 ile aynı:",
          "// strtoupper(method) + \"\\n\" + pathWithQuery + \"\\n\" + unixTimestamp + \"\\n\" + body",
          "const baseString = [",
          "  method,",
          "  apiPath,",
          "  timestamp,",
          "  body",
          "].join(\"\\n\");",
          "",
          "const signature = CryptoJS.HmacSHA256(baseString, clientSecret).toString(CryptoJS.enc.Hex);",
          "",
          "pm.request.headers.upsert({ key: \"X-BZ-CLIENT-ID\", value: clientId });",
          "pm.request.headers.upsert({ key: \"X-BZ-TIMESTAMP\", value: timestamp });",
          "pm.request.headers.upsert({ key: \"X-BZ-SIGNATURE\", value: signature });",
          "pm.request.headers.upsert({ key: \"Accept\", value: \"application/json\" });",
          "",
          "if (method !== \"GET\") {",
          "  pm.request.headers.upsert({ key: \"Content-Type\", value: \"application/json\" });",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Ping",
      "item": [
        {
          "name": "Ping",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/ping.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "ping.php"
              ]
            },
            "description": "Partner API bağlantı ve HMAC imza kontrolü."
          }
        }
      ]
    },
    {
      "name": "Orders",
      "item": [
        {
          "name": "List Orders",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/orders.php?limit={{limit}}&offset={{offset}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "orders.php"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "{{limit}}"
                },
                {
                  "key": "offset",
                  "value": "{{offset}}"
                }
              ]
            },
            "description": "Siparişleri listeler. Permission: orders:read"
          }
        },
        {
          "name": "Order Detail",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/order_detail.php?order_item_id={{order_item_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "order_detail.php"
              ],
              "query": [
                {
                  "key": "order_item_id",
                  "value": "{{order_item_id}}"
                }
              ]
            },
            "description": "Tek sipariş kalemi detayını döndürür. Permission: orders:detail"
          }
        }
      ]
    },
    {
      "name": "Stock",
      "item": [
        {
          "name": "Stock Update By SKU",
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"sku\": \"{{sku}}\",\n  \"stock\": 25\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/stock_update.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "stock_update.php"
              ]
            },
            "description": "SKU bazlı stok günceller. Permission: stock:write"
          }
        }
      ]
    },
    {
      "name": "Webhooks",
      "item": [
        {
          "name": "List Webhooks",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/webhooks.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "webhooks.php"
              ]
            }
          }
        },
        {
          "name": "Create Webhook",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Postman v1.0.6 Test Webhook\",\n  \"url\": \"{{webhook_test_url}}\",\n  \"events\": [\"order.created\", \"stock.updated\"]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{base_url}}/webhooks.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "webhooks.php"
              ]
            }
          }
        },
        {
          "name": "List Webhook Deliveries",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/webhook_deliveries.php?limit={{limit}}&offset={{offset}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "webhook_deliveries.php"
              ],
              "query": [
                {
                  "key": "limit",
                  "value": "{{limit}}"
                },
                {
                  "key": "offset",
                  "value": "{{offset}}"
                }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "XML Feeds",
      "item": [
        {
          "name": "List XML Feeds",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/xml_feeds.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feeds.php"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Create XML Feed",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/xml_feeds.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feeds.php"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"feed_name\": \"Postman XML Feed\",\n  \"feed_url\": \"{{xml_feed_url}}\",\n  \"auth_type\": \"none\",\n  \"status\": \"draft\",\n  \"match_key\": \"barcode\",\n  \"nodes\": {\n    \"product_node\": \"product\",\n    \"variant_node\": \"variants.variant\"\n  },\n  \"fields\": {\n    \"external_product_id_field\": \"id\",\n    \"product_code_field\": \"productCode\",\n    \"barcode_field\": \"barcode\",\n    \"sku_field\": \"sku\",\n    \"name_field\": \"name\",\n    \"description_field\": \"description\",\n    \"price_field\": \"price\",\n    \"stock_field\": \"quantity\",\n    \"brand_field\": \"brand\",\n    \"category_field\": \"category\",\n    \"category_id_field\": \"categoryID\"\n  },\n  \"settings\": {\n    \"safety_stock\": 0,\n    \"import_interval_minutes\": 60\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        },
        {
          "name": "Update XML Feed",
          "request": {
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/xml_feeds.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feeds.php"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{xml_feed_id}}\",\n  \"feed_name\": \"Postman XML Feed Updated\",\n  \"status\": \"paused\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        },
        {
          "name": "Sync XML Feed",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/xml_feed_sync.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feed_sync.php"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{xml_feed_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        },
        {
          "name": "List XML Feed Products",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/xml_feed_products.php?feed_id={{xml_feed_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feed_products.php"
              ],
              "query": [
                {
                  "key": "feed_id",
                  "value": "{{xml_feed_id}}"
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "List XML Feed Import Runs",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/xml_feed_import_runs.php?feed_id={{xml_feed_id}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feed_import_runs.php"
              ],
              "query": [
                {
                  "key": "feed_id",
                  "value": "{{xml_feed_id}}"
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Delete XML Feed",
          "request": {
            "method": "DELETE",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/xml_feeds.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feeds.php"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{xml_feed_id}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "response": []
        },
        {
          "name": "Sync XML Feed - Full Import Dry Run",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"id\": \"{{xml_feed_id}}\",\n  \"mode\": \"full_import\",\n  \"dry_run\": true\n}"
            },
            "url": {
              "raw": "{{base_url}}/xml_feed_sync.php",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "xml_feed_sync.php"
              ]
            },
            "description": "Safe full import preview. dry_run=true does not create products, variants, or mappings."
          },
          "response": []
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "xml_feed_id",
      "value": "1",
      "type": "string"
    }
  ]
}
