Chilkat Online Tools

PowerBuilder / Datadog API Collection / Create an SLO object

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Name
string ls_V_type
integer li_Created_at
string ls_V_Email
string ls_Handle
string ls_Name
string ls_Description
string ls_Id
integer li_Modified_at
string ls_Numerator
string ls_Denominator
string ls_Target_threshold
string ls_Timeframe
string ls_Warning_threshold
integer j
integer li_Count_j
integer li_Target
integer li_Warning
string ls_StrVal
integer li_IntVal
integer li_Total_count
integer li_Total_filtered_count
integer i
integer li_Count_i

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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
// }

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("name","Custom Metric SLO")
loo_Json.UpdateInt("thresholds[0].target",95)
loo_Json.UpdateString("thresholds[0].timeframe","7d")
loo_Json.UpdateInt("thresholds[1].target",95)
loo_Json.UpdateString("thresholds[1].timeframe","30d")
loo_Json.UpdateInt("thresholds[1].warning",97)
loo_Json.UpdateString("type","metric")
loo_Json.UpdateString("description","non et")
loo_Json.UpdateString("groups[0]","env:prod")
loo_Json.UpdateString("groups[1]","role:mysql")
loo_Json.UpdateInt("monitor_ids[0]",19441105)
loo_Json.UpdateInt("monitor_ids[1]",-6429790)
loo_Json.UpdateString("query.numerator","sum:my.custom.metric{type:good}.as_count()")
loo_Json.UpdateString("query.denominator","sum:my.custom.metric{*}.as_count()")
loo_Json.UpdateString("tags[0]","env:prod")
loo_Json.UpdateString("tags[1]","app:core")
loo_Json.UpdateNumber("target_threshold","99.9")
loo_Json.UpdateString("timeframe","30d")
loo_Json.UpdateNumber("warning_threshold","99.95")

loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Http.SetRequestHeader("Accept","application/json")

loo_Resp = loo_Http.PostJson3("https://api.app.ddog-gov.com/api/v1/slo","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_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

li_Total_count = loo_JResp.IntOf("metadata.page.total_count")
li_Total_filtered_count = loo_JResp.IntOf("metadata.page.total_filtered_count")
i = 0
li_Count_i = loo_JResp.SizeOfArray("data")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Name = loo_JResp.StringOf("data[i].name")
    ls_V_type = loo_JResp.StringOf("data[i].type")
    li_Created_at = loo_JResp.IntOf("data[i].created_at")
    ls_V_Email = loo_JResp.StringOf("data[i].creator.email")
    ls_Handle = loo_JResp.StringOf("data[i].creator.handle")
    ls_Name = loo_JResp.StringOf("data[i].creator.name")
    ls_Description = loo_JResp.StringOf("data[i].description")
    ls_Id = loo_JResp.StringOf("data[i].id")
    li_Modified_at = loo_JResp.IntOf("data[i].modified_at")
    ls_Numerator = loo_JResp.StringOf("data[i].query.numerator")
    ls_Denominator = loo_JResp.StringOf("data[i].query.denominator")
    ls_Target_threshold = loo_JResp.StringOf("data[i].target_threshold")
    ls_Timeframe = loo_JResp.StringOf("data[i].timeframe")
    ls_Warning_threshold = loo_JResp.StringOf("data[i].warning_threshold")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data[i].thresholds")
    do while j < li_Count_j
        loo_JResp.J = j
        li_Target = loo_JResp.IntOf("data[i].thresholds[j].target")
        ls_Timeframe = loo_JResp.StringOf("data[i].thresholds[j].timeframe")
        li_Warning = loo_JResp.IntOf("data[i].thresholds[j].warning")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data[i].groups")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data[i].groups[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data[i].monitor_ids")
    do while j < li_Count_j
        loo_JResp.J = j
        li_IntVal = loo_JResp.IntOf("data[i].monitor_ids[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data[i].monitor_tags")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data[i].monitor_tags[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data[i].tags")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data[i].tags[j]")
        j = j + 1
    loop
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("errors")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("errors[i]")
    i = i + 1
loop


destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_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}"
    }
  ]
}