Chilkat Online Tools

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

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sCheck_time
    String sProbe_dc
    Boolean iPassed
    String sV_Dns
    String sDownload
    String sFirstByte
    String sHandshake
    String sRedirect
    String sSsl
    String sTcp
    String sTotal
    String sWait
    String sResult_id
    Integer iStatus
    Integer iLast_timestamp_fetched
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateInt Of hoQueryParams "from_ts" -62147425 To iSuccess
    Get ComUpdateInt Of hoQueryParams "to_ts" -62147425 To iSuccess
    Get ComUpdateString Of hoQueryParams "probe_dc" "dolor cillum in" To iSuccess
    Get ComUpdateString Of hoQueryParams "probe_dc" "proident" To iSuccess

    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v1/synthetics/tests/:public_id/results" vQueryParams To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    Get ComIntOf Of hoJResp "last_timestamp_fetched" To iLast_timestamp_fetched
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "results" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "results[i].check_time" To sCheck_time
        Get ComStringOf Of hoJResp "results[i].probe_dc" To sProbe_dc
        Get ComBoolOf Of hoJResp "results[i].result.passed" To iPassed
        Get ComStringOf Of hoJResp "results[i].result.timings.dns" To sV_Dns
        Get ComStringOf Of hoJResp "results[i].result.timings.download" To sDownload
        Get ComStringOf Of hoJResp "results[i].result.timings.firstByte" To sFirstByte
        Get ComStringOf Of hoJResp "results[i].result.timings.handshake" To sHandshake
        Get ComStringOf Of hoJResp "results[i].result.timings.redirect" To sRedirect
        Get ComStringOf Of hoJResp "results[i].result.timings.ssl" To sSsl
        Get ComStringOf Of hoJResp "results[i].result.timings.tcp" To sTcp
        Get ComStringOf Of hoJResp "results[i].result.timings.total" To sTotal
        Get ComStringOf Of hoJResp "results[i].result.timings.wait" To sWait
        Get ComStringOf Of hoJResp "results[i].result_id" To sResult_id
        Get ComIntOf Of hoJResp "results[i].status" To iStatus
        Move (i + 1) To i
    Loop



End_Procedure

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}"
    }
  ]
}