Chilkat Online Tools

unicodeC / Datadog API Collection / List all AWS integrations

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW queryParams;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *access_key_id;
    const wchar_t *account_id;
    BOOL Auto_scaling;
    BOOL Opswork;
    BOOL cspm_resource_collection_enabled;
    BOOL metrics_collection_enabled;
    BOOL resource_collection_enabled;
    const wchar_t *role_name;
    const wchar_t *secret_access_key;
    int j;
    int count_j;
    const wchar_t *strVal;
    int i;
    int count_i;

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

    http = CkHttpW_Create();

    queryParams = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(queryParams,L"account_id",L"cupidatat Ut Duis");
    CkJsonObjectW_UpdateString(queryParams,L"role_name",L"cupidatat Ut Duis");
    CkJsonObjectW_UpdateString(queryParams,L"access_key_id",L"cupidatat Ut Duis");

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://api.app.ddog-gov.com/api/v1/integration/aws",queryParams);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

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

    // {
    //   "accounts": [
    //     {
    //       "access_key_id": "sit Lorem commodo est",
    //       "account_id": "123456789012",
    //       "account_specific_namespace_rules": {
    //         "auto_scaling": false,
    //         "opswork": false
    //       },
    //       "cspm_resource_collection_enabled": true,
    //       "excluded_regions": [
    //         "us-east-1",
    //         "us-west-2"
    //       ],
    //       "filter_tags": [
    //         "$KEY:$VALUE"
    //       ],
    //       "host_tags": [
    //         "$KEY:$VALUE"
    //       ],
    //       "metrics_collection_enabled": false,
    //       "resource_collection_enabled": true,
    //       "role_name": "DatadogAWSIntegrationRole",
    //       "secret_access_key": "qui veniam sint anim"
    //     },
    //     {
    //       "access_key_id": "quis enim laboris",
    //       "account_id": "123456789012",
    //       "account_specific_namespace_rules": {
    //         "auto_scaling": false,
    //         "opswork": false
    //       },
    //       "cspm_resource_collection_enabled": true,
    //       "excluded_regions": [
    //         "us-east-1",
    //         "us-west-2"
    //       ],
    //       "filter_tags": [
    //         "$KEY:$VALUE"
    //       ],
    //       "host_tags": [
    //         "$KEY:$VALUE"
    //       ],
    //       "metrics_collection_enabled": false,
    //       "resource_collection_enabled": true,
    //       "role_name": "DatadogAWSIntegrationRole",
    //       "secret_access_key": "ea esse Duis"
    //     }
    //   ]
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"accounts");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        access_key_id = CkJsonObjectW_stringOf(jResp,L"accounts[i].access_key_id");
        account_id = CkJsonObjectW_stringOf(jResp,L"accounts[i].account_id");
        Auto_scaling = CkJsonObjectW_BoolOf(jResp,L"accounts[i].account_specific_namespace_rules.auto_scaling");
        Opswork = CkJsonObjectW_BoolOf(jResp,L"accounts[i].account_specific_namespace_rules.opswork");
        cspm_resource_collection_enabled = CkJsonObjectW_BoolOf(jResp,L"accounts[i].cspm_resource_collection_enabled");
        metrics_collection_enabled = CkJsonObjectW_BoolOf(jResp,L"accounts[i].metrics_collection_enabled");
        resource_collection_enabled = CkJsonObjectW_BoolOf(jResp,L"accounts[i].resource_collection_enabled");
        role_name = CkJsonObjectW_stringOf(jResp,L"accounts[i].role_name");
        secret_access_key = CkJsonObjectW_stringOf(jResp,L"accounts[i].secret_access_key");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"accounts[i].excluded_regions");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"accounts[i].excluded_regions[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"accounts[i].filter_tags");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"accounts[i].filter_tags[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"accounts[i].host_tags");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"accounts[i].host_tags[j]");
            j = j + 1;
        }

        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(queryParams);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -G -d "account_id=cupidatat%20Ut%20Duis"
	-d "role_name=cupidatat%20Ut%20Duis"
	-d "access_key_id=cupidatat%20Ut%20Duis"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/integration/aws

Postman Collection Item JSON

{
  "name": "List all AWS integrations",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/integration/aws?account_id=cupidatat Ut Duis&role_name=cupidatat Ut Duis&access_key_id=cupidatat Ut Duis",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "integration",
        "aws"
      ],
      "query": [
        {
          "key": "account_id",
          "value": "cupidatat Ut Duis",
          "description": "Only return AWS accounts that matches this `account_id`."
        },
        {
          "key": "role_name",
          "value": "cupidatat Ut Duis",
          "description": "Only return AWS accounts that matches this role_name."
        },
        {
          "key": "access_key_id",
          "value": "cupidatat Ut Duis",
          "description": "Only return AWS accounts that matches this `access_key_id`."
        }
      ]
    },
    "description": "List all Datadog-AWS integrations available in your Datadog 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/integration/aws?account_id=cupidatat Ut Duis&role_name=cupidatat Ut Duis&access_key_id=cupidatat Ut Duis",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws"
          ],
          "query": [
            {
              "key": "account_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `account_id`."
            },
            {
              "key": "role_name",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this role_name."
            },
            {
              "key": "access_key_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `access_key_id`."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"accounts\": [\n    {\n      \"access_key_id\": \"sit Lorem commodo est\",\n      \"account_id\": \"123456789012\",\n      \"account_specific_namespace_rules\": {\n        \"auto_scaling\": false,\n        \"opswork\": false\n      },\n      \"cspm_resource_collection_enabled\": true,\n      \"excluded_regions\": [\n        \"us-east-1\",\n        \"us-west-2\"\n      ],\n      \"filter_tags\": [\n        \"$KEY:$VALUE\"\n      ],\n      \"host_tags\": [\n        \"$KEY:$VALUE\"\n      ],\n      \"metrics_collection_enabled\": false,\n      \"resource_collection_enabled\": true,\n      \"role_name\": \"DatadogAWSIntegrationRole\",\n      \"secret_access_key\": \"qui veniam sint anim\"\n    },\n    {\n      \"access_key_id\": \"quis enim laboris\",\n      \"account_id\": \"123456789012\",\n      \"account_specific_namespace_rules\": {\n        \"auto_scaling\": false,\n        \"opswork\": false\n      },\n      \"cspm_resource_collection_enabled\": true,\n      \"excluded_regions\": [\n        \"us-east-1\",\n        \"us-west-2\"\n      ],\n      \"filter_tags\": [\n        \"$KEY:$VALUE\"\n      ],\n      \"host_tags\": [\n        \"$KEY:$VALUE\"\n      ],\n      \"metrics_collection_enabled\": false,\n      \"resource_collection_enabled\": true,\n      \"role_name\": \"DatadogAWSIntegrationRole\",\n      \"secret_access_key\": \"ea esse Duis\"\n    }\n  ]\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?account_id=cupidatat Ut Duis&role_name=cupidatat Ut Duis&access_key_id=cupidatat Ut Duis",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws"
          ],
          "query": [
            {
              "key": "account_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `account_id`."
            },
            {
              "key": "role_name",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this role_name."
            },
            {
              "key": "access_key_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `access_key_id`."
            }
          ]
        }
      },
      "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?account_id=cupidatat Ut Duis&role_name=cupidatat Ut Duis&access_key_id=cupidatat Ut Duis",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws"
          ],
          "query": [
            {
              "key": "account_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `account_id`."
            },
            {
              "key": "role_name",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this role_name."
            },
            {
              "key": "access_key_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `access_key_id`."
            }
          ]
        }
      },
      "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?account_id=cupidatat Ut Duis&role_name=cupidatat Ut Duis&access_key_id=cupidatat Ut Duis",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "aws"
          ],
          "query": [
            {
              "key": "account_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `account_id`."
            },
            {
              "key": "role_name",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this role_name."
            },
            {
              "key": "access_key_id",
              "value": "cupidatat Ut Duis",
              "description": "Only return AWS accounts that matches this `access_key_id`."
            }
          ]
        }
      },
      "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}"
    }
  ]
}