Chilkat Online Tools

unicodeC / Datadog API Collection / Get an API test's latest results summaries

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;
    const wchar_t *check_time;
    const wchar_t *probe_dc;
    BOOL Passed;
    const wchar_t *v_Dns;
    const wchar_t *Download;
    const wchar_t *FirstByte;
    const wchar_t *Handshake;
    const wchar_t *Redirect;
    const wchar_t *Ssl;
    const wchar_t *Tcp;
    const wchar_t *Total;
    const wchar_t *Wait;
    const wchar_t *result_id;
    int status;
    int last_timestamp_fetched;
    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_UpdateInt(queryParams,L"from_ts",-62147425);
    CkJsonObjectW_UpdateInt(queryParams,L"to_ts",-62147425);
    CkJsonObjectW_UpdateString(queryParams,L"probe_dc",L"dolor cillum in");
    CkJsonObjectW_UpdateString(queryParams,L"probe_dc",L"proident");

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

    resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://api.app.ddog-gov.com/api/v1/synthetics/tests/:public_id/results",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)

    // {
    //   "last_timestamp_fetched": -96513461,
    //   "results": [
    //     {
    //       "check_time": -32755115.034457833,
    //       "probe_dc": "ex aliquip elit",
    //       "result": {
    //         "passed": false,
    //         "timings": {
    //           "dns": -97211663.12516338,
    //           "download": 69787304.59130791,
    //           "firstByte": 7063435.657899752,
    //           "handshake": 58647320.32120216,
    //           "redirect": -39297333.858247004,
    //           "ssl": 39645260.31412804,
    //           "tcp": 20665973.93464838,
    //           "total": 20845012.956068933,
    //           "wait": -39822886.67901743
    //         }
    //       },
    //       "result_id": "ipsum in",
    //       "status": 0
    //     },
    //     {
    //       "check_time": -45161819.38632564,
    //       "probe_dc": "esse ipsum pariatur do et",
    //       "result": {
    //         "passed": true,
    //         "timings": {
    //           "dns": -36593755.469836965,
    //           "download": 12698868.215193078,
    //           "firstByte": 33271607.027867228,
    //           "handshake": -31538483.54689482,
    //           "redirect": -78495392.91587453,
    //           "ssl": 64556481.18909925,
    //           "tcp": -77981358.8267188,
    //           "total": 41359471.650199294,
    //           "wait": 38487717.98797688
    //         }
    //       },
    //       "result_id": "commodo adipisicing in exercitation",
    //       "status": 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.

    last_timestamp_fetched = CkJsonObjectW_IntOf(jResp,L"last_timestamp_fetched");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"results");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        check_time = CkJsonObjectW_stringOf(jResp,L"results[i].check_time");
        probe_dc = CkJsonObjectW_stringOf(jResp,L"results[i].probe_dc");
        Passed = CkJsonObjectW_BoolOf(jResp,L"results[i].result.passed");
        v_Dns = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.dns");
        Download = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.download");
        FirstByte = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.firstByte");
        Handshake = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.handshake");
        Redirect = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.redirect");
        Ssl = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.ssl");
        Tcp = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.tcp");
        Total = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.total");
        Wait = CkJsonObjectW_stringOf(jResp,L"results[i].result.timings.wait");
        result_id = CkJsonObjectW_stringOf(jResp,L"results[i].result_id");
        status = CkJsonObjectW_IntOf(jResp,L"results[i].status");
        i = i + 1;
    }



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

    }

Curl Command

curl -G -d "from_ts=-62147425"
	-d "to_ts=-62147425"
	-d "probe_dc=dolor%20cillum%20in"
	-d "probe_dc=proident"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/synthetics/tests/:public_id/results

Postman Collection Item JSON

{
  "name": "Get an API test's latest results summaries",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/synthetics/tests/:public_id/results?from_ts=-62147425&to_ts=-62147425&probe_dc=dolor cillum in&probe_dc=proident",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "synthetics",
        "tests",
        ":public_id",
        "results"
      ],
      "query": [
        {
          "key": "from_ts",
          "value": "-62147425",
          "description": "Timestamp in milliseconds from which to start querying results."
        },
        {
          "key": "to_ts",
          "value": "-62147425",
          "description": "Timestamp in milliseconds up to which to query results."
        },
        {
          "key": "probe_dc",
          "value": "dolor cillum in",
          "description": "Locations for which to query results."
        },
        {
          "key": "probe_dc",
          "value": "proident",
          "description": "Locations for which to query results."
        }
      ],
      "variable": [
        {
          "key": "public_id",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Get the last 150 test results summaries for a given Synthetic API test."
  },
  "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/synthetics/tests/:public_id/results?from_ts=-62147425&to_ts=-62147425&probe_dc=proident",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            ":public_id",
            "results"
          ],
          "query": [
            {
              "key": "from_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds from which to start querying results."
            },
            {
              "key": "to_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds up to which to query results."
            },
            {
              "key": "probe_dc",
              "value": "proident",
              "description": "Locations for which to query results."
            }
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"last_timestamp_fetched\": -96513461,\n  \"results\": [\n    {\n      \"check_time\": -32755115.034457833,\n      \"probe_dc\": \"ex aliquip elit\",\n      \"result\": {\n        \"passed\": false,\n        \"timings\": {\n          \"dns\": -97211663.12516338,\n          \"download\": 69787304.59130791,\n          \"firstByte\": 7063435.657899752,\n          \"handshake\": 58647320.32120216,\n          \"redirect\": -39297333.858247004,\n          \"ssl\": 39645260.31412804,\n          \"tcp\": 20665973.93464838,\n          \"total\": 20845012.956068933,\n          \"wait\": -39822886.67901743\n        }\n      },\n      \"result_id\": \"ipsum in\",\n      \"status\": 0\n    },\n    {\n      \"check_time\": -45161819.38632564,\n      \"probe_dc\": \"esse ipsum pariatur do et\",\n      \"result\": {\n        \"passed\": true,\n        \"timings\": {\n          \"dns\": -36593755.469836965,\n          \"download\": 12698868.215193078,\n          \"firstByte\": 33271607.027867228,\n          \"handshake\": -31538483.54689482,\n          \"redirect\": -78495392.91587453,\n          \"ssl\": 64556481.18909925,\n          \"tcp\": -77981358.8267188,\n          \"total\": 41359471.650199294,\n          \"wait\": 38487717.98797688\n        }\n      },\n      \"result_id\": \"commodo adipisicing in exercitation\",\n      \"status\": 2\n    }\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/synthetics/tests/:public_id/results?from_ts=-62147425&to_ts=-62147425&probe_dc=proident",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            ":public_id",
            "results"
          ],
          "query": [
            {
              "key": "from_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds from which to start querying results."
            },
            {
              "key": "to_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds up to which to query results."
            },
            {
              "key": "probe_dc",
              "value": "proident",
              "description": "Locations for which to query results."
            }
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "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": "- Synthetic is not activated for the user\n- Test is not owned by the user",
      "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/synthetics/tests/:public_id/results?from_ts=-62147425&to_ts=-62147425&probe_dc=proident",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            ":public_id",
            "results"
          ],
          "query": [
            {
              "key": "from_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds from which to start querying results."
            },
            {
              "key": "to_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds up to which to query results."
            },
            {
              "key": "probe_dc",
              "value": "proident",
              "description": "Locations for which to query results."
            }
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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/synthetics/tests/:public_id/results?from_ts=-62147425&to_ts=-62147425&probe_dc=proident",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "synthetics",
            "tests",
            ":public_id",
            "results"
          ],
          "query": [
            {
              "key": "from_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds from which to start querying results."
            },
            {
              "key": "to_ts",
              "value": "-62147425",
              "description": "Timestamp in milliseconds up to which to query results."
            },
            {
              "key": "probe_dc",
              "value": "proident",
              "description": "Locations for which to query results."
            }
          ],
          "variable": [
            {
              "key": "public_id"
            }
          ]
        }
      },
      "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}"
    }
  ]
}