Chilkat Online Tools

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

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    Integer iIntVal
    String sStrVal
    Integer iTarget
    String sTimeframe
    Integer iWarning
    Integer iCreated_at
    String sV_Email
    String sHandle
    String sName
    String sDescription
    String sId
    Integer iModified_at
    String sDataName
    String sNumerator
    String sDenominator
    String sTarget_threshold
    String sTimeframe
    String sV_Type
    String sWarning_threshold
    Integer i
    Integer iCount_i
    String sTemp1

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateString Of hoQueryParams "with_configured_alert_ids" "true" To iSuccess

    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoQueryParams to vQueryParams
    Get pvComObject of hoResp to vResp
    Get ComHttpParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v1/slo/:slo_id" vQueryParams vResp To iSuccess
    If (iSuccess = 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."
        Procedure_Return
    End

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

    Get ComIntOf Of hoJResp "data.created_at" To iCreated_at
    Get ComStringOf Of hoJResp "data.creator.email" To sV_Email
    Get ComStringOf Of hoJResp "data.creator.handle" To sHandle
    Get ComStringOf Of hoJResp "data.creator.name" To sName
    Get ComStringOf Of hoJResp "data.description" To sDescription
    Get ComStringOf Of hoJResp "data.id" To sId
    Get ComIntOf Of hoJResp "data.modified_at" To iModified_at
    Get ComStringOf Of hoJResp "data.name" To sDataName
    Get ComStringOf Of hoJResp "data.query.numerator" To sNumerator
    Get ComStringOf Of hoJResp "data.query.denominator" To sDenominator
    Get ComStringOf Of hoJResp "data.target_threshold" To sTarget_threshold
    Get ComStringOf Of hoJResp "data.timeframe" To sTimeframe
    Get ComStringOf Of hoJResp "data.type" To sV_Type
    Get ComStringOf Of hoJResp "data.warning_threshold" To sWarning_threshold
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.configured_alert_ids" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "data.configured_alert_ids[i]" To iIntVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.groups" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data.groups[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.monitor_ids" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "data.monitor_ids[i]" To iIntVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.monitor_tags" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data.monitor_tags[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.tags" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data.tags[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data.thresholds" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "data.thresholds[i].target" To iTarget
        Get ComStringOf Of hoJResp "data.thresholds[i].timeframe" To sTimeframe
        Get ComIntOf Of hoJResp "data.thresholds[i].warning" To iWarning
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "errors" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "errors[i]" To sStrVal
        Move (i + 1) To i
    Loop



End_Procedure

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}"
    }
  ]
}