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.
-- {
-- "description": "Post time-series data that can be graphed on Datadog’s dashboards.",
-- "externalValue": "examples/metrics/distribution-points.json.sh",
-- "summary": "Dynamic Points",
-- "x-variables": {
-- "NOW": "$(date +%s)"
-- }
-- }
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, 'description', 'Post time-series data that can be graphed on Datadog’s dashboards.'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'externalValue', 'examples/metrics/distribution-points.json.sh'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'summary', 'Dynamic Points'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'x-variables.NOW', '$(date +%s)'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'text/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'text/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Encoding', 'identity'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.app.ddog-gov.com/api/v1/distribution_points', 'text/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)
-- {
-- "status": "ok"
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @status nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
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-Encoding: identity"
-H "Content-Type: text/json"
-H "Accept: text/json"
-d '{
"description": "Post time-series data that can be graphed on Datadog’s dashboards.",
"externalValue": "examples/metrics/distribution-points.json.sh",
"summary": "Dynamic Points",
"x-variables": {
"NOW": "$(date +%s)"
}
}'
https://api.app.ddog-gov.com/api/v1/distribution_points
Postman Collection Item JSON
{
"name": "Submit distribution points",
"request": {
"method": "POST",
"header": [
{
"description": "HTTP header used to compress the media-type.",
"key": "Content-Encoding",
"value": "identity"
},
{
"key": "Content-Type",
"value": "text/json"
},
{
"key": "Accept",
"value": "text/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Post time-series data that can be graphed on Datadog’s dashboards.\",\n \"externalValue\": \"examples/metrics/distribution-points.json.sh\",\n \"summary\": \"Dynamic Points\",\n \"x-variables\": {\n \"NOW\": \"$(date +%s)\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/api/v1/distribution_points",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"distribution_points"
]
},
"description": "The distribution points end-point allows you to post distribution data that can be graphed on Datadog’s dashboards."
},
"response": [
{
"name": "Payload accepted",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "HTTP header used to compress the media-type.",
"key": "Content-Encoding",
"value": "deflate"
},
{
"key": "Content-Type",
"value": "text/json"
},
{
"key": "Accept",
"value": "text/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Post time-series data that can be graphed on Datadog’s dashboards.\",\n \"externalValue\": \"examples/metrics/distribution-points.json.sh\",\n \"summary\": \"Dynamic Points\",\n \"x-variables\": {\n \"NOW\": \"$(date +%s)\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/api/v1/distribution_points",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"distribution_points"
]
}
},
"status": "Accepted",
"code": 202,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/json"
}
],
"cookie": [
],
"body": "{\n \"status\": \"ok\"\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "HTTP header used to compress the media-type.",
"key": "Content-Encoding",
"value": "deflate"
},
{
"key": "Content-Type",
"value": "text/json"
},
{
"key": "Accept",
"value": "text/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Post time-series data that can be graphed on Datadog’s dashboards.\",\n \"externalValue\": \"examples/metrics/distribution-points.json.sh\",\n \"summary\": \"Dynamic Points\",\n \"x-variables\": {\n \"NOW\": \"$(date +%s)\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/api/v1/distribution_points",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"distribution_points"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Authentication error",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "HTTP header used to compress the media-type.",
"key": "Content-Encoding",
"value": "deflate"
},
{
"key": "Content-Type",
"value": "text/json"
},
{
"key": "Accept",
"value": "text/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Post time-series data that can be graphed on Datadog’s dashboards.\",\n \"externalValue\": \"examples/metrics/distribution-points.json.sh\",\n \"summary\": \"Dynamic Points\",\n \"x-variables\": {\n \"NOW\": \"$(date +%s)\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/api/v1/distribution_points",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"distribution_points"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Request timeout",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "HTTP header used to compress the media-type.",
"key": "Content-Encoding",
"value": "deflate"
},
{
"key": "Content-Type",
"value": "text/json"
},
{
"key": "Accept",
"value": "text/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Post time-series data that can be graphed on Datadog’s dashboards.\",\n \"externalValue\": \"examples/metrics/distribution-points.json.sh\",\n \"summary\": \"Dynamic Points\",\n \"x-variables\": {\n \"NOW\": \"$(date +%s)\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/api/v1/distribution_points",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"distribution_points"
]
}
},
"status": "Request Timeout",
"code": 408,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Payload too large",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "HTTP header used to compress the media-type.",
"key": "Content-Encoding",
"value": "deflate"
},
{
"key": "Content-Type",
"value": "text/json"
},
{
"key": "Accept",
"value": "text/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Post time-series data that can be graphed on Datadog’s dashboards.\",\n \"externalValue\": \"examples/metrics/distribution-points.json.sh\",\n \"summary\": \"Dynamic Points\",\n \"x-variables\": {\n \"NOW\": \"$(date +%s)\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/api/v1/distribution_points",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"distribution_points"
]
}
},
"status": "Request Entity Too Large",
"code": 413,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "HTTP header used to compress the media-type.",
"key": "Content-Encoding",
"value": "deflate"
},
{
"key": "Content-Type",
"value": "text/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 \"description\": \"Post time-series data that can be graphed on Datadog’s dashboards.\",\n \"externalValue\": \"examples/metrics/distribution-points.json.sh\",\n \"summary\": \"Dynamic Points\",\n \"x-variables\": {\n \"NOW\": \"$(date +%s)\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/api/v1/distribution_points",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"distribution_points"
]
}
},
"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}"
}
]
}