Chilkat Online Tools

C / Postman API / Update Monitor

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *Id;
    const char *Name;
    const char *Uid;

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

    http = CkHttp_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "monitor": {
    //     "name": "Updated Monitor Name",
    //     "schedule": {
    //       "cron": "*/5 * * * *",
    //       "timezone": "America/Chicago"
    //     }
    //   }
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"monitor.name","Updated Monitor Name");
    CkJsonObject_UpdateString(json,"monitor.schedule.cron","*/5 * * * *");
    CkJsonObject_UpdateString(json,"monitor.schedule.timezone","America/Chicago");

    CkHttp_SetRequestHeader(http,"Content-Type","application/json");
    CkHttp_SetRequestHeader(http,"X-API-Key","{{postman_api_key}}");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);

    resp = CkHttp_PTextSb(http,"PUT","https://api.getpostman.com/monitors/{{monitor_uid}}",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttpResponse_Dispose(resp);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    CkHttpResponse_Dispose(resp);

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

    // {
    //   "monitor": {
    //     "id": "1e6b6e2a-c2ad-4090-b750-0df4e6624352",
    //     "name": "Updated Monitor Name",
    //     "uid": "5852-1e6b6e2a-c2ad-4090-b750-0df4e6624352"
    //   }
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Id = CkJsonObject_stringOf(jResp,"monitor.id");
    Name = CkJsonObject_stringOf(jResp,"monitor.name");
    Uid = CkJsonObject_stringOf(jResp,"monitor.uid");


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -X PUT
	-H "X-API-Key: {{postman_api_key}}"
	-H "Content-Type: application/json"
	-d '{
  "monitor": {
    "name": "Updated Monitor Name",
    "schedule": {
      "cron": "*/5 * * * *",
      "timezone": "America/Chicago"
    }
  }
}'
https://api.getpostman.com/monitors/{{monitor_uid}}

Postman Collection Item JSON

{
  "name": "Update Monitor",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"monitor\": {\n    \"name\": \"Updated Monitor Name\",\n    \"schedule\": {\n      \"cron\": \"*/5 * * * *\",\n      \"timezone\": \"America/Chicago\"\n    }\n  }\n}"
    },
    "url": {
      "raw": "https://api.getpostman.com/monitors/{{monitor_uid}}",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "monitors",
        "{{monitor_uid}}"
      ]
    },
    "description": "This endpoint allows you to update a monitor using its `uid`. Only the monitor name and its schedule can be updated.\n\nSome example `cron` values are:\n\n| Frequency                  | Cron Pattern   |\n|-----------------------|----------------|\n| Every 5 minutes       | `*/5 * * * *`  |\n| Every 30 minutes     | `*/30 * * * *` |\n| Every Hour         | `0 */1 * * *`  |\n| Every 6 Hours      | `0 */6 * * *`  |\n| Every day at 5pm    | `0 17 * * *`   |\n| Every Monday at 12pm  | `0 12 * * MON` |\n| Every weekday (Monday - Friday) at 6am | `0 6 * * MON-FRI` |\n\nNote: Currently, you can only create monitors at some limited schedules. You can head to [Postman Monitors](https://monitor.getpostman.com) to see the allowed schedules. \n\nFor more information about the format of the `timezone` value, check this [list of time zones.](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
  },
  "response": [
    {
      "name": "Monitor Updated",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"monitor\": {\n\t\t\"name\": \"Updated Monitor Name\",\n\t\t\"schedule\": {\n\t\t\t\"cron\": \"*/5 * * * *\",\n\t\t\t\"timezone\": \"America/Chicago\"\n\t\t}\n\t}\n}"
        },
        "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\": \"1e6b6e2a-c2ad-4090-b750-0df4e6624352\",\n    \"name\": \"Updated Monitor Name\",\n    \"uid\": \"5852-1e6b6e2a-c2ad-4090-b750-0df4e6624352\"\n  }\n}"
    }
  ]
}