{
  "info": {
    "name": "Teria Sandbox Telemetry — V3",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "description": "Use V3 to submit individual attempt outcomes or batches of telemetry from your institution.\n\nImport the separate sandbox environment and supply your private credential and onboarding identifiers. Do not sync or share credentials. Examples generate test observations only. Before using a credential for a different customer account or institution, clear stored payloads. Credential rotation within the same account and institution preserves stored observations. Payloads are generated once and retained in collection variables so Send retries the same immutable events. Clear single_outcome_json or batch_outcomes_json to create a new example; do not edit a stored event under its existing ID. Events older than seven days require manual handling. Verify your institution credential with GET /v1/telemetry/connection before sending telemetry."
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{ingestion_credential}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "single_outcome_json",
      "value": ""
    },
    {
      "key": "batch_outcomes_json",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "Verify connection",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.environment.get('base_url') !== 'https://sandbox.teriahq.com') { pm.execution.skipRequest(); throw new Error('This collection only sends to the Teria sandbox.'); }",
              "if (!pm.environment.get('ingestion_credential')) { pm.execution.skipRequest(); throw new Error('Set your private ingestion_credential first.'); }"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": "https://sandbox.teriahq.com/v1/telemetry/connection",
        "description": "Verify your institution credential with GET /v1/telemetry/connection before sending telemetry."
      }
    },
    {
      "name": "Submit one outcome",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.environment.get('base_url') !== 'https://sandbox.teriahq.com') { pm.execution.skipRequest(); throw new Error('This collection only sends to the Teria sandbox.'); }",
              "for (const name of ['destination_institution_id', 'ingestion_credential']) {",
              "  if (!pm.environment.get(name)) { pm.execution.skipRequest(); throw new Error('Set ' + name + ' in your private sandbox environment before sending.'); }",
              "}",
              "const storageKey = 'single_outcome_json';",
              "if (!pm.collectionVariables.get(storageKey)) {",
              "  const now = new Date().toISOString();",
              "  const uuid = () => pm.variables.replaceIn('{{$guid}}');",
              "  const events = Array.from({ length: 1 }, (_, index) => ({",
              "    event_id: uuid(), transaction_id: 'sandbox-' + uuid(), attempt_id: 'sandbox-' + uuid(),",
              "    destination_institution_id: pm.environment.get('destination_institution_id'),",
              "    payment_capability: 'interbank_transfer', switch_id: 'nibss', nibss_technology: 'nip',",
              "    kind: index === 0 ? 'attempt_succeeded' : 'attempt_timed_out', occurred_at: now,",
              "  }));",
              "  pm.collectionVariables.set(storageKey, JSON.stringify({ schema_version: 3, batch_id: uuid(),",
              "    sent_at: now, events }, null, 2));",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "https://sandbox.teriahq.com/v1/telemetry/batches",
        "body": {
          "mode": "raw",
          "raw": "{{single_outcome_json}}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "description": "Use V3 to submit individual attempt outcomes or batches of telemetry from your institution. Replace directory IDs before first send. Each subsequent Send retries the stored immutable payload. A 202 means durable acceptance; check processing separately."
      }
    },
    {
      "name": "Submit a batch of outcomes",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.environment.get('base_url') !== 'https://sandbox.teriahq.com') { pm.execution.skipRequest(); throw new Error('This collection only sends to the Teria sandbox.'); }",
              "for (const name of ['destination_institution_id', 'ingestion_credential']) {",
              "  if (!pm.environment.get(name)) { pm.execution.skipRequest(); throw new Error('Set ' + name + ' in your private sandbox environment before sending.'); }",
              "}",
              "const storageKey = 'batch_outcomes_json';",
              "if (!pm.collectionVariables.get(storageKey)) {",
              "  const now = new Date().toISOString();",
              "  const uuid = () => pm.variables.replaceIn('{{$guid}}');",
              "  const events = Array.from({ length: 2 }, (_, index) => ({",
              "    event_id: uuid(), transaction_id: 'sandbox-' + uuid(), attempt_id: 'sandbox-' + uuid(),",
              "    destination_institution_id: pm.environment.get('destination_institution_id'),",
              "    payment_capability: 'interbank_transfer', switch_id: 'nibss', nibss_technology: 'nip',",
              "    kind: index === 0 ? 'attempt_succeeded' : 'attempt_timed_out', occurred_at: now,",
              "  }));",
              "  pm.collectionVariables.set(storageKey, JSON.stringify({ schema_version: 3, batch_id: uuid(),",
              "    sent_at: now, events }, null, 2));",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "https://sandbox.teriahq.com/v1/telemetry/batches",
        "body": {
          "mode": "raw",
          "raw": "{{batch_outcomes_json}}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "description": "Use V3 to submit individual attempt outcomes or batches of telemetry from your institution. Replace directory IDs before first send. Each subsequent Send retries the stored immutable payload. A 202 means durable acceptance; check processing separately."
      }
    }
  ]
}
