Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sStrVal
String sAlert_type
Integer iDate_happened
String sDevice_name
String sHost
Integer iId
String sId_str
String sPayload
String sPriority
String sSource_type_name
String sText
String sTitle
String sV_Url
String sStatus
Integer i
Integer iCount_i
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "title": "Did you hear the news today?",
// "text": "Oh boy!",
// "aggregation_key": "officia ex veniam",
// "alert_type": "info",
// "date_happened": 73027040,
// "device_name": "ut eu fugiat cul",
// "host": "i",
// "priority": "normal",
// "related_event_id": -43026196,
// "source_type_name": "Lorem Ut",
// "tags": [
// "environment:test"
// ]
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "title" "Did you hear the news today?" To iSuccess
Get ComUpdateString Of hoJson "text" "Oh boy!" To iSuccess
Get ComUpdateString Of hoJson "aggregation_key" "officia ex veniam" To iSuccess
Get ComUpdateString Of hoJson "alert_type" "info" To iSuccess
Get ComUpdateInt Of hoJson "date_happened" 73027040 To iSuccess
Get ComUpdateString Of hoJson "device_name" "ut eu fugiat cul" To iSuccess
Get ComUpdateString Of hoJson "host" "i" To iSuccess
Get ComUpdateString Of hoJson "priority" "normal" To iSuccess
Get ComUpdateInt Of hoJson "related_event_id" -43026196 To iSuccess
Get ComUpdateString Of hoJson "source_type_name" "Lorem Ut" To iSuccess
Get ComUpdateString Of hoJson "tags[0]" "environment:test" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Send ComSetRequestHeader To hoHttp "Accept" "application/json"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://api.app.ddog-gov.com/api/v1/events" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// 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
Get ComStringOf Of hoJResp "event.alert_type" To sAlert_type
Get ComIntOf Of hoJResp "event.date_happened" To iDate_happened
Get ComStringOf Of hoJResp "event.device_name" To sDevice_name
Get ComStringOf Of hoJResp "event.host" To sHost
Get ComIntOf Of hoJResp "event.id" To iId
Get ComStringOf Of hoJResp "event.id_str" To sId_str
Get ComStringOf Of hoJResp "event.payload" To sPayload
Get ComStringOf Of hoJResp "event.priority" To sPriority
Get ComStringOf Of hoJResp "event.source_type_name" To sSource_type_name
Get ComStringOf Of hoJResp "event.text" To sText
Get ComStringOf Of hoJResp "event.title" To sTitle
Get ComStringOf Of hoJResp "event.url" To sV_Url
Get ComStringOf Of hoJResp "status" To sStatus
Move 0 To i
Get ComSizeOfArray Of hoJResp "event.tags" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "event.tags[i]" To sStrVal
Move (i + 1) To i
Loop
End_Procedure
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"title": "Did you hear the news today?",
"text": "Oh boy!",
"aggregation_key": "officia ex veniam",
"alert_type": "info",
"date_happened": 73027040,
"device_name": "ut eu fugiat cul",
"host": "i",
"priority": "normal",
"related_event_id": -43026196,
"source_type_name": "Lorem Ut",
"tags": [
"environment:test"
]
}'
https://api.app.ddog-gov.com/api/v1/events
Postman Collection Item JSON
{
"name": "Post an event",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"title\": \"Did you hear the news today?\",\n \"text\": \"Oh boy!\",\n \"aggregation_key\": \"officia ex veniam\",\n \"alert_type\": \"info\",\n \"date_happened\": 73027040,\n \"device_name\": \"ut eu fugiat cul\",\n \"host\": \"i\",\n \"priority\": \"normal\",\n \"related_event_id\": -43026196,\n \"source_type_name\": \"Lorem Ut\",\n \"tags\": [\n \"environment:test\"\n ]\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/events",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events"
]
},
"description": "This endpoint allows you to post events to the stream.\nTag them, set priority and event aggregate them with other events."
},
"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 \"title\": \"Did you hear the news today?\",\n \"text\": \"Oh boy!\",\n \"aggregation_key\": \"officia ex veniam\",\n \"alert_type\": \"info\",\n \"date_happened\": 73027040,\n \"device_name\": \"ut eu fugiat cul\",\n \"host\": \"i\",\n \"priority\": \"normal\",\n \"related_event_id\": -43026196,\n \"source_type_name\": \"Lorem Ut\",\n \"tags\": [\n \"environment:test\"\n ]\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/events",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events"
]
}
},
"status": "Accepted",
"code": 202,
"_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": "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 \"title\": \"Did you hear the news today?\",\n \"text\": \"Oh boy!\",\n \"aggregation_key\": \"officia ex veniam\",\n \"alert_type\": \"info\",\n \"date_happened\": 73027040,\n \"device_name\": \"ut eu fugiat cul\",\n \"host\": \"i\",\n \"priority\": \"normal\",\n \"related_event_id\": -43026196,\n \"source_type_name\": \"Lorem Ut\",\n \"tags\": [\n \"environment:test\"\n ]\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/events",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events"
]
}
},
"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": "Too many requests",
"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 \"title\": \"Did you hear the news today?\",\n \"text\": \"Oh boy!\",\n \"aggregation_key\": \"officia ex veniam\",\n \"alert_type\": \"info\",\n \"date_happened\": 73027040,\n \"device_name\": \"ut eu fugiat cul\",\n \"host\": \"i\",\n \"priority\": \"normal\",\n \"related_event_id\": -43026196,\n \"source_type_name\": \"Lorem Ut\",\n \"tags\": [\n \"environment:test\"\n ]\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/events",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"events"
]
}
},
"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}"
}
]
}