Chilkat Online Tools

delphiDll / Datadog API Collection / Get an event

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
strVal: PWideChar;
Alert_type: PWideChar;
Date_happened: Integer;
Device_name: PWideChar;
Host: PWideChar;
Id: Integer;
Id_str: PWideChar;
Payload: PWideChar;
Priority: PWideChar;
Source_type_name: PWideChar;
Text: PWideChar;
Title: PWideChar;
v_Url: PWideChar;
status: PWideChar;
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/api/v1/events/:event_id',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)

// {
//   "event": {
//     "alert_type": "info",
//     "date_happened": -7687934,
//     "device_name": "labore aliquip dolor",
//     "host": "incididunt sunt",
//     "id": -98412440,
//     "id_str": "incididunt laborum",
//     "payload": "{}",
//     "priority": "normal",
//     "source_type_name": "commodo cupidatat ea",
//     "tags": [
//       "environment:test"
//     ],
//     "text": "Oh boy!",
//     "title": "Did you hear the news today?",
//     "url": "non"
//   },
//   "status": "sit in"
// }

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

Alert_type := CkJsonObject__stringOf(jResp,'event.alert_type');
Date_happened := CkJsonObject_IntOf(jResp,'event.date_happened');
Device_name := CkJsonObject__stringOf(jResp,'event.device_name');
Host := CkJsonObject__stringOf(jResp,'event.host');
Id := CkJsonObject_IntOf(jResp,'event.id');
Id_str := CkJsonObject__stringOf(jResp,'event.id_str');
Payload := CkJsonObject__stringOf(jResp,'event.payload');
Priority := CkJsonObject__stringOf(jResp,'event.priority');
Source_type_name := CkJsonObject__stringOf(jResp,'event.source_type_name');
Text := CkJsonObject__stringOf(jResp,'event.text');
Title := CkJsonObject__stringOf(jResp,'event.title');
v_Url := CkJsonObject__stringOf(jResp,'event.url');
status := CkJsonObject__stringOf(jResp,'status');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'event.tags');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'event.tags[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/api/v1/events/:event_id

Postman Collection Item JSON

{
  "name": "Get an event",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/events/:event_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "events",
        ":event_id"
      ],
      "variable": [
        {
          "key": "event_id",
          "value": "-62147425"
        }
      ]
    },
    "description": "This endpoint allows you to query for event details.\n\n**Note**: If the event you’re querying contains markdown formatting of any kind,\nyou may see characters such as `%`,`\\`,`n` in your output."
  },
  "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/events/:event_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events",
            ":event_id"
          ],
          "variable": [
            {
              "key": "event_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"event\": {\n    \"alert_type\": \"info\",\n    \"date_happened\": -7687934,\n    \"device_name\": \"labore aliquip dolor\",\n    \"host\": \"incididunt sunt\",\n    \"id\": -98412440,\n    \"id_str\": \"incididunt laborum\",\n    \"payload\": \"{}\",\n    \"priority\": \"normal\",\n    \"source_type_name\": \"commodo cupidatat ea\",\n    \"tags\": [\n      \"environment:test\"\n    ],\n    \"text\": \"Oh boy!\",\n    \"title\": \"Did you hear the news today?\",\n    \"url\": \"non\"\n  },\n  \"status\": \"sit in\"\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/events/:event_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events",
            ":event_id"
          ],
          "variable": [
            {
              "key": "event_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": "Item 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/v1/events/:event_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events",
            ":event_id"
          ],
          "variable": [
            {
              "key": "event_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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/events/:event_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events",
            ":event_id"
          ],
          "variable": [
            {
              "key": "event_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}"
    }
  ]
}