Back to Collection Items
load ./chilkat.dll
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
# Use this online tool to generate code from sample JSON: Generate Code to Create JSON
# The following JSON is sent in the request body.
# {
# "name": "Custom Metric SLO",
# "thresholds": [
# {
# "target": 95,
# "timeframe": "7d"
# },
# {
# "target": 95,
# "timeframe": "30d",
# "warning": 97
# }
# ],
# "type": "metric",
# "description": "non et",
# "groups": [
# "env:prod",
# "role:mysql"
# ],
# "monitor_ids": [
# 19441105,
# -6429790
# ],
# "query": {
# "numerator": "sum:my.custom.metric{type:good}.as_count()",
# "denominator": "sum:my.custom.metric{*}.as_count()"
# },
# "tags": [
# "env:prod",
# "app:core"
# ],
# "target_threshold": 99.9,
# "timeframe": "30d",
# "warning_threshold": 99.95
# }
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "name" "Custom Metric SLO"
CkJsonObject_UpdateInt $json "thresholds[0].target" 95
CkJsonObject_UpdateString $json "thresholds[0].timeframe" "7d"
CkJsonObject_UpdateInt $json "thresholds[1].target" 95
CkJsonObject_UpdateString $json "thresholds[1].timeframe" "30d"
CkJsonObject_UpdateInt $json "thresholds[1].warning" 97
CkJsonObject_UpdateString $json "type" "metric"
CkJsonObject_UpdateString $json "description" "non et"
CkJsonObject_UpdateString $json "groups[0]" "env:prod"
CkJsonObject_UpdateString $json "groups[1]" "role:mysql"
CkJsonObject_UpdateInt $json "monitor_ids[0]" 19441105
CkJsonObject_UpdateInt $json "monitor_ids[1]" -6429790
CkJsonObject_UpdateString $json "query.numerator" "sum:my.custom.metric{type:good}.as_count()"
CkJsonObject_UpdateString $json "query.denominator" "sum:my.custom.metric{*}.as_count()"
CkJsonObject_UpdateString $json "tags[0]" "env:prod"
CkJsonObject_UpdateString $json "tags[1]" "app:core"
CkJsonObject_UpdateNumber $json "target_threshold" "99.9"
CkJsonObject_UpdateString $json "timeframe" "30d"
CkJsonObject_UpdateNumber $json "warning_threshold" "99.95"
CkHttp_SetRequestHeader $http "Content-Type" "application/json"
CkHttp_SetRequestHeader $http "Accept" "application/json"
# resp is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://api.app.ddog-gov.com/api/v1/slo" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkJsonObject $json
exit
}
set sbResponseBody [new_CkStringBuilder]
CkHttpResponse_GetBodySb $resp $sbResponseBody
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0
puts "Response Body:"
puts [CkJsonObject_emit $jResp]
set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
puts "Response Header:"
puts [CkHttpResponse_header $resp]
puts "Failed."
delete_CkHttpResponse $resp
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
exit
}
delete_CkHttpResponse $resp
# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)
# {
# "data": [
# {
# "name": "Custom Metric SLO",
# "thresholds": [
# {
# "target": 95,
# "timeframe": "7d"
# },
# {
# "target": 95,
# "timeframe": "30d",
# "warning": 97
# }
# ],
# "type": "metric",
# "created_at": -94400396,
# "creator": {
# "email": "esse ullamco",
# "handle": "pariatur irure sit non",
# "name": "in proident laborum"
# },
# "description": "est proident magna reprehenderit",
# "groups": [
# "env:prod",
# "role:mysql"
# ],
# "id": "ipsum laboris consequat",
# "modified_at": -34908193,
# "monitor_ids": [
# 35412081,
# -51315393
# ],
# "monitor_tags": [
# "voluptate adipisicing fugiat elit",
# "reprehenderit et nostrud pariatur Excepteur"
# ],
# "query": {
# "numerator": "sum:my.custom.metric{type:good}.as_count()",
# "denominator": "sum:my.custom.metric{*}.as_count()"
# },
# "tags": [
# "env:prod",
# "app:core"
# ],
# "target_threshold": 99.9,
# "timeframe": "30d",
# "warning_threshold": 99.95
# },
# {
# "name": "Custom Metric SLO",
# "thresholds": [
# {
# "target": 95,
# "timeframe": "7d"
# },
# {
# "target": 95,
# "timeframe": "30d",
# "warning": 97
# }
# ],
# "type": "metric",
# "created_at": -83055437,
# "creator": {
# "email": "exercitation",
# "handle": "commodo aute incididunt ut",
# "name": "Lorem dolor irure"
# },
# "description": "do nostrud ex sit",
# "groups": [
# "env:prod",
# "role:mysql"
# ],
# "id": "ut elit commodo",
# "modified_at": -65512371,
# "monitor_ids": [
# 70922825,
# -10561601
# ],
# "monitor_tags": [
# "laborum aliqua proident",
# "ullamco cillum ea consectetur"
# ],
# "query": {
# "numerator": "sum:my.custom.metric{type:good}.as_count()",
# "denominator": "sum:my.custom.metric{*}.as_count()"
# },
# "tags": [
# "env:prod",
# "app:core"
# ],
# "target_threshold": 99.9,
# "timeframe": "30d",
# "warning_threshold": 99.95
# }
# ],
# "errors": [
# "deserunt in fugiat",
# "proident"
# ],
# "metadata": {
# "page": {
# "total_count": 69715777,
# "total_filtered_count": -16033264
# }
# }
# }
# Sample code for parsing the JSON response...
# Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
set Total_count [CkJsonObject_IntOf $jResp "metadata.page.total_count"]
set Total_filtered_count [CkJsonObject_IntOf $jResp "metadata.page.total_filtered_count"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "data"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set name [CkJsonObject_stringOf $jResp "data[i].name"]
set v_type [CkJsonObject_stringOf $jResp "data[i].type"]
set created_at [CkJsonObject_IntOf $jResp "data[i].created_at"]
set v_Email [CkJsonObject_stringOf $jResp "data[i].creator.email"]
set Handle [CkJsonObject_stringOf $jResp "data[i].creator.handle"]
set Name [CkJsonObject_stringOf $jResp "data[i].creator.name"]
set description [CkJsonObject_stringOf $jResp "data[i].description"]
set id [CkJsonObject_stringOf $jResp "data[i].id"]
set modified_at [CkJsonObject_IntOf $jResp "data[i].modified_at"]
set Numerator [CkJsonObject_stringOf $jResp "data[i].query.numerator"]
set Denominator [CkJsonObject_stringOf $jResp "data[i].query.denominator"]
set target_threshold [CkJsonObject_stringOf $jResp "data[i].target_threshold"]
set timeframe [CkJsonObject_stringOf $jResp "data[i].timeframe"]
set warning_threshold [CkJsonObject_stringOf $jResp "data[i].warning_threshold"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "data[i].thresholds"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set target [CkJsonObject_IntOf $jResp "data[i].thresholds[j].target"]
set timeframe [CkJsonObject_stringOf $jResp "data[i].thresholds[j].timeframe"]
set warning [CkJsonObject_IntOf $jResp "data[i].thresholds[j].warning"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "data[i].groups"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set strVal [CkJsonObject_stringOf $jResp "data[i].groups[j]"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "data[i].monitor_ids"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set intVal [CkJsonObject_IntOf $jResp "data[i].monitor_ids[j]"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "data[i].monitor_tags"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set strVal [CkJsonObject_stringOf $jResp "data[i].monitor_tags[j]"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "data[i].tags"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set strVal [CkJsonObject_stringOf $jResp "data[i].tags[j]"]
set j [expr $j + 1]
}
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "errors"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set strVal [CkJsonObject_stringOf $jResp "errors[i]"]
set i [expr $i + 1]
}
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"name": "Custom Metric SLO",
"thresholds": [
{
"target": 95,
"timeframe": "7d"
},
{
"target": 95,
"timeframe": "30d",
"warning": 97
}
],
"type": "metric",
"description": "non et",
"groups": [
"env:prod",
"role:mysql"
],
"monitor_ids": [
19441105,
-6429790
],
"query": {
"numerator": "sum:my.custom.metric{type:good}.as_count()",
"denominator": "sum:my.custom.metric{*}.as_count()"
},
"tags": [
"env:prod",
"app:core"
],
"target_threshold": 99.9,
"timeframe": "30d",
"warning_threshold": 99.95
}'
https://api.app.ddog-gov.com/api/v1/slo
Postman Collection Item JSON
{
"name": "Create an SLO object",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Custom Metric SLO\",\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"type\": \"metric\",\n \"description\": \"non et\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"monitor_ids\": [\n 19441105,\n -6429790\n ],\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"timeframe\": \"30d\",\n \"warning_threshold\": 99.95\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo"
]
},
"description": "Create a service level objective object."
},
"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 \"name\": \"Custom Metric SLO\",\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"type\": \"metric\",\n \"description\": \"non et\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"monitor_ids\": [\n 19441105,\n -6429790\n ],\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"timeframe\": \"30d\",\n \"warning_threshold\": 99.95\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": [\n {\n \"name\": \"Custom Metric SLO\",\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"type\": \"metric\",\n \"created_at\": -94400396,\n \"creator\": {\n \"email\": \"esse ullamco\",\n \"handle\": \"pariatur irure sit non\",\n \"name\": \"in proident laborum\"\n },\n \"description\": \"est proident magna reprehenderit\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"id\": \"ipsum laboris consequat\",\n \"modified_at\": -34908193,\n \"monitor_ids\": [\n 35412081,\n -51315393\n ],\n \"monitor_tags\": [\n \"voluptate adipisicing fugiat elit\",\n \"reprehenderit et nostrud pariatur Excepteur\"\n ],\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"timeframe\": \"30d\",\n \"warning_threshold\": 99.95\n },\n {\n \"name\": \"Custom Metric SLO\",\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"type\": \"metric\",\n \"created_at\": -83055437,\n \"creator\": {\n \"email\": \"exercitation\",\n \"handle\": \"commodo aute incididunt ut\",\n \"name\": \"Lorem dolor irure\"\n },\n \"description\": \"do nostrud ex sit\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"id\": \"ut elit commodo\",\n \"modified_at\": -65512371,\n \"monitor_ids\": [\n 70922825,\n -10561601\n ],\n \"monitor_tags\": [\n \"laborum aliqua proident\",\n \"ullamco cillum ea consectetur\"\n ],\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"timeframe\": \"30d\",\n \"warning_threshold\": 99.95\n }\n ],\n \"errors\": [\n \"deserunt in fugiat\",\n \"proident\"\n ],\n \"metadata\": {\n \"page\": {\n \"total_count\": 69715777,\n \"total_filtered_count\": -16033264\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 \"name\": \"Custom Metric SLO\",\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"type\": \"metric\",\n \"description\": \"non et\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"monitor_ids\": [\n 19441105,\n -6429790\n ],\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"timeframe\": \"30d\",\n \"warning_threshold\": 99.95\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo"
]
}
},
"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": "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 \"name\": \"Custom Metric SLO\",\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"type\": \"metric\",\n \"description\": \"non et\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"monitor_ids\": [\n 19441105,\n -6429790\n ],\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"timeframe\": \"30d\",\n \"warning_threshold\": 99.95\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo"
]
}
},
"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": "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 \"name\": \"Custom Metric SLO\",\n \"thresholds\": [\n {\n \"target\": 95,\n \"timeframe\": \"7d\"\n },\n {\n \"target\": 95,\n \"timeframe\": \"30d\",\n \"warning\": 97\n }\n ],\n \"type\": \"metric\",\n \"description\": \"non et\",\n \"groups\": [\n \"env:prod\",\n \"role:mysql\"\n ],\n \"monitor_ids\": [\n 19441105,\n -6429790\n ],\n \"query\": {\n \"numerator\": \"sum:my.custom.metric{type:good}.as_count()\",\n \"denominator\": \"sum:my.custom.metric{*}.as_count()\"\n },\n \"tags\": [\n \"env:prod\",\n \"app:core\"\n ],\n \"target_threshold\": 99.9,\n \"timeframe\": \"30d\",\n \"warning_threshold\": 99.95\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/slo",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"slo"
]
}
},
"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}"
}
]
}