Chilkat Online Tools

delphiAx / Postman API / Single Monitor

Back to Collection Items

var
http: TChilkatHttp;
success: Integer;
sbResponseBody: TChilkatStringBuilder;
jResp: TChilkatJsonObject;
respStatusCode: Integer;
email: WideString;
Id: WideString;
Name: WideString;
Uid: WideString;
Owner: WideString;
CollectionUid: WideString;
EnvironmentUid: WideString;
StrictSSL: Integer;
FollowRedirects: Integer;
RequestTimeout: Integer;
RequestDelay: Integer;
Cron: WideString;
Timezone: WideString;
NextRun: WideString;
Status: WideString;
StartedAt: WideString;
FinishedAt: WideString;
Total: Integer;
Failed: Integer;
RequestsTotal: Integer;
i: Integer;
count_i: Integer;

begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

http := TChilkatHttp.Create(Self);

http.SetRequestHeader('X-API-Key','{{postman_api_key}}');

sbResponseBody := TChilkatStringBuilder.Create(Self);
success := http.QuickGetSb('https://api.getpostman.com/monitors/{{monitor_uid}}',sbResponseBody.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(http.LastErrorText);
    Exit;
  end;

jResp := TChilkatJsonObject.Create(Self);
jResp.LoadSb(sbResponseBody.ControlInterface);
jResp.EmitCompact := 0;

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(jResp.Emit());

respStatusCode := http.LastStatus;
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(http.LastHeader);
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "monitor": {
//     "id": "1e6b6cc1-c760-48e0-968f-4bfaeeae9af1",
//     "name": "Postman Echo Monitor",
//     "uid": "5852-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1",
//     "owner": "5852",
//     "collectionUid": "5852-8d05dd85-222c-1452-553b-e76a531b71ed",
//     "environmentUid": "5851-8d05dd85-222c-1452-553b-e76a531b71ed",
//     "options": {
//       "strictSSL": true,
//       "followRedirects": true,
//       "requestTimeout": 3000,
//       "requestDelay": 0
//     },
//     "notifications": {
//       "onError": [
//         {
//           "email": "john.appleseed@example.com"
//         }
//       ],
//       "onFailure": [
//         {
//           "email": "john.appleseed@example.com"
//         }
//       ]
//     },
//     "distribution": [
//     ],
//     "schedule": {
//       "cron": "0 0 * * * *",
//       "timezone": "Asia/Calcutta",
//       "nextRun": "2016-11-30T09:30:00.000Z"
//     },
//     "lastRun": {
//       "status": "failed",
//       "startedAt": "2020-03-25T15:45:29.218Z",
//       "finishedAt": "2020-03-25T15:45:31.340Z",
//       "stats": {
//         "assertions": {
//           "total": 8,
//           "failed": 1
//         },
//         "requests": {
//           "total": 4
//         }
//       }
//     }
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

Id := jResp.StringOf('monitor.id');
Name := jResp.StringOf('monitor.name');
Uid := jResp.StringOf('monitor.uid');
Owner := jResp.StringOf('monitor.owner');
CollectionUid := jResp.StringOf('monitor.collectionUid');
EnvironmentUid := jResp.StringOf('monitor.environmentUid');
StrictSSL := jResp.BoolOf('monitor.options.strictSSL');
FollowRedirects := jResp.BoolOf('monitor.options.followRedirects');
RequestTimeout := jResp.IntOf('monitor.options.requestTimeout');
RequestDelay := jResp.IntOf('monitor.options.requestDelay');
Cron := jResp.StringOf('monitor.schedule.cron');
Timezone := jResp.StringOf('monitor.schedule.timezone');
NextRun := jResp.StringOf('monitor.schedule.nextRun');
Status := jResp.StringOf('monitor.lastRun.status');
StartedAt := jResp.StringOf('monitor.lastRun.startedAt');
FinishedAt := jResp.StringOf('monitor.lastRun.finishedAt');
Total := jResp.IntOf('monitor.lastRun.stats.assertions.total');
Failed := jResp.IntOf('monitor.lastRun.stats.assertions.failed');
RequestsTotal := jResp.IntOf('monitor.lastRun.stats.requests.total');
i := 0;
count_i := jResp.SizeOfArray('monitor.notifications.onError');
while i < count_i do
  begin
    jResp.I := i;
    email := jResp.StringOf('monitor.notifications.onError[i].email');
    i := i + 1;
  end;

i := 0;
count_i := jResp.SizeOfArray('monitor.notifications.onFailure');
while i < count_i do
  begin
    jResp.I := i;
    email := jResp.StringOf('monitor.notifications.onFailure[i].email');
    i := i + 1;
  end;

i := 0;
count_i := jResp.SizeOfArray('monitor.distribution');
while i < count_i do
  begin
    jResp.I := i;
    i := i + 1;
  end;

Curl Command

curl -X GET
	-H "X-API-Key: {{postman_api_key}}"
https://api.getpostman.com/monitors/{{monitor_uid}}

Postman Collection Item JSON

{
  "name": "Single Monitor",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.getpostman.com/monitors/{{monitor_uid}}",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "monitors",
        "{{monitor_uid}}"
      ]
    },
    "description": "This endpoint fetches you basic information about the monitor using its `uid`.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
    {
      "name": "Monitor Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/monitors/{{monitor_uid}}",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "monitors",
            "{{monitor_uid}}"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "name": "Content-Type",
          "description": {
            "content": "",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
        {
          "expires": "Invalid Date",
          "hostOnly": false,
          "httpOnly": false,
          "domain": "getpostman.com",
          "path": "/",
          "secure": false,
          "session": false,
          "value": "yes",
          "key": "getpostmanlogin"
        },
        {
          "expires": "Invalid Date",
          "hostOnly": false,
          "httpOnly": false,
          "domain": "getpostman.com",
          "path": "/",
          "secure": false,
          "session": false,
          "value": "0e9f9b1f3e7218e7fd625cca14597bc771064a433bdd75b5a40196cef86c3fa29d483358e0b254b0a097ac305b132ec8481e2c5b835663fbed3bbb93b5a747cf8776efe85650e29a8e5f0a63906480e5b9e5a9860bef703234812ce9f65ea6dcbc099ac952d1c36338e2d192a793b82a1d8a2dd6dd031f831c08805a9e7ea1f55d46c54cf6ecaecbac84ddf581c8a267a116c0d6d935f19171bce93c6e040c0bd49fc1325bdb8929914548d7c0cae78796aba4073dc9ab63194a90e430919d8757c7ccb7b4dffc61b9cd4a748edc88d0b4ba727c83ea1af546908ff63a1e2ee9784a7b9af2f61997e0dd34adcb479151d11d0e8d67ba76050d55c7bbb88f2f700e14f848f6b929b441869fba53436eb7983660d0e4af82aa0dc5c47dddf974599280179889c03c3e38212eaa8270c641298f0a49b923ed3d04d61e2c6c25844b67df9e4814d378b440e8124e429dc292a147038a57c03e8b8ece700b376fcf8e002dca35142f97b5f49144e2f7477b99d767dff12bb37dd846419051bdaa4c6d931545a5df09bda8a80a336585e5d6ba44f087607512344f91321a359dc150cb411600fbf0d974f63116046d681d3f82a16e50e3bb69c463430e284f64e007f354a9ed4a2afdb27caad0414d451875ec78ea98924e32d8f881eb2c260b348e00baf782",
          "key": "postman.sid"
        }
      ],
      "body": "{\n  \"error\": {\n    \"name\": \"instanceNotFoundError\",\n    \"message\": \"The specified monitor does not exist.\"\n  }\n}"
    },
    {
      "name": "Successful Response",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.getpostman.com/monitors/{{monitor_uid}}",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "monitors",
            "{{monitor_uid}}"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json",
          "name": "Content-Type",
          "description": {
            "content": "",
            "type": "text/plain"
          }
        }
      ],
      "cookie": [
        {
          "expires": "Invalid Date",
          "hostOnly": false,
          "httpOnly": false,
          "domain": "getpostman.com",
          "path": "/",
          "secure": false,
          "session": false,
          "value": "yes",
          "key": "getpostmanlogin"
        },
        {
          "expires": "Invalid Date",
          "hostOnly": false,
          "httpOnly": false,
          "domain": "getpostman.com",
          "path": "/",
          "secure": false,
          "session": false,
          "value": "0e9f9b1f3e7218e7fd625cca14597bc771064a433bdd75b5a40196cef86c3fa29d483358e0b254b0a097ac305b132ec8481e2c5b835663fbed3bbb93b5a747cf8776efe85650e29a8e5f0a63906480e5b9e5a9860bef703234812ce9f65ea6dcbc099ac952d1c36338e2d192a793b82a1d8a2dd6dd031f831c08805a9e7ea1f55d46c54cf6ecaecbac84ddf581c8a267a116c0d6d935f19171bce93c6e040c0bd49fc1325bdb8929914548d7c0cae78796aba4073dc9ab63194a90e430919d8757c7ccb7b4dffc61b9cd4a748edc88d0b4ba727c83ea1af546908ff63a1e2ee9784a7b9af2f61997e0dd34adcb479151d11d0e8d67ba76050d55c7bbb88f2f700e14f848f6b929b441869fba53436eb7983660d0e4af82aa0dc5c47dddf974599280179889c03c3e38212eaa8270c641298f0a49b923ed3d04d61e2c6c25844b67df9e4814d378b440e8124e429dc292a147038a57c03e8b8ece700b376fcf8e002dca35142f97b5f49144e2f7477b99d767dff12bb37dd846419051bdaa4c6d931545a5df09bda8a80a336585e5d6ba44f087607512344f91321a359dc150cb411600fbf0d974f63116046d681d3f82a16e50e3bb69c463430e284f64e007f354a9ed4a2afdb27caad0414d451875ec78ea98924e32d8f881eb2c260b348e00baf782",
          "key": "postman.sid"
        }
      ],
      "body": "{\n \"monitor\": {\n  \"id\": \"1e6b6cc1-c760-48e0-968f-4bfaeeae9af1\",\n  \"name\": \"Postman Echo Monitor\",\n  \"uid\": \"5852-1e6b6cc1-c760-48e0-968f-4bfaeeae9af1\",\n  \"owner\": \"5852\",\n  \"collectionUid\": \"5852-8d05dd85-222c-1452-553b-e76a531b71ed\",\n  \"environmentUid\": \"5851-8d05dd85-222c-1452-553b-e76a531b71ed\",\n  \"options\": {\n   \"strictSSL\": true,\n   \"followRedirects\": true,\n   \"requestTimeout\": 3000,\n   \"requestDelay\": 0\n  },\n  \"notifications\": {\n   \"onError\": [\n    {\n     \"email\": \"john.appleseed@example.com\"\n    }\n   ],\n   \"onFailure\": [\n    {\n     \"email\": \"john.appleseed@example.com\"\n    }\n   ]\n  },\n  \"distribution\": [],\n  \"schedule\": {\n   \"cron\": \"0 0 * * * *\",\n   \"timezone\": \"Asia/Calcutta\",\n   \"nextRun\": \"2016-11-30T09:30:00.000Z\"\n  },\n  \"lastRun\": {\n   \"status\": \"failed\",\n   \"startedAt\": \"2020-03-25T15:45:29.218Z\",\n   \"finishedAt\": \"2020-03-25T15:45:31.340Z\",\n   \"stats\": {\n    \"assertions\": {\n     \"total\": 8,\n     \"failed\": 1\n    },\n    \"requests\": {\n     \"total\": 4\n    }\n   }\n  }\n }\n}"
    }
  ]
}