Chilkat Online Tools

PowerBuilder / Datadog API Collection / Get an SLO's details

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_IntVal
string ls_StrVal
integer li_Target
string ls_Timeframe
integer li_Warning
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_DataName
string ls_Numerator
string ls_Denominator
string ls_Target_threshold
string ls_Timeframe
string ls_V_Type
string ls_Warning_threshold
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
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_QueryParams = create oleobject
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_QueryParams.UpdateString("with_configured_alert_ids","true")

loo_Http.SetRequestHeader("Accept","application/json")

loo_Resp = loo_Http.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v1/slo/:slo_id",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_QueryParams
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.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_QueryParams
    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": {
//     "configured_alert_ids": [
//       123,
//       456,
//       789
//     ],
//     "created_at": 17466638,
//     "creator": {
//       "email": "proident ex ullamco",
//       "handle": "laborum ad ex non",
//       "name": "officia dolor consectetur nisi"
//     },
//     "description": "est id",
//     "groups": [
//       "env:prod",
//       "role:mysql"
//     ],
//     "id": "esse cillum anim ",
//     "modified_at": -26273532,
//     "monitor_ids": [
//       -91642399,
//       93741
//     ],
//     "monitor_tags": [
//       "aliquip nulla Lorem ut",
//       "reprehenderit velit"
//     ],
//     "name": "Custom Metric SLO",
//     "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,
//     "thresholds": [
//       {
//         "target": 95,
//         "timeframe": "7d"
//       },
//       {
//         "target": 95,
//         "timeframe": "30d",
//         "warning": 97
//       }
//     ],
//     "timeframe": "30d",
//     "type": "metric",
//     "warning_threshold": 99.95
//   },
//   "errors": [
//     "consectetur velit",
//     "elit in"
//   ]
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

li_Created_at = loo_JResp.IntOf("data.created_at")
ls_V_Email = loo_JResp.StringOf("data.creator.email")
ls_Handle = loo_JResp.StringOf("data.creator.handle")
ls_Name = loo_JResp.StringOf("data.creator.name")
ls_Description = loo_JResp.StringOf("data.description")
ls_Id = loo_JResp.StringOf("data.id")
li_Modified_at = loo_JResp.IntOf("data.modified_at")
ls_DataName = loo_JResp.StringOf("data.name")
ls_Numerator = loo_JResp.StringOf("data.query.numerator")
ls_Denominator = loo_JResp.StringOf("data.query.denominator")
ls_Target_threshold = loo_JResp.StringOf("data.target_threshold")
ls_Timeframe = loo_JResp.StringOf("data.timeframe")
ls_V_Type = loo_JResp.StringOf("data.type")
ls_Warning_threshold = loo_JResp.StringOf("data.warning_threshold")
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.configured_alert_ids")
do while i < li_Count_i
    loo_JResp.I = i
    li_IntVal = loo_JResp.IntOf("data.configured_alert_ids[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.groups")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("data.groups[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.monitor_ids")
do while i < li_Count_i
    loo_JResp.I = i
    li_IntVal = loo_JResp.IntOf("data.monitor_ids[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.monitor_tags")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("data.monitor_tags[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.tags")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("data.tags[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.thresholds")
do while i < li_Count_i
    loo_JResp.I = i
    li_Target = loo_JResp.IntOf("data.thresholds[i].target")
    ls_Timeframe = loo_JResp.StringOf("data.thresholds[i].timeframe")
    li_Warning = loo_JResp.IntOf("data.thresholds[i].warning")
    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_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -G -d "with_configured_alert_ids=true"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/slo/:slo_id

Postman Collection Item JSON

{
  "name": "Get an SLO's details",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/slo/:slo_id?with_configured_alert_ids=true",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "slo",
        ":slo_id"
      ],
      "query": [
        {
          "key": "with_configured_alert_ids",
          "value": "true",
          "description": "Get the IDs of SLO monitors that reference this SLO."
        }
      ],
      "variable": [
        {
          "key": "slo_id",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Get a service level objective object."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/:slo_id?with_configured_alert_ids=true",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            ":slo_id"
          ],
          "query": [
            {
              "key": "with_configured_alert_ids",
              "value": "true",
              "description": "Get the IDs of SLO monitors that reference this SLO."
            }
          ],
          "variable": [
            {
              "key": "slo_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"configured_alert_ids\": [\n      123,\n      456,\n      789\n    ],\n    \"created_at\": 17466638,\n    \"creator\": {\n      \"email\": \"proident ex ullamco\",\n      \"handle\": \"laborum ad ex non\",\n      \"name\": \"officia dolor consectetur nisi\"\n    },\n    \"description\": \"est id\",\n    \"groups\": [\n      \"env:prod\",\n      \"role:mysql\"\n    ],\n    \"id\": \"esse cillum anim \",\n    \"modified_at\": -26273532,\n    \"monitor_ids\": [\n      -91642399,\n      93741\n    ],\n    \"monitor_tags\": [\n      \"aliquip nulla Lorem ut\",\n      \"reprehenderit velit\"\n    ],\n    \"name\": \"Custom Metric SLO\",\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    \"thresholds\": [\n      {\n        \"target\": 95,\n        \"timeframe\": \"7d\"\n      },\n      {\n        \"target\": 95,\n        \"timeframe\": \"30d\",\n        \"warning\": 97\n      }\n    ],\n    \"timeframe\": \"30d\",\n    \"type\": \"metric\",\n    \"warning_threshold\": 99.95\n  },\n  \"errors\": [\n    \"consectetur velit\",\n    \"elit in\"\n  ]\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/:slo_id?with_configured_alert_ids=true",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            ":slo_id"
          ],
          "query": [
            {
              "key": "with_configured_alert_ids",
              "value": "true",
              "description": "Get the IDs of SLO monitors that reference this SLO."
            }
          ],
          "variable": [
            {
              "key": "slo_id"
            }
          ]
        }
      },
      "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": "Not found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/:slo_id?with_configured_alert_ids=true",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            ":slo_id"
          ],
          "query": [
            {
              "key": "with_configured_alert_ids",
              "value": "true",
              "description": "Get the IDs of SLO monitors that reference this SLO."
            }
          ],
          "variable": [
            {
              "key": "slo_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/slo/:slo_id?with_configured_alert_ids=true",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo",
            ":slo_id"
          ],
          "query": [
            {
              "key": "with_configured_alert_ids",
              "value": "true",
              "description": "Get the IDs of SLO monitors that reference this SLO."
            }
          ],
          "variable": [
            {
              "key": "slo_id"
            }
          ]
        }
      },
      "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}"
    }
  ]
}