{
  "info": {
    "name": "Massar Brand API \u2014 production",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Set apiKey in a private local environment. GET cities first; set cityId from the response. POST orders creates a real shipment. Do not run the entire collection as a connectivity test."
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://torok-api.onrender.com/api/integrations/v1"
    },
    {
      "key": "apiKey",
      "value": ""
    },
    {
      "key": "cityId",
      "value": ""
    },
    {
      "key": "externalOrderId",
      "value": "YOUR-ORDER-1001"
    }
  ],
  "item": [
    {
      "name": "GET /cities \u2014 Find delivery cities",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/cities?q=Nasr",
        "description": "Search English city, Arabic city or English governorate name. Returns at most 1000 serviceable cities. No pagination parameters."
      }
    },
    {
      "name": "POST /quote \u2014 Calculate price and collection amount",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/quote",
        "description": "No shipment is created. COD total = productCodAmount + deliveryCost. PREPAID total = 0. Prices follow your brand agreement; never hardcode shipping fees.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"cityId\": \"{{cityId}}\",\n  \"productCodAmount\": 1000,\n  \"paymentMethod\": \"COD\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "POST /orders \u2014 Create a shipment",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/orders",
        "description": "PRODUCTION WRITE: creates a real shipment record. Identical normalized payload and externalOrderId returns the existing order. Changed payload with same ID returns 409. No Idempotency-Key header is used. After a timeout, look up or retry the exact same payload; never mint a new externalOrderId to retry.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"externalOrderId\": \"YOUR-ORDER-1001\",\n  \"receiverName\": \"Example customer\",\n  \"receiverAddress\": \"Building, street, floor and apartment\",\n  \"cityId\": \"{{cityId}}\",\n  \"receiverMobile1\": \"REPLACE_WITH_CUSTOMER_PHONE\",\n  \"productCodAmount\": 1000,\n  \"paymentMethod\": \"COD\",\n  \"items\": [\n    {\n      \"itemName\": \"Cotton shirt\",\n      \"sku\": \"SHIRT-M\",\n      \"quantity\": 1\n    }\n  ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "GET /orders/{externalOrderId} \u2014 Look up an order by your external ID",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/orders/{{externalOrderId}}",
        "description": "Brand-scoped lookup using your original externalOrderId, not the Massar waybill. URL-encode the path value."
      }
    },
    {
      "name": "GET /webhook \u2014 Read your webhook subscription",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/webhook",
        "description": "Returns null if no subscription exists; otherwise includes active=false for a disabled subscription."
      }
    },
    {
      "name": "PUT /webhook \u2014 Register or rotate a webhook",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/webhook",
        "description": "One endpoint per brand. Every PUT rotates the signing secret, including the same URL. Use public HTTPS port 443; private/loopback hosts, credentials, redirects and non-public DNS are refused. Secret is returned once.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"url\": \"https://your-store.example/api/massar/webhook\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "DELETE /webhook \u2014 Disable webhook delivery",
      "request": {
        "method": "DELETE",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/webhook",
        "description": ""
      }
    },
    {
      "name": "POST /webhook/test \u2014 Send a signed test event",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{baseUrl}}/webhook/test",
        "description": "Sends webhook.test to your configured receiver (external side effect). HTTP 502 means delivery failed; inspect responseStatus and error. The test can be retried by the delivery worker."
      }
    }
  ]
}
