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
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "data": {
-- "attributes": {
-- "filter": {
-- "from": "now-15m",
-- "query": "*",
-- "to": "now"
-- },
-- "options": {
-- "timeOffset": "<long>",
-- "timezone": "UTC"
-- },
-- "page": {
-- "cursor": "<string>",
-- "limit": 10
-- },
-- "sort": "-timestamp"
-- },
-- "type": "search_request"
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.filter.from', 'now-15m'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.filter.query', '*'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.filter.to', 'now'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.options.timeOffset', '<long>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.options.timezone', 'UTC'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.page.cursor', '<string>'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'data.attributes.page.limit', 10
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.attributes.sort', '-timestamp'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'data.type', 'search_request'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.app.ddog-gov.com/api/v2/spans/events/search', 'application/json', @json
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 @json
RETURN
END
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.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 @json
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)
-- {
-- "data": [
-- {
-- "attributes": {
-- "attributes": {
-- "culpac": {}
-- },
-- "custom": {
-- "aliquip_8": {},
-- "commodo_9c1": {}
-- },
-- "end_timestamp": "<dateTime>",
-- "env": "<string>",
-- "host": "<string>",
-- "ingestion_reason": "<string>",
-- "parent_id": "<string>",
-- "resource_hash": "<string>",
-- "resource_name": "<string>",
-- "retained_by": "<string>",
-- "service": "<string>",
-- "single_span": "<boolean>",
-- "span_id": "<string>",
-- "start_timestamp": "<dateTime>",
-- "tags": [
-- "<string>",
-- "<string>"
-- ],
-- "trace_id": "<string>",
-- "type": "<string>"
-- },
-- "id": "<string>",
-- "type": "spans"
-- },
-- {
-- "attributes": {
-- "attributes": {
-- "Lorem_c": {}
-- },
-- "custom": {
-- "culpa_c": {},
-- "consectetur_cf": {}
-- },
-- "end_timestamp": "<dateTime>",
-- "env": "<string>",
-- "host": "<string>",
-- "ingestion_reason": "<string>",
-- "parent_id": "<string>",
-- "resource_hash": "<string>",
-- "resource_name": "<string>",
-- "retained_by": "<string>",
-- "service": "<string>",
-- "single_span": "<boolean>",
-- "span_id": "<string>",
-- "start_timestamp": "<dateTime>",
-- "tags": [
-- "<string>",
-- "<string>"
-- ],
-- "trace_id": "<string>",
-- "type": "<string>"
-- },
-- "id": "<string>",
-- "type": "spans"
-- }
-- ],
-- "links": {
-- "next": "<string>"
-- },
-- "meta": {
-- "elapsed": "<long>",
-- "page": {
-- "after": "<string>"
-- },
-- "request_id": "<string>",
-- "status": "timeout",
-- "warnings": [
-- {
-- "code": "<string>",
-- "detail": "<string>",
-- "title": "<string>"
-- },
-- {
-- "code": "<string>",
-- "detail": "<string>",
-- "title": "<string>"
-- }
-- ]
-- }
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @End_timestamp nvarchar(4000)
DECLARE @Env nvarchar(4000)
DECLARE @Host nvarchar(4000)
DECLARE @Ingestion_reason nvarchar(4000)
DECLARE @Parent_id nvarchar(4000)
DECLARE @Resource_hash nvarchar(4000)
DECLARE @Resource_name nvarchar(4000)
DECLARE @Retained_by nvarchar(4000)
DECLARE @Service nvarchar(4000)
DECLARE @Single_span nvarchar(4000)
DECLARE @Span_id nvarchar(4000)
DECLARE @Start_timestamp nvarchar(4000)
DECLARE @Trace_id nvarchar(4000)
DECLARE @v_Type nvarchar(4000)
DECLARE @id nvarchar(4000)
DECLARE @v_type nvarchar(4000)
DECLARE @j int
DECLARE @count_j int
DECLARE @strVal nvarchar(4000)
DECLARE @code nvarchar(4000)
DECLARE @detail nvarchar(4000)
DECLARE @title nvarchar(4000)
DECLARE @v_Next nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_Next OUT, 'links.next'
DECLARE @Elapsed nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Elapsed OUT, 'meta.elapsed'
DECLARE @After nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @After OUT, 'meta.page.after'
DECLARE @Request_id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Request_id OUT, 'meta.request_id'
DECLARE @Status nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Status OUT, 'meta.status'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @End_timestamp OUT, 'data[i].attributes.end_timestamp'
EXEC sp_OAMethod @jResp, 'StringOf', @Env OUT, 'data[i].attributes.env'
EXEC sp_OAMethod @jResp, 'StringOf', @Host OUT, 'data[i].attributes.host'
EXEC sp_OAMethod @jResp, 'StringOf', @Ingestion_reason OUT, 'data[i].attributes.ingestion_reason'
EXEC sp_OAMethod @jResp, 'StringOf', @Parent_id OUT, 'data[i].attributes.parent_id'
EXEC sp_OAMethod @jResp, 'StringOf', @Resource_hash OUT, 'data[i].attributes.resource_hash'
EXEC sp_OAMethod @jResp, 'StringOf', @Resource_name OUT, 'data[i].attributes.resource_name'
EXEC sp_OAMethod @jResp, 'StringOf', @Retained_by OUT, 'data[i].attributes.retained_by'
EXEC sp_OAMethod @jResp, 'StringOf', @Service OUT, 'data[i].attributes.service'
EXEC sp_OAMethod @jResp, 'StringOf', @Single_span OUT, 'data[i].attributes.single_span'
EXEC sp_OAMethod @jResp, 'StringOf', @Span_id OUT, 'data[i].attributes.span_id'
EXEC sp_OAMethod @jResp, 'StringOf', @Start_timestamp OUT, 'data[i].attributes.start_timestamp'
EXEC sp_OAMethod @jResp, 'StringOf', @Trace_id OUT, 'data[i].attributes.trace_id'
EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'data[i].attributes.type'
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'data[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'data[i].type'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'data[i].attributes.tags'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'data[i].attributes.tags[j]'
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'meta.warnings'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @code OUT, 'meta.warnings[i].code'
EXEC sp_OAMethod @jResp, 'StringOf', @detail OUT, 'meta.warnings[i].detail'
EXEC sp_OAMethod @jResp, 'StringOf', @title OUT, 'meta.warnings[i].title'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"attributes": {
"filter": {
"from": "now-15m",
"query": "*",
"to": "now"
},
"options": {
"timeOffset": "<long>",
"timezone": "UTC"
},
"page": {
"cursor": "<string>",
"limit": 10
},
"sort": "-timestamp"
},
"type": "search_request"
}
}'
https://api.app.ddog-gov.com/api/v2/spans/events/search
Postman Collection Item JSON
{
"name": "Search spans",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"filter\": {\n \"from\": \"now-15m\",\n \"query\": \"*\",\n \"to\": \"now\"\n },\n \"options\": {\n \"timeOffset\": \"<long>\",\n \"timezone\": \"UTC\"\n },\n \"page\": {\n \"cursor\": \"<string>\",\n \"limit\": 10\n },\n \"sort\": \"-timestamp\"\n },\n \"type\": \"search_request\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/spans/events/search",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"spans",
"events",
"search"
]
},
"description": "List endpoint returns spans that match a span search query.\n[Results are paginated][1].\n\nUse this endpoint to build complex spans filtering and search.\nThis endpoint is rate limited to `300` requests per hour.\n\n[1]: /logs/guide/collect-multiple-logs-with-pagination?tab=v2api"
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"filter\": {\n \"from\": \"now-15m\",\n \"query\": \"*\",\n \"to\": \"now\"\n },\n \"options\": {\n \"timeOffset\": \"<long>\",\n \"timezone\": \"UTC\"\n },\n \"page\": {\n \"cursor\": \"<string>\",\n \"limit\": 10\n },\n \"sort\": \"-timestamp\"\n },\n \"type\": \"search_request\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/spans/events/search",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"spans",
"events",
"search"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"attributes\": {\n \"attributes\": {\n \"culpac\": {}\n },\n \"custom\": {\n \"aliquip_8\": {},\n \"commodo_9c1\": {}\n },\n \"end_timestamp\": \"<dateTime>\",\n \"env\": \"<string>\",\n \"host\": \"<string>\",\n \"ingestion_reason\": \"<string>\",\n \"parent_id\": \"<string>\",\n \"resource_hash\": \"<string>\",\n \"resource_name\": \"<string>\",\n \"retained_by\": \"<string>\",\n \"service\": \"<string>\",\n \"single_span\": \"<boolean>\",\n \"span_id\": \"<string>\",\n \"start_timestamp\": \"<dateTime>\",\n \"tags\": [\n \"<string>\",\n \"<string>\"\n ],\n \"trace_id\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"spans\"\n },\n {\n \"attributes\": {\n \"attributes\": {\n \"Lorem_c\": {}\n },\n \"custom\": {\n \"culpa_c\": {},\n \"consectetur_cf\": {}\n },\n \"end_timestamp\": \"<dateTime>\",\n \"env\": \"<string>\",\n \"host\": \"<string>\",\n \"ingestion_reason\": \"<string>\",\n \"parent_id\": \"<string>\",\n \"resource_hash\": \"<string>\",\n \"resource_name\": \"<string>\",\n \"retained_by\": \"<string>\",\n \"service\": \"<string>\",\n \"single_span\": \"<boolean>\",\n \"span_id\": \"<string>\",\n \"start_timestamp\": \"<dateTime>\",\n \"tags\": [\n \"<string>\",\n \"<string>\"\n ],\n \"trace_id\": \"<string>\",\n \"type\": \"<string>\"\n },\n \"id\": \"<string>\",\n \"type\": \"spans\"\n }\n ],\n \"links\": {\n \"next\": \"<string>\"\n },\n \"meta\": {\n \"elapsed\": \"<long>\",\n \"page\": {\n \"after\": \"<string>\"\n },\n \"request_id\": \"<string>\",\n \"status\": \"timeout\",\n \"warnings\": [\n {\n \"code\": \"<string>\",\n \"detail\": \"<string>\",\n \"title\": \"<string>\"\n },\n {\n \"code\": \"<string>\",\n \"detail\": \"<string>\",\n \"title\": \"<string>\"\n }\n ]\n }\n}"
},
{
"name": "Bad Request.",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"filter\": {\n \"from\": \"now-15m\",\n \"query\": \"*\",\n \"to\": \"now\"\n },\n \"options\": {\n \"timeOffset\": \"<long>\",\n \"timezone\": \"UTC\"\n },\n \"page\": {\n \"cursor\": \"<string>\",\n \"limit\": 10\n },\n \"sort\": \"-timestamp\"\n },\n \"type\": \"search_request\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/spans/events/search",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"spans",
"events",
"search"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n },\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n }\n ]\n}"
},
{
"name": "Forbidden: Access denied.",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"filter\": {\n \"from\": \"now-15m\",\n \"query\": \"*\",\n \"to\": \"now\"\n },\n \"options\": {\n \"timeOffset\": \"<long>\",\n \"timezone\": \"UTC\"\n },\n \"page\": {\n \"cursor\": \"<string>\",\n \"limit\": 10\n },\n \"sort\": \"-timestamp\"\n },\n \"type\": \"search_request\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/spans/events/search",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"spans",
"events",
"search"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n },\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n }\n ]\n}"
},
{
"name": "Unprocessable Entity.",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"filter\": {\n \"from\": \"now-15m\",\n \"query\": \"*\",\n \"to\": \"now\"\n },\n \"options\": {\n \"timeOffset\": \"<long>\",\n \"timezone\": \"UTC\"\n },\n \"page\": {\n \"cursor\": \"<string>\",\n \"limit\": 10\n },\n \"sort\": \"-timestamp\"\n },\n \"type\": \"search_request\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/spans/events/search",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"spans",
"events",
"search"
]
}
},
"status": "Unprocessable Entity (WebDAV) (RFC 4918)",
"code": 422,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n },\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n }\n ]\n}"
},
{
"name": "Too many requests: The rate limit set by the API has been exceeded.",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"attributes\": {\n \"filter\": {\n \"from\": \"now-15m\",\n \"query\": \"*\",\n \"to\": \"now\"\n },\n \"options\": {\n \"timeOffset\": \"<long>\",\n \"timezone\": \"UTC\"\n },\n \"page\": {\n \"cursor\": \"<string>\",\n \"limit\": 10\n },\n \"sort\": \"-timestamp\"\n },\n \"type\": \"search_request\"\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/spans/events/search",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"spans",
"events",
"search"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n },\n {\n \"detail\": \"<string>\",\n \"status\": \"<string>\",\n \"title\": \"<string>\"\n }\n ]\n}"
}
]
}