Chilkat Online Tools

SQL Server / Datadog API Collection / Get a list of events

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'start', -62147425
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'end', -62147425
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'priority', 'normal'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'sources', 'tempor Ut sed velit'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'tags', 'host:host0'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'unaggregated', 'true'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'exclude_aggregate', 'true'
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'page', -90656756

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://api.app.ddog-gov.com/api/v1/events', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @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

    DECLARE @alert_type nvarchar(4000)

    DECLARE @date_happened int

    DECLARE @device_name nvarchar(4000)

    DECLARE @host nvarchar(4000)

    DECLARE @id int

    DECLARE @id_str nvarchar(4000)

    DECLARE @payload nvarchar(4000)

    DECLARE @priority nvarchar(4000)

    DECLARE @source_type_name nvarchar(4000)

    DECLARE @text nvarchar(4000)

    DECLARE @title nvarchar(4000)

    DECLARE @url nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @strVal nvarchar(4000)

    DECLARE @status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'events'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @alert_type OUT, 'events[i].alert_type'
        EXEC sp_OAMethod @jResp, 'IntOf', @date_happened OUT, 'events[i].date_happened'
        EXEC sp_OAMethod @jResp, 'StringOf', @device_name OUT, 'events[i].device_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @host OUT, 'events[i].host'
        EXEC sp_OAMethod @jResp, 'IntOf', @id OUT, 'events[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @id_str OUT, 'events[i].id_str'
        EXEC sp_OAMethod @jResp, 'StringOf', @payload OUT, 'events[i].payload'
        EXEC sp_OAMethod @jResp, 'StringOf', @priority OUT, 'events[i].priority'
        EXEC sp_OAMethod @jResp, 'StringOf', @source_type_name OUT, 'events[i].source_type_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @text OUT, 'events[i].text'
        EXEC sp_OAMethod @jResp, 'StringOf', @title OUT, 'events[i].title'
        EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'events[i].url'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'events[i].tags'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'events[i].tags[j]'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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}"
    }
  ]
}