Chilkat Online Tools

PowerBuilder / Datadog API Collection / Get a list of events

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Alert_type
integer li_Date_happened
string ls_Device_name
string ls_Host
integer li_Id
string ls_Id_str
string ls_Payload
string ls_Priority
string ls_Source_type_name
string ls_Text
string ls_Title
string ls_Url
integer j
integer li_Count_j
string ls_StrVal
string ls_Status
integer i
integer li_Count_i

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_QueryParams = create oleobject
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_QueryParams.UpdateInt("start",-62147425)
loo_QueryParams.UpdateInt("end",-62147425)
loo_QueryParams.UpdateString("priority","normal")
loo_QueryParams.UpdateString("sources","tempor Ut sed velit")
loo_QueryParams.UpdateString("tags","host:host0")
loo_QueryParams.UpdateString("unaggregated","true")
loo_QueryParams.UpdateString("exclude_aggregate","true")
loo_QueryParams.UpdateInt("page",-90656756)

loo_Http.SetRequestHeader("Accept","application/json")

loo_Resp = loo_Http.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v1/events",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_QueryParams
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_QueryParams
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

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

// {
//   "events": [
//     {
//       "alert_type": "info",
//       "date_happened": -60006686,
//       "device_name": "dolore",
//       "host": "proident in",
//       "id": -22759649,
//       "id_str": "quis labore cupidatat minim",
//       "payload": "{}",
//       "priority": "normal",
//       "source_type_name": "nulla aute",
//       "tags": [
//         "environment:test"
//       ],
//       "text": "Oh boy!",
//       "title": "Did you hear the news today?",
//       "url": "ex"
//     },
//     {
//       "alert_type": "info",
//       "date_happened": 12830805,
//       "device_name": "incididunt",
//       "host": "ex Excepteur eu magna",
//       "id": -86397972,
//       "id_str": "Duis",
//       "payload": "{}",
//       "priority": "normal",
//       "source_type_name": "quis amet voluptate fugiat enim",
//       "tags": [
//         "environment:test"
//       ],
//       "text": "Oh boy!",
//       "title": "Did you hear the news today?",
//       "url": "tempor"
//     }
//   ],
//   "status": "laborum consequat"
// }

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

ls_Status = loo_JResp.StringOf("status")
i = 0
li_Count_i = loo_JResp.SizeOfArray("events")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Alert_type = loo_JResp.StringOf("events[i].alert_type")
    li_Date_happened = loo_JResp.IntOf("events[i].date_happened")
    ls_Device_name = loo_JResp.StringOf("events[i].device_name")
    ls_Host = loo_JResp.StringOf("events[i].host")
    li_Id = loo_JResp.IntOf("events[i].id")
    ls_Id_str = loo_JResp.StringOf("events[i].id_str")
    ls_Payload = loo_JResp.StringOf("events[i].payload")
    ls_Priority = loo_JResp.StringOf("events[i].priority")
    ls_Source_type_name = loo_JResp.StringOf("events[i].source_type_name")
    ls_Text = loo_JResp.StringOf("events[i].text")
    ls_Title = loo_JResp.StringOf("events[i].title")
    ls_Url = loo_JResp.StringOf("events[i].url")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("events[i].tags")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("events[i].tags[j]")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -G -d "start=-62147425"
	-d "end=-62147425"
	-d "priority=normal"
	-d "sources=tempor%20Ut%20sed%20velit"
	-d "tags=host%3Ahost0"
	-d "unaggregated=true"
	-d "exclude_aggregate=true"
	-d "page=-90656756"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/events

Postman Collection Item JSON

{
  "name": "Get a list of events",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/events?start=-62147425&end=-62147425&priority=normal&sources=tempor Ut sed velit&tags=host:host0&unaggregated=true&exclude_aggregate=true&page=-90656756",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "events"
      ],
      "query": [
        {
          "key": "start",
          "value": "-62147425",
          "description": "(Required) POSIX timestamp."
        },
        {
          "key": "end",
          "value": "-62147425",
          "description": "(Required) POSIX timestamp."
        },
        {
          "key": "priority",
          "value": "normal",
          "description": "Priority of your events, either `low` or `normal`."
        },
        {
          "key": "sources",
          "value": "tempor Ut sed velit",
          "description": "A comma separated string of sources."
        },
        {
          "key": "tags",
          "value": "host:host0",
          "description": "A comma separated list indicating what tags, if any, should be used to filter the list of events."
        },
        {
          "key": "unaggregated",
          "value": "true",
          "description": "Set unaggregated to `true` to return all events within the specified [`start`,`end`] timeframe.\nOtherwise if an event is aggregated to a parent event with a timestamp outside of the timeframe,\nit won't be available in the output. Aggregated events with `is_aggregate=true` in the response will still be returned unless exclude_aggregate is set to `true.`"
        },
        {
          "key": "exclude_aggregate",
          "value": "true",
          "description": "Set `exclude_aggregate` to `true` to only return unaggregated events where `is_aggregate=false` in the response. If the `exclude_aggregate` parameter is set to `true`,\nthen the unaggregated parameter is ignored and will be `true` by default."
        },
        {
          "key": "page",
          "value": "-90656756",
          "description": "By default 1000 results are returned per request. Set page to the number of the page to return with `0` being the first page. The page parameter can only be used\nwhen either unaggregated or exclude_aggregate is set to `true.`"
        }
      ]
    },
    "description": "The event stream can be queried and filtered by time, priority, sources and tags.\n\n**Notes**:\n- If the event you’re querying contains markdown formatting of any kind,\nyou may see characters such as `%`,`\\`,`n` in your output.\n\n- This endpoint returns a maximum of `1000` most recent results. To return additional results,\nidentify the last timestamp of the last result and set that as the `end` query time to\npaginate the results. You can also use the page parameter to specify which set of `1000` results to return."
  },
  "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?start=-62147425&end=-62147425&priority=normal&sources=tempor Ut sed velit&tags=host:host0&unaggregated=true&exclude_aggregate=true&page=-90656756",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events"
          ],
          "query": [
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "priority",
              "value": "normal",
              "description": "Priority of your events, either `low` or `normal`."
            },
            {
              "key": "sources",
              "value": "tempor Ut sed velit",
              "description": "A comma separated string of sources."
            },
            {
              "key": "tags",
              "value": "host:host0",
              "description": "A comma separated list indicating what tags, if any, should be used to filter the list of events."
            },
            {
              "key": "unaggregated",
              "value": "true",
              "description": "Set unaggregated to `true` to return all events within the specified [`start`,`end`] timeframe.\nOtherwise if an event is aggregated to a parent event with a timestamp outside of the timeframe,\nit won't be available in the output. Aggregated events with `is_aggregate=true` in the response will still be returned unless exclude_aggregate is set to `true.`"
            },
            {
              "key": "exclude_aggregate",
              "value": "true",
              "description": "Set `exclude_aggregate` to `true` to only return unaggregated events where `is_aggregate=false` in the response. If the `exclude_aggregate` parameter is set to `true`,\nthen the unaggregated parameter is ignored and will be `true` by default."
            },
            {
              "key": "page",
              "value": "-90656756",
              "description": "By default 1000 results are returned per request. Set page to the number of the page to return with `0` being the first page. The page parameter can only be used\nwhen either unaggregated or exclude_aggregate is set to `true.`"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"events\": [\n    {\n      \"alert_type\": \"info\",\n      \"date_happened\": -60006686,\n      \"device_name\": \"dolore\",\n      \"host\": \"proident in\",\n      \"id\": -22759649,\n      \"id_str\": \"quis labore cupidatat minim\",\n      \"payload\": \"{}\",\n      \"priority\": \"normal\",\n      \"source_type_name\": \"nulla aute\",\n      \"tags\": [\n        \"environment:test\"\n      ],\n      \"text\": \"Oh boy!\",\n      \"title\": \"Did you hear the news today?\",\n      \"url\": \"ex\"\n    },\n    {\n      \"alert_type\": \"info\",\n      \"date_happened\": 12830805,\n      \"device_name\": \"incididunt\",\n      \"host\": \"ex Excepteur eu magna\",\n      \"id\": -86397972,\n      \"id_str\": \"Duis\",\n      \"payload\": \"{}\",\n      \"priority\": \"normal\",\n      \"source_type_name\": \"quis amet voluptate fugiat enim\",\n      \"tags\": [\n        \"environment:test\"\n      ],\n      \"text\": \"Oh boy!\",\n      \"title\": \"Did you hear the news today?\",\n      \"url\": \"tempor\"\n    }\n  ],\n  \"status\": \"laborum consequat\"\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/events?start=-62147425&end=-62147425&priority=normal&sources=tempor Ut sed velit&tags=host:host0&unaggregated=true&exclude_aggregate=true&page=-90656756",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events"
          ],
          "query": [
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "priority",
              "value": "normal",
              "description": "Priority of your events, either `low` or `normal`."
            },
            {
              "key": "sources",
              "value": "tempor Ut sed velit",
              "description": "A comma separated string of sources."
            },
            {
              "key": "tags",
              "value": "host:host0",
              "description": "A comma separated list indicating what tags, if any, should be used to filter the list of events."
            },
            {
              "key": "unaggregated",
              "value": "true",
              "description": "Set unaggregated to `true` to return all events within the specified [`start`,`end`] timeframe.\nOtherwise if an event is aggregated to a parent event with a timestamp outside of the timeframe,\nit won't be available in the output. Aggregated events with `is_aggregate=true` in the response will still be returned unless exclude_aggregate is set to `true.`"
            },
            {
              "key": "exclude_aggregate",
              "value": "true",
              "description": "Set `exclude_aggregate` to `true` to only return unaggregated events where `is_aggregate=false` in the response. If the `exclude_aggregate` parameter is set to `true`,\nthen the unaggregated parameter is ignored and will be `true` by default."
            },
            {
              "key": "page",
              "value": "-90656756",
              "description": "By default 1000 results are returned per request. Set page to the number of the page to return with `0` being the first page. The page parameter can only be used\nwhen either unaggregated or exclude_aggregate is set to `true.`"
            }
          ]
        }
      },
      "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/events?start=-62147425&end=-62147425&priority=normal&sources=tempor Ut sed velit&tags=host:host0&unaggregated=true&exclude_aggregate=true&page=-90656756",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events"
          ],
          "query": [
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "priority",
              "value": "normal",
              "description": "Priority of your events, either `low` or `normal`."
            },
            {
              "key": "sources",
              "value": "tempor Ut sed velit",
              "description": "A comma separated string of sources."
            },
            {
              "key": "tags",
              "value": "host:host0",
              "description": "A comma separated list indicating what tags, if any, should be used to filter the list of events."
            },
            {
              "key": "unaggregated",
              "value": "true",
              "description": "Set unaggregated to `true` to return all events within the specified [`start`,`end`] timeframe.\nOtherwise if an event is aggregated to a parent event with a timestamp outside of the timeframe,\nit won't be available in the output. Aggregated events with `is_aggregate=true` in the response will still be returned unless exclude_aggregate is set to `true.`"
            },
            {
              "key": "exclude_aggregate",
              "value": "true",
              "description": "Set `exclude_aggregate` to `true` to only return unaggregated events where `is_aggregate=false` in the response. If the `exclude_aggregate` parameter is set to `true`,\nthen the unaggregated parameter is ignored and will be `true` by default."
            },
            {
              "key": "page",
              "value": "-90656756",
              "description": "By default 1000 results are returned per request. Set page to the number of the page to return with `0` being the first page. The page parameter can only be used\nwhen either unaggregated or exclude_aggregate is set to `true.`"
            }
          ]
        }
      },
      "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/events?start=-62147425&end=-62147425&priority=normal&sources=tempor Ut sed velit&tags=host:host0&unaggregated=true&exclude_aggregate=true&page=-90656756",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "events"
          ],
          "query": [
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) POSIX timestamp."
            },
            {
              "key": "priority",
              "value": "normal",
              "description": "Priority of your events, either `low` or `normal`."
            },
            {
              "key": "sources",
              "value": "tempor Ut sed velit",
              "description": "A comma separated string of sources."
            },
            {
              "key": "tags",
              "value": "host:host0",
              "description": "A comma separated list indicating what tags, if any, should be used to filter the list of events."
            },
            {
              "key": "unaggregated",
              "value": "true",
              "description": "Set unaggregated to `true` to return all events within the specified [`start`,`end`] timeframe.\nOtherwise if an event is aggregated to a parent event with a timestamp outside of the timeframe,\nit won't be available in the output. Aggregated events with `is_aggregate=true` in the response will still be returned unless exclude_aggregate is set to `true.`"
            },
            {
              "key": "exclude_aggregate",
              "value": "true",
              "description": "Set `exclude_aggregate` to `true` to only return unaggregated events where `is_aggregate=false` in the response. If the `exclude_aggregate` parameter is set to `true`,\nthen the unaggregated parameter is ignored and will be `true` by default."
            },
            {
              "key": "page",
              "value": "-90656756",
              "description": "By default 1000 results are returned per request. Set page to the number of the page to return with `0` being the first page. The page parameter can only be used\nwhen either unaggregated or exclude_aggregate is set to `true.`"
            }
          ]
        }
      },
      "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}"
    }
  ]
}