{
  "info": {
    "name": "Travlix Travel API v1",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Set api_key and api_secret (collection variables, keep secret in 'Current value' only). Requests are signed by the collection pre-request script."
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://api.travlix.com"
    },
    {
      "key": "api_key",
      "value": ""
    },
    {
      "key": "api_secret",
      "value": ""
    },
    {
      "key": "departure_date",
      "value": "2026-12-15"
    },
    {
      "key": "offer_id",
      "value": ""
    },
    {
      "key": "booking_id",
      "value": ""
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Travlix HMAC signing (runs before every request in this collection)",
          "const key = pm.collectionVariables.get('api_key'), secret = pm.collectionVariables.get('api_secret');",
          "const url = pm.request.url;",
          "const path = pm.variables.replaceIn('/' + url.path.join('/'));",
          "const query = url.query && url.query.count() ? url.getQueryString() : '';",
          "const body = (pm.request.method !== 'GET' && pm.request.body && pm.request.body.raw) ? pm.variables.replaceIn(pm.request.body.raw) : '';",
          "const ts = Math.floor(Date.now() / 1000).toString();",
          "const nonce = CryptoJS.lib.WordArray.random(16).toString();",
          "const sts = [pm.request.method, path, pm.variables.replaceIn(query), ts, nonce, CryptoJS.SHA256(body).toString()].join('\\n');",
          "pm.request.headers.upsert({key: 'X-Api-Key', value: key});",
          "pm.request.headers.upsert({key: 'X-Timestamp', value: ts});",
          "pm.request.headers.upsert({key: 'X-Nonce', value: nonce});",
          "pm.request.headers.upsert({key: 'X-Signature', value: CryptoJS.HmacSHA256(sts, secret).toString()});",
          "if (['book','ticket','cancel'].some(s => path.endsWith('/flight/' + s)) && !pm.request.headers.has('Idempotency-Key')) {",
          "  pm.request.headers.upsert({key: 'Idempotency-Key', value: CryptoJS.lib.WordArray.random(12).toString()});",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Ping",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/ping",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "ping"
          ]
        }
      }
    },
    {
      "name": "Wallet balance",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/wallet/balance",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "wallet",
            "balance"
          ]
        }
      }
    },
    {
      "name": "Wallet ledger",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/wallet/ledger?page=1&per_page=20",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "wallet",
            "ledger"
          ],
          "query": [
            {
              "key": "page",
              "value": "1"
            },
            {
              "key": "per_page",
              "value": "20"
            }
          ]
        }
      }
    },
    {
      "name": "Flight search",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/flight/search",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "flight",
            "search"
          ]
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"origin\": \"DEL\",\n  \"destination\": \"BOM\",\n  \"departure_date\": \"{{departure_date}}\",\n  \"adults\": 1,\n  \"children\": 0,\n  \"infants\": 0,\n  \"cabin\": \"economy\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const j = pm.response.json(); if (j.success && j.data.offers.length) pm.collectionVariables.set('offer_id', j.data.offers[0].offer_id);"
            ]
          }
        }
      ]
    },
    {
      "name": "Fare quote",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/flight/fare-quote",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "flight",
            "fare-quote"
          ]
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"offer_id\": \"{{offer_id}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "Book",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/flight/book",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "flight",
            "book"
          ]
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"offer_id\": \"{{offer_id}}\",\n  \"passengers\": [\n    {\n      \"type\": \"adult\",\n      \"title\": \"MR\",\n      \"first_name\": \"Rahul\",\n      \"last_name\": \"Sharma\",\n      \"gender\": \"M\"\n    }\n  ],\n  \"contact\": {\n    \"email\": \"rahul@example.com\",\n    \"phone\": \"+919876543210\"\n  },\n  \"client_reference\": \"POSTMAN-1\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const j = pm.response.json(); if (j.data && j.data.booking_id) pm.collectionVariables.set('booking_id', j.data.booking_id);"
            ]
          }
        }
      ]
    },
    {
      "name": "Ticket",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/flight/ticket",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "flight",
            "ticket"
          ]
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"booking_id\": \"{{booking_id}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "Booking status",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/flight/booking/{{booking_id}}",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "flight",
            "booking",
            "{{booking_id}}"
          ]
        }
      }
    },
    {
      "name": "Cancel",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/v1/flight/cancel",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "v1",
            "flight",
            "cancel"
          ]
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"booking_id\": \"{{booking_id}}\",\n  \"reason\": \"Customer request\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    }
  ]
}