Chilkat Online Tools

unicodeC / Datadog API Collection / Monitors group search

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW queryParams;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    int count;
    const wchar_t *name;
    const wchar_t *group;
    int last_nodata_ts;
    int last_triggered_ts;
    int monitor_id;
    const wchar_t *monitor_name;
    const wchar_t *status;
    int j;
    int count_j;
    const wchar_t *strVal;
    int Page;
    int Page_count;
    int Per_page;
    int Total_count;
    int i;
    int count_i;

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

    http = CkHttpW_Create();

    queryParams = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(queryParams,L"query",L"tempor Ut sed velit");
    CkJsonObjectW_UpdateInt(queryParams,L"page",0);
    CkJsonObjectW_UpdateInt(queryParams,L"per_page",30);
    CkJsonObjectW_UpdateString(queryParams,L"sort",L"tempor Ut sed velit");

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://api.app.ddog-gov.com/api/v1/monitor/groups/search",queryParams);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // {
    //   "counts": {
    //     "status": [
    //       {
    //         "count": 2,
    //         "name": "OK"
    //       }
    //     ],
    //     "type": [
    //       {
    //         "count": 2,
    //         "name": "metric"
    //       }
    //     ]
    //   },
    //   "groups": [
    //     {
    //       "group": "*",
    //       "group_tags": [
    //         "*"
    //       ],
    //       "last_nodata_ts": 0,
    //       "last_triggered_ts": 1525702966,
    //       "monitor_id": 2738266,
    //       "monitor_name": "[demo] Cassandra disk usage is high on {{host.name}}",
    //       "status": "OK"
    //     },
    //     {
    //       "group": "*",
    //       "group_tags": [
    //         "*"
    //       ],
    //       "last_nodata_ts": 0,
    //       "last_triggered_ts": 1525703008,
    //       "monitor_id": 1576648,
    //       "monitor_name": "[demo] Disk usage is high on {{host.name}}",
    //       "status": "OK"
    //     }
    //   ],
    //   "metadata": {
    //     "page": 0,
    //     "page_count": 2,
    //     "per_page": 30,
    //     "total_count": 2
    //   }
    // }

    // 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.

    Page = CkJsonObjectW_IntOf(jResp,L"metadata.page");
    Page_count = CkJsonObjectW_IntOf(jResp,L"metadata.page_count");
    Per_page = CkJsonObjectW_IntOf(jResp,L"metadata.per_page");
    Total_count = CkJsonObjectW_IntOf(jResp,L"metadata.total_count");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"counts.status");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        count = CkJsonObjectW_IntOf(jResp,L"counts.status[i].count");
        name = CkJsonObjectW_stringOf(jResp,L"counts.status[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"counts.type");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        count = CkJsonObjectW_IntOf(jResp,L"counts.type[i].count");
        name = CkJsonObjectW_stringOf(jResp,L"counts.type[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"groups");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        group = CkJsonObjectW_stringOf(jResp,L"groups[i].group");
        last_nodata_ts = CkJsonObjectW_IntOf(jResp,L"groups[i].last_nodata_ts");
        last_triggered_ts = CkJsonObjectW_IntOf(jResp,L"groups[i].last_triggered_ts");
        monitor_id = CkJsonObjectW_IntOf(jResp,L"groups[i].monitor_id");
        monitor_name = CkJsonObjectW_stringOf(jResp,L"groups[i].monitor_name");
        status = CkJsonObjectW_stringOf(jResp,L"groups[i].status");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"groups[i].group_tags");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"groups[i].group_tags[j]");
            j = j + 1;
        }

        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(queryParams);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -G -d "query=tempor%20Ut%20sed%20velit"
	-d "page=0"
	-d "per_page=30"
	-d "sort=tempor%20Ut%20sed%20velit"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/monitor/groups/search

Postman Collection Item JSON

{
  "name": "Monitors group search",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/monitor/groups/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "monitor",
        "groups",
        "search"
      ],
      "query": [
        {
          "key": "query",
          "value": "tempor Ut sed velit",
          "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
        },
        {
          "key": "page",
          "value": "0",
          "description": "Page to start paginating from."
        },
        {
          "key": "per_page",
          "value": "30",
          "description": "Number of monitors to return per page."
        },
        {
          "key": "sort",
          "value": "tempor Ut sed velit",
          "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
        }
      ]
    },
    "description": "Search and filter your monitor groups details."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor/groups/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "groups",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"counts\": {\n    \"status\": [\n      {\n        \"count\": 2,\n        \"name\": \"OK\"\n      }\n    ],\n    \"type\": [\n      {\n        \"count\": 2,\n        \"name\": \"metric\"\n      }\n    ]\n  },\n  \"groups\": [\n    {\n      \"group\": \"*\",\n      \"group_tags\": [\n        \"*\"\n      ],\n      \"last_nodata_ts\": 0,\n      \"last_triggered_ts\": 1525702966,\n      \"monitor_id\": 2738266,\n      \"monitor_name\": \"[demo] Cassandra disk usage is high on {{host.name}}\",\n      \"status\": \"OK\"\n    },\n    {\n      \"group\": \"*\",\n      \"group_tags\": [\n        \"*\"\n      ],\n      \"last_nodata_ts\": 0,\n      \"last_triggered_ts\": 1525703008,\n      \"monitor_id\": 1576648,\n      \"monitor_name\": \"[demo] Disk usage is high on {{host.name}}\",\n      \"status\": \"OK\"\n    }\n  ],\n  \"metadata\": {\n    \"page\": 0,\n    \"page_count\": 2,\n    \"per_page\": 30,\n    \"total_count\": 2\n  }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor/groups/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "groups",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor/groups/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "groups",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/monitor/groups/search?query=tempor Ut sed velit&page=0&per_page=30&sort=tempor Ut sed velit",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "monitor",
            "groups",
            "search"
          ],
          "query": [
            {
              "key": "query",
              "value": "tempor Ut sed velit",
              "description": "After entering a search query in your [Manage Monitor page][1] use the query parameter value in the\nURL of the page as value for this parameter. Consult the dedicated [manage monitor documentation][2]\npage to learn more.\n\nThe query can contain any number of space-separated monitor attributes, for instance `query=\"type:metric status:alert\"`.\n\n[1]: https://app.datadoghq.com/monitors/manage\n[2]: /monitors/manage/#find-the-monitors"
            },
            {
              "key": "page",
              "value": "0",
              "description": "Page to start paginating from."
            },
            {
              "key": "per_page",
              "value": "30",
              "description": "Number of monitors to return per page."
            },
            {
              "key": "sort",
              "value": "tempor Ut sed velit",
              "description": "String for sort order, composed of field and sort order separate by a comma, for example `name,asc`. Supported sort directions: `asc`, `desc`. Supported fields:\n\n* `name`\n* `status`\n* `tags`"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    }
  ]
}