Chilkat Online Tools

PureBasic / Datadog API Collection / Get all Amazon EventBridge sources

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::ckSetRequestHeader(http,"DD-API-KEY","{{apiKey}}")
    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://api.app.ddog-gov.com/api/v1/integration/aws/event_bridge",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

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

    ; {
    ;   "accounts": [
    ;     {
    ;       "accountId": "123456789012",
    ;       "eventHubs": [
    ;         {
    ;           "name": "dolor non",
    ;           "region": "i"
    ;         },
    ;         {
    ;           "name": "sit in ut Ut",
    ;           "region": "nisi Ut voluptate"
    ;         }
    ;       ],
    ;       "tags": [
    ;         "$KEY:$VALUE"
    ;       ]
    ;     },
    ;     {
    ;       "accountId": "123456789012",
    ;       "eventHubs": [
    ;         {
    ;           "name": "Ut eu",
    ;           "region": "mollit"
    ;         },
    ;         {
    ;           "name": "sed dolore Excepteur",
    ;           "region": "nisi consectetur ut"
    ;         }
    ;       ],
    ;       "tags": [
    ;         "$KEY:$VALUE"
    ;       ]
    ;     }
    ;   ],
    ;   "isInstalled": false
    ; }

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

    accountId.s
    j.i
    count_j.i
    name.s
    region.s
    strVal.s

    isInstalled.i = CkJsonObject::ckBoolOf(jResp,"isInstalled")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"accounts")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        accountId = CkJsonObject::ckStringOf(jResp,"accounts[i].accountId")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"accounts[i].eventHubs")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            name = CkJsonObject::ckStringOf(jResp,"accounts[i].eventHubs[j].name")
            region = CkJsonObject::ckStringOf(jResp,"accounts[i].eventHubs[j].region")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"accounts[i].tags")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"accounts[i].tags[j]")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -X GET
	-H "DD-API-KEY: {{apiKey}}"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/integration/aws/event_bridge

Postman Collection Item JSON

{
  "name": "Get all Amazon EventBridge sources",
  "request": {
    "auth": {
      "type": "apikey",
      "apikey": [
        {
          "key": "key",
          "value": "DD-API-KEY",
          "type": "string"
        },
        {
          "key": "value",
          "value": "{{apiKey}}",
          "type": "string"
        },
        {
          "key": "in",
          "value": "header",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/integration/aws/event_bridge",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "integration",
        "aws",
        "event_bridge"
      ]
    },
    "description": "Get all Amazon EventBridge sources."
  },
  "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/integration/aws/event_bridge",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws",
            "event_bridge"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"accounts\": [\n    {\n      \"accountId\": \"123456789012\",\n      \"eventHubs\": [\n        {\n          \"name\": \"dolor non\",\n          \"region\": \"i\"\n        },\n        {\n          \"name\": \"sit in ut Ut\",\n          \"region\": \"nisi Ut voluptate\"\n        }\n      ],\n      \"tags\": [\n        \"$KEY:$VALUE\"\n      ]\n    },\n    {\n      \"accountId\": \"123456789012\",\n      \"eventHubs\": [\n        {\n          \"name\": \"Ut eu\",\n          \"region\": \"mollit\"\n        },\n        {\n          \"name\": \"sed dolore Excepteur\",\n          \"region\": \"nisi consectetur ut\"\n        }\n      ],\n      \"tags\": [\n        \"$KEY:$VALUE\"\n      ]\n    }\n  ],\n  \"isInstalled\": false\n}"
    },
    {
      "name": "Bad Request",
      "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/integration/aws/event_bridge",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws",
            "event_bridge"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    },
    {
      "name": "Authentication Error",
      "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/integration/aws/event_bridge",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws",
            "event_bridge"
          ]
        }
      },
      "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/integration/aws/event_bridge",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws",
            "event_bridge"
          ]
        }
      },
      "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}"
    }
  ]
}