Chilkat Online Tools

autoit / Datadog API Collection / List all GCP STS-enabled service accounts

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/v2/integration/gcp/accounts",$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)

; {
;   "data": [
;     {
;       "attributes": {
;         "automute": "<boolean>",
;         "client_email": "<string>",
;         "host_filters": [
;           "<string>",
;           "<string>"
;         ],
;         "is_cspm_enabled": "<boolean>"
;       },
;       "id": "<string>",
;       "meta": {
;         "accessible_projects": [
;           "<string>",
;           "<string>"
;         ]
;       },
;       "type": "gcp_service_account"
;     },
;     {
;       "attributes": {
;         "automute": "<boolean>",
;         "client_email": "<string>",
;         "host_filters": [
;           "<string>",
;           "<string>"
;         ],
;         "is_cspm_enabled": "<boolean>"
;       },
;       "id": "<string>",
;       "meta": {
;         "accessible_projects": [
;           "<string>",
;           "<string>"
;         ]
;       },
;       "type": "gcp_service_account"
;     }
;   ]
; }

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

Local $sAutomute
Local $sClient_email
Local $sIs_cspm_enabled
Local $sId
Local $sV_type
Local $iJ
Local $iCount_j
Local $strVal

Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("data")
While $i < $iCount_i
    $oJResp.I = $i
    $sAutomute = $oJResp.StringOf("data[i].attributes.automute")
    $sClient_email = $oJResp.StringOf("data[i].attributes.client_email")
    $sIs_cspm_enabled = $oJResp.StringOf("data[i].attributes.is_cspm_enabled")
    $sId = $oJResp.StringOf("data[i].id")
    $sV_type = $oJResp.StringOf("data[i].type")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("data[i].attributes.host_filters")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("data[i].attributes.host_filters[j]")
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("data[i].meta.accessible_projects")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $strVal = $oJResp.StringOf("data[i].meta.accessible_projects[j]")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

Curl Command

curl -X GET
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts

Postman Collection Item JSON

{
  "name": "List all GCP STS-enabled service accounts",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/integration/gcp/accounts",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "integration",
        "gcp",
        "accounts"
      ]
    },
    "description": "List all GCP STS-enabled service accounts configured in your Datadog account."
  },
  "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/integration/gcp/accounts",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"automute\": \"<boolean>\",\n        \"client_email\": \"<string>\",\n        \"host_filters\": [\n          \"<string>\",\n          \"<string>\"\n        ],\n        \"is_cspm_enabled\": \"<boolean>\"\n      },\n      \"id\": \"<string>\",\n      \"meta\": {\n        \"accessible_projects\": [\n          \"<string>\",\n          \"<string>\"\n        ]\n      },\n      \"type\": \"gcp_service_account\"\n    },\n    {\n      \"attributes\": {\n        \"automute\": \"<boolean>\",\n        \"client_email\": \"<string>\",\n        \"host_filters\": [\n          \"<string>\",\n          \"<string>\"\n        ],\n        \"is_cspm_enabled\": \"<boolean>\"\n      },\n      \"id\": \"<string>\",\n      \"meta\": {\n        \"accessible_projects\": [\n          \"<string>\",\n          \"<string>\"\n        ]\n      },\n      \"type\": \"gcp_service_account\"\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/integration/gcp/accounts",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts"
          ]
        }
      },
      "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": "Not Found",
      "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/integration/gcp/accounts",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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/integration/gcp/accounts",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts"
          ]
        }
      },
      "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}"
    }
  ]
}