Changes feed

Changes feed is the best option for synchronization with the SAS monitoring database. Let’s use feed=changes to get monitors sorted by changes ascending:

GET /api/2.5/monitorings?feed=changes&limit=3&opt_fields=reasons HTTP/1.0
Authorization: Basic YnJva2VyOmJyb2tlcg==
Host: audit-api-sandbox.prozorro.gov.ua

Response: 200 OK
Content-Type: application/json
Set-Cookie: SESSION=eyJvcGVyYXRpb25fdGltZSI6IHsiJHRpbWVzdGFtcCI6IHsidCI6IDE3NjIyNTM5OTEsICJpIjogMzZ9fSwgImNsdXN0ZXJfdGltZSI6IHsiY2x1c3RlclRpbWUiOiB7IiR0aW1lc3RhbXAiOiB7InQiOiAxNzYyMjUzOTkxLCAiaSI6IDM2fX0sICJzaWduYXR1cmUiOiB7Imhhc2giOiB7IiRiaW5hcnkiOiB7ImJhc2U2NCI6ICJ0SkVPdFFtYm03REhFTENuQTFjMHgxL1RQeE09IiwgInN1YlR5cGUiOiAiMDAifX0sICJrZXlJZCI6IDc1NjY2Mjk2Njg0Njg1NTU3ODN9fX0=; Path=/
X-Content-Type-Options: nosniff
{
  "data": [
    {
      "reasons": [
        "indicator"
      ],
      "dateModified": "2018-01-01T02:00:01+02:00",
      "id": "98e6dfb91a774304a13f1318cc3aa7f5"
    },
    {
      "reasons": [
        "indicator"
      ],
      "dateModified": "2018-01-01T02:00:02+02:00",
      "id": "25ddf7194b7f490b8e0b36aa995869be"
    },
    {
      "reasons": [
        "indicator"
      ],
      "dateModified": "2018-01-01T02:00:03+02:00",
      "id": "c21408cf32824b098f59c9681d33f68a"
    }
  ],
  "next_page": {
    "offset": 1762253991.435,
    "path": "/api/2.5/monitorings?limit=3&opt_fields=reasons&offset=1762253991.435",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?limit=3&opt_fields=reasons&offset=1762253991.435"
  }
}

The response contains next_page. Every time we use it, we get monitors with changes that haven’t been synced yet.

GET /api/2.5/monitorings?limit=3&opt_fields=reasons&offset=1762253991.435 HTTP/1.0
Authorization: Basic YnJva2VyOmJyb2tlcg==
Host: audit-api-sandbox.prozorro.gov.ua

Response: 200 OK
Content-Type: application/json
Set-Cookie: SESSION=eyJvcGVyYXRpb25fdGltZSI6IHsiJHRpbWVzdGFtcCI6IHsidCI6IDE3NjIyNTM5OTEsICJpIjogMzZ9fSwgImNsdXN0ZXJfdGltZSI6IHsiY2x1c3RlclRpbWUiOiB7IiR0aW1lc3RhbXAiOiB7InQiOiAxNzYyMjUzOTkxLCAiaSI6IDM2fX0sICJzaWduYXR1cmUiOiB7Imhhc2giOiB7IiRiaW5hcnkiOiB7ImJhc2U2NCI6ICJ0SkVPdFFtYm03REhFTENuQTFjMHgxL1RQeE09IiwgInN1YlR5cGUiOiAiMDAifX0sICJrZXlJZCI6IDc1NjY2Mjk2Njg0Njg1NTU3ODN9fX0=; Path=/
X-Content-Type-Options: nosniff
{
  "data": [
    {
      "reasons": [
        "indicator"
      ],
      "dateModified": "2018-01-01T02:00:04+02:00",
      "id": "63d2d46084ef4f4a9462aec3305e6cb6"
    },
    {
      "reasons": [
        "indicator"
      ],
      "dateModified": "2018-01-01T02:00:05+02:00",
      "id": "a79d875188b34061bd1d88e3ecf1383e"
    }
  ],
  "next_page": {
    "offset": 1762253991.54,
    "path": "/api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons"
  },
  "prev_page": {
    "offset": 1762253991.489,
    "path": "/api/2.5/monitorings?offset=1762253991.489&limit=3&opt_fields=reasons&descending=1",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.489&limit=3&opt_fields=reasons&descending=1"
  }
}

Let’s proceed to the last page:

GET /api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons HTTP/1.0
Authorization: Basic YnJva2VyOmJyb2tlcg==
Host: audit-api-sandbox.prozorro.gov.ua

Response: 200 OK
Content-Type: application/json
Set-Cookie: SESSION=eyJvcGVyYXRpb25fdGltZSI6IHsiJHRpbWVzdGFtcCI6IHsidCI6IDE3NjIyNTM5OTEsICJpIjogMzZ9fSwgImNsdXN0ZXJfdGltZSI6IHsiY2x1c3RlclRpbWUiOiB7IiR0aW1lc3RhbXAiOiB7InQiOiAxNzYyMjUzOTkxLCAiaSI6IDM2fX0sICJzaWduYXR1cmUiOiB7Imhhc2giOiB7IiRiaW5hcnkiOiB7ImJhc2U2NCI6ICJ0SkVPdFFtYm03REhFTENuQTFjMHgxL1RQeE09IiwgInN1YlR5cGUiOiAiMDAifX0sICJrZXlJZCI6IDc1NjY2Mjk2Njg0Njg1NTU3ODN9fX0=; Path=/
X-Content-Type-Options: nosniff
{
  "data": [],
  "next_page": {
    "offset": 1762253991.54,
    "path": "/api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons"
  },
  "prev_page": {
    "offset": 1762253991.54,
    "path": "/api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons&descending=1",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons&descending=1"
  }
}

Since there are no results, let’s wait before we try it again:

GET /api/2.5/monitorings?offset=1762253991.54&limit=3&opt_fields=reasons HTTP/1.0
Authorization: Basic YnJva2VyOmJyb2tlcg==
Host: audit-api-sandbox.prozorro.gov.ua

Response: 200 OK
Content-Type: application/json
Set-Cookie: SESSION=eyJvcGVyYXRpb25fdGltZSI6IHsiJHRpbWVzdGFtcCI6IHsidCI6IDE3NjIyNTM5OTEsICJpIjogNDN9fSwgImNsdXN0ZXJfdGltZSI6IHsiY2x1c3RlclRpbWUiOiB7IiR0aW1lc3RhbXAiOiB7InQiOiAxNzYyMjUzOTkxLCAiaSI6IDQzfX0sICJzaWduYXR1cmUiOiB7Imhhc2giOiB7IiRiaW5hcnkiOiB7ImJhc2U2NCI6ICJ0SkVPdFFtYm03REhFTENuQTFjMHgxL1RQeE09IiwgInN1YlR5cGUiOiAiMDAifX0sICJrZXlJZCI6IDc1NjY2Mjk2Njg0Njg1NTU3ODN9fX0=; Path=/
X-Content-Type-Options: nosniff
{
  "data": [
    {
      "reasons": [
        "indicator"
      ],
      "dateModified": "2018-01-01T02:00:06+02:00",
      "id": "943956c91fdf410e988ce95cc3c3a0f9"
    }
  ],
  "next_page": {
    "offset": 1762253991.633,
    "path": "/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons"
  },
  "prev_page": {
    "offset": 1762253991.633,
    "path": "/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons&descending=1",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons&descending=1"
  }
}

And the next page can either be empty again

GET /api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons HTTP/1.0
Authorization: Basic YnJva2VyOmJyb2tlcg==
Host: audit-api-sandbox.prozorro.gov.ua

Response: 200 OK
Content-Type: application/json
Set-Cookie: SESSION=eyJvcGVyYXRpb25fdGltZSI6IHsiJHRpbWVzdGFtcCI6IHsidCI6IDE3NjIyNTM5OTEsICJpIjogNDN9fSwgImNsdXN0ZXJfdGltZSI6IHsiY2x1c3RlclRpbWUiOiB7IiR0aW1lc3RhbXAiOiB7InQiOiAxNzYyMjUzOTkxLCAiaSI6IDQzfX0sICJzaWduYXR1cmUiOiB7Imhhc2giOiB7IiRiaW5hcnkiOiB7ImJhc2U2NCI6ICJ0SkVPdFFtYm03REhFTENuQTFjMHgxL1RQeE09IiwgInN1YlR5cGUiOiAiMDAifX0sICJrZXlJZCI6IDc1NjY2Mjk2Njg0Njg1NTU3ODN9fX0=; Path=/
X-Content-Type-Options: nosniff
{
  "data": [],
  "next_page": {
    "offset": 1762253991.633,
    "path": "/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons"
  },
  "prev_page": {
    "offset": 1762253991.633,
    "path": "/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons&descending=1",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons&descending=1"
  }
}

or contain a monitor with new changes

GET /api/2.5/monitorings?offset=1762253991.633&limit=3&opt_fields=reasons HTTP/1.0
Authorization: Basic YnJva2VyOmJyb2tlcg==
Host: audit-api-sandbox.prozorro.gov.ua

Response: 200 OK
Content-Type: application/json
Set-Cookie: SESSION=eyJvcGVyYXRpb25fdGltZSI6IHsiJHRpbWVzdGFtcCI6IHsidCI6IDE3NjIyNTM5OTEsICJpIjogNTB9fSwgImNsdXN0ZXJfdGltZSI6IHsiY2x1c3RlclRpbWUiOiB7IiR0aW1lc3RhbXAiOiB7InQiOiAxNzYyMjUzOTkxLCAiaSI6IDUwfX0sICJzaWduYXR1cmUiOiB7Imhhc2giOiB7IiRiaW5hcnkiOiB7ImJhc2U2NCI6ICJ0SkVPdFFtYm03REhFTENuQTFjMHgxL1RQeE09IiwgInN1YlR5cGUiOiAiMDAifX0sICJrZXlJZCI6IDc1NjY2Mjk2Njg0Njg1NTU3ODN9fX0=; Path=/
X-Content-Type-Options: nosniff
{
  "data": [
    {
      "reasons": [
        "indicator"
      ],
      "dateModified": "2018-01-01T02:00:07+02:00",
      "id": "2fdf48b54cea4839b5e89ec1dd8dca63"
    }
  ],
  "next_page": {
    "offset": 1762253991.706,
    "path": "/api/2.5/monitorings?offset=1762253991.706&limit=3&opt_fields=reasons",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.706&limit=3&opt_fields=reasons"
  },
  "prev_page": {
    "offset": 1762253991.706,
    "path": "/api/2.5/monitorings?offset=1762253991.706&limit=3&opt_fields=reasons&descending=1",
    "uri": "http://audit-api-sandbox.prozorro.gov.ua/api/2.5/monitorings?offset=1762253991.706&limit=3&opt_fields=reasons&descending=1"
  }
}