VBScript / Datadog API Collection / Create a monitor configuration policy
Back to Collection Items
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Http")
set http = CreateObject("Chilkat.Http")
' 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": {
' "type": "monitor-config-policy",
' "attributes": {
' "policy_type": "tag",
' "policy": {
' "tag_key": "<string>",
' "tag_key_required": "<boolean>",
' "valid_tag_values": [
' "<string>",
' "<string>"
' ]
' }
' }
' }
' }
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.JsonObject")
set json = CreateObject("Chilkat.JsonObject")
success = json.UpdateString("data.type","monitor-config-policy")
success = json.UpdateString("data.attributes.policy_type","tag")
success = json.UpdateString("data.attributes.policy.tag_key","<string>")
success = json.UpdateString("data.attributes.policy.tag_key_required","<boolean>")
success = json.UpdateString("data.attributes.policy.valid_tag_values[0]","<string>")
success = json.UpdateString("data.attributes.policy.valid_tag_values[1]","<string>")
http.SetRequestHeader "Content-Type","application/json"
http.SetRequestHeader "Accept","application/json"
' resp is a Chilkat.HttpResponse
Set resp = http.PostJson3("https://api.app.ddog-gov.com/api/v2/monitor/policy","application/json",json)
If (http.LastMethodSuccess = 0) Then
outFile.WriteLine(http.LastErrorText)
WScript.Quit
End If
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder")
set sbResponseBody = CreateObject("Chilkat.StringBuilder")
success = resp.GetBodySb(sbResponseBody)
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.JsonObject")
set jResp = CreateObject("Chilkat.JsonObject")
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0
outFile.WriteLine("Response Body:")
outFile.WriteLine(jResp.Emit())
respStatusCode = resp.StatusCode
outFile.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
outFile.WriteLine("Response Header:")
outFile.WriteLine(resp.Header)
outFile.WriteLine("Failed.")
WScript.Quit
End If
' Sample JSON response:
' (Sample code for parsing the JSON response is shown below)
' {
' "data": {
' "attributes": {
' "policy": {
' "tag_key": "<string>",
' "tag_key_required": "<boolean>",
' "valid_tag_values": [
' "<string>",
' "<string>"
' ]
' },
' "policy_type": "tag"
' },
' "id": "<string>",
' "type": "monitor-config-policy"
' }
' }
' Sample code for parsing the JSON response...
' Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Tag_key = jResp.StringOf("data.attributes.policy.tag_key")
Tag_key_required = jResp.StringOf("data.attributes.policy.tag_key_required")
Policy_type = jResp.StringOf("data.attributes.policy_type")
Id = jResp.StringOf("data.id")
v_Type = jResp.StringOf("data.type")
i = 0
count_i = jResp.SizeOfArray("data.attributes.policy.valid_tag_values")
Do While i < count_i
jResp.I = i
strVal = jResp.StringOf("data.attributes.policy.valid_tag_values[i]")
i = i + 1
Loop
outFile.Close
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"data": {
"type": "monitor-config-policy",
"attributes": {
"policy_type": "tag",
"policy": {
"tag_key": "<string>",
"tag_key_required": "<boolean>",
"valid_tag_values": [
"<string>",
"<string>"
]
}
}
}
}'
https://api.app.ddog-gov.com/api/v2/monitor/policy
Postman Collection Item JSON
{
"name": "Create a monitor configuration policy",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"data\": {\n \"type\": \"monitor-config-policy\",\n \"attributes\": {\n \"policy_type\": \"tag\",\n \"policy\": {\n \"tag_key\": \"<string>\",\n \"tag_key_required\": \"<boolean>\",\n \"valid_tag_values\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/monitor/policy",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"monitor",
"policy"
]
},
"description": "Create a monitor configuration policy."
},
"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 \"type\": \"monitor-config-policy\",\n \"attributes\": {\n \"policy_type\": \"tag\",\n \"policy\": {\n \"tag_key\": \"<string>\",\n \"tag_key_required\": \"<boolean>\",\n \"valid_tag_values\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/monitor/policy",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"monitor",
"policy"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"attributes\": {\n \"policy\": {\n \"tag_key\": \"<string>\",\n \"tag_key_required\": \"<boolean>\",\n \"valid_tag_values\": [\n \"<string>\",\n \"<string>\"\n ]\n },\n \"policy_type\": \"tag\"\n },\n \"id\": \"<string>\",\n \"type\": \"monitor-config-policy\"\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 \"type\": \"monitor-config-policy\",\n \"attributes\": {\n \"policy_type\": \"tag\",\n \"policy\": {\n \"tag_key\": \"<string>\",\n \"tag_key_required\": \"<boolean>\",\n \"valid_tag_values\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/monitor/policy",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"monitor",
"policy"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
},
{
"name": "Forbidden",
"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 \"type\": \"monitor-config-policy\",\n \"attributes\": {\n \"policy_type\": \"tag\",\n \"policy\": {\n \"tag_key\": \"<string>\",\n \"tag_key_required\": \"<boolean>\",\n \"valid_tag_values\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/monitor/policy",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"monitor",
"policy"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\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 \"data\": {\n \"type\": \"monitor-config-policy\",\n \"attributes\": {\n \"policy_type\": \"tag\",\n \"policy\": {\n \"tag_key\": \"<string>\",\n \"tag_key_required\": \"<boolean>\",\n \"valid_tag_values\": [\n \"<string>\",\n \"<string>\"\n ]\n }\n }\n }\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v2/monitor/policy",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"monitor",
"policy"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"<string>\",\n \"<string>\"\n ]\n}"
}
]
}