Chilkat Online Tools

Foxpro / Datadog API Collection / Get all indexes

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcName
LOCAL lcQuery
LOCAL lnDaily_limit
LOCAL lnIs_rate_limited
LOCAL lnNum_retention_days
LOCAL j
LOCAL lnCount_j
LOCAL lnSample_rate
LOCAL lcFilterQuery
LOCAL lnIs_enabled
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/v1/logs/config/indexes",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)

* {
*   "indexes": [
*     {
*       "name": "main",
*       "filter": {
*         "query": "source:python"
*       },
*       "daily_limit": 300000000,
*       "exclusion_filters": [
*         {
*           "name": "payment",
*           "filter": {
*             "sample_rate": 1,
*             "query": "*"
*           },
*           "is_enabled": false
*         },
*         {
*           "name": "payment",
*           "filter": {
*             "sample_rate": 1,
*             "query": "*"
*           },
*           "is_enabled": false
*         }
*       ],
*       "is_rate_limited": false,
*       "num_retention_days": 15
*     },
*     {
*       "name": "main",
*       "filter": {
*         "query": "source:python"
*       },
*       "daily_limit": 300000000,
*       "exclusion_filters": [
*         {
*           "name": "payment",
*           "filter": {
*             "sample_rate": 1,
*             "query": "*"
*           },
*           "is_enabled": false
*         },
*         {
*           "name": "payment",
*           "filter": {
*             "sample_rate": 1,
*             "query": "*"
*           },
*           "is_enabled": false
*         }
*       ],
*       "is_rate_limited": false,
*       "num_retention_days": 15
*     }
*   ]
* }

* 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("indexes")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcName = loJResp.StringOf("indexes[i].name")
    lcQuery = loJResp.StringOf("indexes[i].filter.query")
    lnDaily_limit = loJResp.IntOf("indexes[i].daily_limit")
    lnIs_rate_limited = loJResp.BoolOf("indexes[i].is_rate_limited")
    lnNum_retention_days = loJResp.IntOf("indexes[i].num_retention_days")
    j = 0
    lnCount_j = loJResp.SizeOfArray("indexes[i].exclusion_filters")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcName = loJResp.StringOf("indexes[i].exclusion_filters[j].name")
        lnSample_rate = loJResp.IntOf("indexes[i].exclusion_filters[j].filter.sample_rate")
        lcFilterQuery = loJResp.StringOf("indexes[i].exclusion_filters[j].filter.query")
        lnIs_enabled = loJResp.BoolOf("indexes[i].exclusion_filters[j].is_enabled")
        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/v1/logs/config/indexes

Postman Collection Item JSON

{
  "name": "Get all indexes",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/logs/config/indexes",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "logs",
        "config",
        "indexes"
      ]
    },
    "description": "The Index object describes the configuration of a log index.\nThis endpoint returns an array of the `LogIndex` objects of your organization."
  },
  "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/logs/config/indexes",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "logs",
            "config",
            "indexes"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"indexes\": [\n    {\n      \"name\": \"main\",\n      \"filter\": {\n        \"query\": \"source:python\"\n      },\n      \"daily_limit\": 300000000,\n      \"exclusion_filters\": [\n        {\n          \"name\": \"payment\",\n          \"filter\": {\n            \"sample_rate\": 1,\n            \"query\": \"*\"\n          },\n          \"is_enabled\": false\n        },\n        {\n          \"name\": \"payment\",\n          \"filter\": {\n            \"sample_rate\": 1,\n            \"query\": \"*\"\n          },\n          \"is_enabled\": false\n        }\n      ],\n      \"is_rate_limited\": false,\n      \"num_retention_days\": 15\n    },\n    {\n      \"name\": \"main\",\n      \"filter\": {\n        \"query\": \"source:python\"\n      },\n      \"daily_limit\": 300000000,\n      \"exclusion_filters\": [\n        {\n          \"name\": \"payment\",\n          \"filter\": {\n            \"sample_rate\": 1,\n            \"query\": \"*\"\n          },\n          \"is_enabled\": false\n        },\n        {\n          \"name\": \"payment\",\n          \"filter\": {\n            \"sample_rate\": 1,\n            \"query\": \"*\"\n          },\n          \"is_enabled\": false\n        }\n      ],\n      \"is_rate_limited\": false,\n      \"num_retention_days\": 15\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/logs/config/indexes",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "logs",
            "config",
            "indexes"
          ]
        }
      },
      "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/logs/config/indexes",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "logs",
            "config",
            "indexes"
          ]
        }
      },
      "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}"
    }
  ]
}