Chilkat Online Tools

delphiDll / Datadog API Collection / List IP Ranges

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
strVal: PWideChar;
modified: PWideChar;
version: Integer;
i: Integer;
count_i: Integer;

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

http := CkHttp_Create();

CkHttp_SetRequestHeader(http,'Accept','application/json');

sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://api.app.ddog-gov.com/',sbResponseBody);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttp__lastHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

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

// {
//   "agents": {
//     "prefixes_ipv4": [
//       "qui dolor",
//       "Ut in"
//     ],
//     "prefixes_ipv6": [
//       "irure occaecat Ut elit",
//       "Ut est voluptate"
//     ]
//   },
//   "api": {
//     "prefixes_ipv4": [
//       "do irure",
//       "id dolor magna consequat"
//     ],
//     "prefixes_ipv6": [
//       "non magna enim",
//       "dolor magna labore"
//     ]
//   },
//   "apm": {
//     "prefixes_ipv4": [
//       "enim dolo",
//       "incididunt sunt voluptate exercitati"
//     ],
//     "prefixes_ipv6": [
//       "Duis elit minim occaecat",
//       "qui sit "
//     ]
//   },
//   "logs": {
//     "prefixes_ipv4": [
//       "aute ",
//       "ullamco commodo Ut Excepteur"
//     ],
//     "prefixes_ipv6": [
//       "veniam ex",
//       "incididunt consectetur dolor est"
//     ]
//   },
//   "modified": "2019-10-31-20-00-00",
//   "orchestrator": {
//     "prefixes_ipv4": [
//       "nulla adipisicing",
//       "nostrud do enim laborum"
//     ],
//     "prefixes_ipv6": [
//       "mollit sed ut",
//       "est"
//     ]
//   },
//   "process": {
//     "prefixes_ipv4": [
//       "Excepteur nulla mollit",
//       "labore nulla esse"
//     ],
//     "prefixes_ipv6": [
//       "nostrud laborum dolor",
//       "do sed nulla elit"
//     ]
//   },
//   "remote-configuration": {
//     "prefixes_ipv4": [
//       "sunt tempor",
//       "nostrud ipsum"
//     ],
//     "prefixes_ipv6": [
//       "sunt Dui",
//       "sit amet"
//     ]
//   },
//   "synthetics": {
//     "prefixes_ipv4": [
//       "in exercitation eu sunt",
//       "velit pariatur consecte"
//     ],
//     "prefixes_ipv4_by_location": {
//       "pariatur7": [
//         "elit adipisicing",
//         "reprehenderit eiusmod Duis"
//       ]
//     },
//     "prefixes_ipv6": [
//       "cupidatat magna enim minim",
//       "Excepteur in dolor do eiusmod"
//     ],
//     "prefixes_ipv6_by_location": {
//       "est1": [
//         "Ut",
//         "dolor sed nulla"
//       ],
//       "magna_3b": [
//         "tempor Lorem do qui enim",
//         "dolore eiusmod"
//       ]
//     }
//   },
//   "synthetics-private-locations": {
//     "prefixes_ipv4": [
//       "labo",
//       "s"
//     ],
//     "prefixes_ipv6": [
//       "nisi incididunt",
//       "l"
//     ]
//   },
//   "version": 11,
//   "webhooks": {
//     "prefixes_ipv4": [
//       "id ullamco deserunt",
//       "consequat sunt tempor minim"
//     ],
//     "prefixes_ipv6": [
//       "fugiat est dolore quis",
//       "proident sunt aliquip"
//     ]
//   }
// }

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

modified := CkJsonObject__stringOf(jResp,'modified');
version := CkJsonObject_IntOf(jResp,'version');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'agents.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'agents.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'agents.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'agents.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'api.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'api.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'api.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'api.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'apm.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'apm.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'apm.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'apm.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'logs.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'logs.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'logs.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'logs.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'orchestrator.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'orchestrator.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'orchestrator.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'orchestrator.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'process.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'process.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'process.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'process.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'remote-configuration.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'remote-configuration.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'remote-configuration.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'remote-configuration.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'synthetics.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'synthetics.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'synthetics.prefixes_ipv4_by_location.pariatur7');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'synthetics.prefixes_ipv4_by_location.pariatur7[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'synthetics.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'synthetics.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'synthetics.prefixes_ipv6_by_location.est1');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'synthetics.prefixes_ipv6_by_location.est1[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'synthetics.prefixes_ipv6_by_location.magna_3b');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'synthetics.prefixes_ipv6_by_location.magna_3b[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'synthetics-private-locations.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'synthetics-private-locations.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'synthetics-private-locations.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'synthetics-private-locations.prefixes_ipv6[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'webhooks.prefixes_ipv4');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'webhooks.prefixes_ipv4[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'webhooks.prefixes_ipv6');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'webhooks.prefixes_ipv6[i]');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

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

Postman Collection Item JSON

{
  "name": "List IP Ranges",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "https://{{subdomain}}.{{site}}/",
      "protocol": "https",
      "host": [
        "{{subdomain}}",
        "{{site}}"
      ],
      "path": [
        ""
      ]
    },
    "description": "Get information about Datadog IP ranges."
  },
  "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": "https://{{subdomain}}.{{site}}/",
          "protocol": "https",
          "host": [
            "{{subdomain}}",
            "{{site}}"
          ],
          "path": [
            ""
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"agents\": {\n    \"prefixes_ipv4\": [\n      \"qui dolor\",\n      \"Ut in\"\n    ],\n    \"prefixes_ipv6\": [\n      \"irure occaecat Ut elit\",\n      \"Ut est voluptate\"\n    ]\n  },\n  \"api\": {\n    \"prefixes_ipv4\": [\n      \"do irure\",\n      \"id dolor magna consequat\"\n    ],\n    \"prefixes_ipv6\": [\n      \"non magna enim\",\n      \"dolor magna labore\"\n    ]\n  },\n  \"apm\": {\n    \"prefixes_ipv4\": [\n      \"enim dolo\",\n      \"incididunt sunt voluptate exercitati\"\n    ],\n    \"prefixes_ipv6\": [\n      \"Duis elit minim occaecat\",\n      \"qui sit \"\n    ]\n  },\n  \"logs\": {\n    \"prefixes_ipv4\": [\n      \"aute \",\n      \"ullamco commodo Ut Excepteur\"\n    ],\n    \"prefixes_ipv6\": [\n      \"veniam ex\",\n      \"incididunt consectetur dolor est\"\n    ]\n  },\n  \"modified\": \"2019-10-31-20-00-00\",\n  \"orchestrator\": {\n    \"prefixes_ipv4\": [\n      \"nulla adipisicing\",\n      \"nostrud do enim laborum\"\n    ],\n    \"prefixes_ipv6\": [\n      \"mollit sed ut\",\n      \"est\"\n    ]\n  },\n  \"process\": {\n    \"prefixes_ipv4\": [\n      \"Excepteur nulla mollit\",\n      \"labore nulla esse\"\n    ],\n    \"prefixes_ipv6\": [\n      \"nostrud laborum dolor\",\n      \"do sed nulla elit\"\n    ]\n  },\n  \"remote-configuration\": {\n    \"prefixes_ipv4\": [\n      \"sunt tempor\",\n      \"nostrud ipsum\"\n    ],\n    \"prefixes_ipv6\": [\n      \"sunt Dui\",\n      \"sit amet\"\n    ]\n  },\n  \"synthetics\": {\n    \"prefixes_ipv4\": [\n      \"in exercitation eu sunt\",\n      \"velit pariatur consecte\"\n    ],\n    \"prefixes_ipv4_by_location\": {\n      \"pariatur7\": [\n        \"elit adipisicing\",\n        \"reprehenderit eiusmod Duis\"\n      ]\n    },\n    \"prefixes_ipv6\": [\n      \"cupidatat magna enim minim\",\n      \"Excepteur in dolor do eiusmod\"\n    ],\n    \"prefixes_ipv6_by_location\": {\n      \"est1\": [\n        \"Ut\",\n        \"dolor sed nulla\"\n      ],\n      \"magna_3b\": [\n        \"tempor Lorem do qui enim\",\n        \"dolore eiusmod\"\n      ]\n    }\n  },\n  \"synthetics-private-locations\": {\n    \"prefixes_ipv4\": [\n      \"labo\",\n      \"s\"\n    ],\n    \"prefixes_ipv6\": [\n      \"nisi incididunt\",\n      \"l\"\n    ]\n  },\n  \"version\": 11,\n  \"webhooks\": {\n    \"prefixes_ipv4\": [\n      \"id ullamco deserunt\",\n      \"consequat sunt tempor minim\"\n    ],\n    \"prefixes_ipv6\": [\n      \"fugiat est dolore quis\",\n      \"proident sunt aliquip\"\n    ]\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": "https://{{subdomain}}.{{site}}/",
          "protocol": "https",
          "host": [
            "{{subdomain}}",
            "{{site}}"
          ],
          "path": [
            ""
          ]
        }
      },
      "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}"
    }
  ]
}