{
  "info": {
    "name": "Barcode Price History | Read a completed run",
    "description": "Set apifyToken and runId in a private environment. These requests read a completed Apify run and its dataset.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apifyToken}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "apiBase",
      "value": "https://api.apify.com/v2"
    }
  ],
  "item": [
    {
      "name": "Read the completed run",
      "request": {
        "method": "GET",
        "url": "{{apiBase}}/actor-runs/{{runId}}"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('The run is accessible', () => pm.response.to.have.status(200));",
              "pm.test('The run succeeded and has a dataset', () => {",
              "  const run = pm.response.json().data;",
              "  pm.expect(run.status).to.eql('SUCCEEDED');",
              "  pm.expect(run.defaultDatasetId).to.be.a('string');",
              "  pm.collectionVariables.set('datasetId', run.defaultDatasetId);",
              "});"
            ]
          }
        }
      ]
    },
    {
      "name": "Read the price observations",
      "request": {
        "method": "GET",
        "url": "{{apiBase}}/datasets/{{datasetId}}/items?format=json&clean=true&limit=80"
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('The restricted dataset is accessible', () => pm.response.to.have.status(200));",
              "pm.test('Every result has a barcode and a numeric price', () => {",
              "  const rows = pm.response.json();",
              "  pm.expect(rows).to.be.an('array');",
              "  rows.forEach(row => { pm.expect(row.gtin).to.match(/^\\d{8,14}$/); pm.expect(row.price).to.be.a('number'); });",
              "});"
            ]
          }
        }
      ]
    }
  ]
}
