{
  "info": {
    "name": "GrivaOne API",
    "_postman_id": "grivaone-api-v1",
    "description": "A representative Postman collection for the GrivaOne REST API (v1).\n\nSetup:\n1. Open the collection Variables tab and set `email` and `password`.\n2. Run \"Auth / Login\" — its test script saves the returned accessToken into the `token` variable automatically.\n3. Every other request inherits Bearer auth from that variable.\n\nSet `companyId` for multi-company tenants. See https://developers.grivaone.com for the full reference and https://api.grivaone.com for the complete endpoint catalogue.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{token}}", "type": "string" }]
  },
  "variable": [
    { "key": "baseUrl", "value": "https://gulfpay-production.up.railway.app/api/v1" },
    { "key": "email", "value": "you@company.com" },
    { "key": "password", "value": "your-password" },
    { "key": "token", "value": "" },
    { "key": "companyId", "value": "" }
  ],
  "item": [
    {
      "name": "Auth",
      "item": [
        {
          "name": "Login",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const body = pm.response.json();",
                  "const token = body && body.data && body.data.accessToken;",
                  "if (token) {",
                  "  pm.collectionVariables.set('token', token);",
                  "  console.log('Saved accessToken to {{token}}');",
                  "}",
                  "pm.test('200 OK', function () { pm.response.to.have.status(200); });"
                ]
              }
            }
          ],
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"{{email}}\",\n  \"password\": \"{{password}}\"\n}"
            },
            "url": { "raw": "{{baseUrl}}/auth/login", "host": ["{{baseUrl}}"], "path": ["auth", "login"] },
            "description": "Exchange email + password for an access token. Public. The test script stores data.accessToken into the collection's `token` variable."
          }
        },
        {
          "name": "Refresh",
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/json" }],
            "body": { "mode": "raw", "raw": "{\n  \"refreshToken\": \"<REFRESH_TOKEN>\"\n}" },
            "url": { "raw": "{{baseUrl}}/auth/refresh", "host": ["{{baseUrl}}"], "path": ["auth", "refresh"] }
          }
        },
        {
          "name": "Me",
          "request": {
            "method": "GET",
            "header": [],
            "url": { "raw": "{{baseUrl}}/auth/me", "host": ["{{baseUrl}}"], "path": ["auth", "me"] }
          }
        }
      ]
    },
    {
      "name": "Customers",
      "item": [
        {
          "name": "List customers",
          "request": {
            "method": "GET",
            "header": [{ "key": "X-Company-Id", "value": "{{companyId}}" }],
            "url": {
              "raw": "{{baseUrl}}/customers?page=1&limit=20",
              "host": ["{{baseUrl}}"],
              "path": ["customers"],
              "query": [
                { "key": "page", "value": "1" },
                { "key": "limit", "value": "20" },
                { "key": "search", "value": "", "disabled": true }
              ]
            }
          }
        },
        {
          "name": "Get customer",
          "request": {
            "method": "GET",
            "header": [{ "key": "X-Company-Id", "value": "{{companyId}}" }],
            "url": { "raw": "{{baseUrl}}/customers/:id", "host": ["{{baseUrl}}"], "path": ["customers", ":id"], "variable": [{ "key": "id", "value": "cus_123" }] }
          }
        },
        {
          "name": "Create customer",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-Company-Id", "value": "{{companyId}}" },
              { "key": "Idempotency-Key", "value": "{{$guid}}" }
            ],
            "body": { "mode": "raw", "raw": "{\n  \"name\": \"Acme Trading LLC\",\n  \"email\": \"ap@acme.example\"\n}" },
            "url": { "raw": "{{baseUrl}}/customers", "host": ["{{baseUrl}}"], "path": ["customers"] },
            "description": "The Idempotency-Key uses Postman's dynamic {{$guid}} so each send is a distinct operation; reuse a fixed value to test replay (409 idempotentReplay)."
          }
        }
      ]
    },
    {
      "name": "Items",
      "item": [
        {
          "name": "List items",
          "request": {
            "method": "GET",
            "header": [{ "key": "X-Company-Id", "value": "{{companyId}}" }],
            "url": {
              "raw": "{{baseUrl}}/items?page=1&limit=20",
              "host": ["{{baseUrl}}"],
              "path": ["items"],
              "query": [
                { "key": "page", "value": "1" },
                { "key": "limit", "value": "20" }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Sales invoices",
      "item": [
        {
          "name": "List sales invoices",
          "request": {
            "method": "GET",
            "header": [{ "key": "X-Company-Id", "value": "{{companyId}}" }],
            "url": { "raw": "{{baseUrl}}/sales-invoices?page=1&limit=20", "host": ["{{baseUrl}}"], "path": ["sales-invoices"], "query": [{ "key": "page", "value": "1" }, { "key": "limit", "value": "20" }] }
          }
        },
        {
          "name": "Create sales invoice",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-Company-Id", "value": "{{companyId}}" },
              { "key": "Idempotency-Key", "value": "{{$guid}}" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"customerId\": \"cus_123\",\n  \"date\": \"2026-09-07\",\n  \"lines\": [\n    { \"itemId\": \"itm_1\", \"quantity\": 10, \"unitPrice\": 25.00, \"taxRate\": 15 }\n  ]\n}"
            },
            "url": { "raw": "{{baseUrl}}/sales-invoices", "host": ["{{baseUrl}}"], "path": ["sales-invoices"] }
          }
        },
        {
          "name": "Record payment",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" },
              { "key": "X-Company-Id", "value": "{{companyId}}" },
              { "key": "Idempotency-Key", "value": "{{$guid}}" }
            ],
            "body": { "mode": "raw", "raw": "{\n  \"amount\": 287.50,\n  \"date\": \"2026-09-07\",\n  \"method\": \"Cash\"\n}" },
            "url": { "raw": "{{baseUrl}}/sales-invoices/:id/record-payment", "host": ["{{baseUrl}}"], "path": ["sales-invoices", ":id", "record-payment"], "variable": [{ "key": "id", "value": "inv_123" }] }
          }
        }
      ]
    }
  ]
}
