Chilkat Online Tools

Foxpro / Datadog API Collection / Get all log-based metrics

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcAggregation_type
LOCAL lcInclude_percentiles
LOCAL lcPath
LOCAL lcQuery
LOCAL lcId
LOCAL lcV_type
LOCAL j
LOCAL lnCount_j
LOCAL lcPath
LOCAL lcTag_name
LOCAL i
LOCAL lnCount_i

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

loHttp = CreateObject('Chilkat_9_5_0.Http')

loHttp.SetRequestHeader("Accept","application/json")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://api.app.ddog-gov.com/api/v2/logs/config/metrics",loSbResponseBody)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    RELEASE loHttp
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

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

* {
*   "data": [
*     {
*       "attributes": {
*         "compute": {
*           "aggregation_type": "count",
*           "include_percentiles": "<boolean>",
*           "path": "<string>"
*         },
*         "filter": {
*           "query": "<string>"
*         },
*         "group_by": [
*           {
*             "path": "<string>",
*             "tag_name": "<string>"
*           },
*           {
*             "path": "<string>",
*             "tag_name": "<string>"
*           }
*         ]
*       },
*       "id": "<string>",
*       "type": "logs_metrics"
*     },
*     {
*       "attributes": {
*         "compute": {
*           "aggregation_type": "distribution",
*           "include_percentiles": "<boolean>",
*           "path": "<string>"
*         },
*         "filter": {
*           "query": "<string>"
*         },
*         "group_by": [
*           {
*             "path": "<string>",
*             "tag_name": "<string>"
*           },
*           {
*             "path": "<string>",
*             "tag_name": "<string>"
*           }
*         ]
*       },
*       "id": "<string>",
*       "type": "logs_metrics"
*     }
*   ]
* }

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

i = 0
lnCount_i = loJResp.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcAggregation_type = loJResp.StringOf("data[i].attributes.compute.aggregation_type")
    lcInclude_percentiles = loJResp.StringOf("data[i].attributes.compute.include_percentiles")
    lcPath = loJResp.StringOf("data[i].attributes.compute.path")
    lcQuery = loJResp.StringOf("data[i].attributes.filter.query")
    lcId = loJResp.StringOf("data[i].id")
    lcV_type = loJResp.StringOf("data[i].type")
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.group_by")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcPath = loJResp.StringOf("data[i].attributes.group_by[j].path")
        lcTag_name = loJResp.StringOf("data[i].attributes.group_by[j].tag_name")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loSbResponseBody
RELEASE loJResp

Curl Command

curl -X GET
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/logs/config/metrics

Postman Collection Item JSON

{
  "name": "Get all log-based metrics",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/logs/config/metrics",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "logs",
        "config",
        "metrics"
      ]
    },
    "description": "Get the list of configured log-based metrics with their definitions."
  },
  "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/v2/logs/config/metrics",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "logs",
            "config",
            "metrics"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"compute\": {\n          \"aggregation_type\": \"count\",\n          \"include_percentiles\": \"<boolean>\",\n          \"path\": \"<string>\"\n        },\n        \"filter\": {\n          \"query\": \"<string>\"\n        },\n        \"group_by\": [\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          },\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          }\n        ]\n      },\n      \"id\": \"<string>\",\n      \"type\": \"logs_metrics\"\n    },\n    {\n      \"attributes\": {\n        \"compute\": {\n          \"aggregation_type\": \"distribution\",\n          \"include_percentiles\": \"<boolean>\",\n          \"path\": \"<string>\"\n        },\n        \"filter\": {\n          \"query\": \"<string>\"\n        },\n        \"group_by\": [\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          },\n          {\n            \"path\": \"<string>\",\n            \"tag_name\": \"<string>\"\n          }\n        ]\n      },\n      \"id\": \"<string>\",\n      \"type\": \"logs_metrics\"\n    }\n  ]\n}"
    },
    {
      "name": "Not Authorized",
      "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/v2/logs/config/metrics",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "logs",
            "config",
            "metrics"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\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/v2/logs/config/metrics",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "logs",
            "config",
            "metrics"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}