Chilkat Online Tools

autoit / Datadog API Collection / Get all indexes

Back to Collection Items

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

$oHttp = ObjCreate("Chilkat_9_5_0.Http")
Local $bSuccess

$oHttp.SetRequestHeader "Accept","application/json"

$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api.app.ddog-gov.com/api/v1/logs/config/indexes",$oSbResponseBody)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oHttp.LastHeader & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
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

Local $sName
Local $sQuery
Local $iDaily_limit
Local $bIs_rate_limited
Local $iNum_retention_days
Local $iJ
Local $iCount_j
Local $iSample_rate
Local $sFilterQuery
Local $bIs_enabled

Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("indexes")
While $i < $iCount_i
    $oJResp.I = $i
    $sName = $oJResp.StringOf("indexes[i].name")
    $sQuery = $oJResp.StringOf("indexes[i].filter.query")
    $iDaily_limit = $oJResp.IntOf("indexes[i].daily_limit")
    $bIs_rate_limited = $oJResp.BoolOf("indexes[i].is_rate_limited")
    $iNum_retention_days = $oJResp.IntOf("indexes[i].num_retention_days")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("indexes[i].exclusion_filters")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sName = $oJResp.StringOf("indexes[i].exclusion_filters[j].name")
        $iSample_rate = $oJResp.IntOf("indexes[i].exclusion_filters[j].filter.sample_rate")
        $sFilterQuery = $oJResp.StringOf("indexes[i].exclusion_filters[j].filter.query")
        $bIs_enabled = $oJResp.BoolOf("indexes[i].exclusion_filters[j].is_enabled")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

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