Chilkat Online Tools

DataFlex / Datadog API Collection / Get all SLOs

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

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

    // 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 "ids" "id1, id2, id3" To iSuccess
    Get ComUpdateString Of hoQueryParams "query" "monitor" To iSuccess
    Get ComUpdateString Of hoQueryParams "tags_query" "env:prod" To iSuccess
    Get ComUpdateString Of hoQueryParams "metrics_query" "aws.elb.request_count" To iSuccess
    Get ComUpdateInt Of hoQueryParams "limit" -62147425 To iSuccess
    Get ComUpdateInt Of hoQueryParams "offset" -62147425 To iSuccess

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

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v1/slo" vQueryParams To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = 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."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    Get ComIntOf Of hoJResp "metadata.page.total_count" To iTotal_count
    Get ComIntOf Of hoJResp "metadata.page.total_filtered_count" To iTotal_filtered_count
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data[i].name" To sName
        Get ComStringOf Of hoJResp "data[i].type" To sV_type
        Get ComIntOf Of hoJResp "data[i].created_at" To iCreated_at
        Get ComStringOf Of hoJResp "data[i].creator.email" To sV_Email
        Get ComStringOf Of hoJResp "data[i].creator.handle" To sHandle
        Get ComStringOf Of hoJResp "data[i].creator.name" To sName
        Get ComStringOf Of hoJResp "data[i].description" To sDescription
        Get ComStringOf Of hoJResp "data[i].id" To sId
        Get ComIntOf Of hoJResp "data[i].modified_at" To iModified_at
        Get ComStringOf Of hoJResp "data[i].query.numerator" To sNumerator
        Get ComStringOf Of hoJResp "data[i].query.denominator" To sDenominator
        Get ComStringOf Of hoJResp "data[i].target_threshold" To sTarget_threshold
        Get ComStringOf Of hoJResp "data[i].timeframe" To sTimeframe
        Get ComStringOf Of hoJResp "data[i].warning_threshold" To sWarning_threshold
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "data[i].thresholds" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComIntOf Of hoJResp "data[i].thresholds[j].target" To iTarget
            Get ComStringOf Of hoJResp "data[i].thresholds[j].timeframe" To sTimeframe
            Get ComIntOf Of hoJResp "data[i].thresholds[j].warning" To iWarning
            Move (j + 1) To j
        Loop

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

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

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

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

        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 "ids=id1,%20id2,%20id3"
	-d "query=monitor"
	-d "tags_query=env%3Aprod"
	-d "metrics_query=aws.elb.request_count"
	-d "limit=-62147425"
	-d "offset=-62147425"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/slo

Postman Collection Item JSON

{
  "name": "Get all SLOs",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/slo?ids=id1, id2, id3&query=monitor&tags_query=env:prod&metrics_query=aws.elb.request_count&limit=-62147425&offset=-62147425",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "slo"
      ],
      "query": [
        {
          "key": "ids",
          "value": "id1, id2, id3",
          "description": "A comma separated list of the IDs of the service level objectives objects."
        },
        {
          "key": "query",
          "value": "monitor",
          "description": "The query string to filter results based on SLO names."
        },
        {
          "key": "tags_query",
          "value": "env:prod",
          "description": "The query string to filter results based on a single SLO tag."
        },
        {
          "key": "metrics_query",
          "value": "aws.elb.request_count",
          "description": "The query string to filter results based on SLO numerator and denominator."
        },
        {
          "key": "limit",
          "value": "-62147425",
          "description": "The number of SLOs to return in the response."
        },
        {
          "key": "offset",
          "value": "-62147425",
          "description": "The specific offset to use as the beginning of the returned response."
        }
      ]
    },
    "description": "Get a list of service level objective objects for your organization."
  },
  "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?ids=id1, id2, id3&query=monitor&tags_query=env:prod&metrics_query=aws.elb.request_count&limit=-62147425&offset=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo"
          ],
          "query": [
            {
              "key": "ids",
              "value": "id1, id2, id3",
              "description": "A comma separated list of the IDs of the service level objectives objects."
            },
            {
              "key": "query",
              "value": "monitor",
              "description": "The query string to filter results based on SLO names."
            },
            {
              "key": "tags_query",
              "value": "env:prod",
              "description": "The query string to filter results based on a single SLO tag."
            },
            {
              "key": "metrics_query",
              "value": "aws.elb.request_count",
              "description": "The query string to filter results based on SLO numerator and denominator."
            },
            {
              "key": "limit",
              "value": "-62147425",
              "description": "The number of SLOs to return in the response."
            },
            {
              "key": "offset",
              "value": "-62147425",
              "description": "The specific offset to use as the beginning of the returned response."
            }
          ]
        }
      },
      "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": "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?ids=id1, id2, id3&query=monitor&tags_query=env:prod&metrics_query=aws.elb.request_count&limit=-62147425&offset=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo"
          ],
          "query": [
            {
              "key": "ids",
              "value": "id1, id2, id3",
              "description": "A comma separated list of the IDs of the service level objectives objects."
            },
            {
              "key": "query",
              "value": "monitor",
              "description": "The query string to filter results based on SLO names."
            },
            {
              "key": "tags_query",
              "value": "env:prod",
              "description": "The query string to filter results based on a single SLO tag."
            },
            {
              "key": "metrics_query",
              "value": "aws.elb.request_count",
              "description": "The query string to filter results based on SLO numerator and denominator."
            },
            {
              "key": "limit",
              "value": "-62147425",
              "description": "The number of SLOs to return in the response."
            },
            {
              "key": "offset",
              "value": "-62147425",
              "description": "The specific offset to use as the beginning of the returned response."
            }
          ]
        }
      },
      "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": "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?ids=id1, id2, id3&query=monitor&tags_query=env:prod&metrics_query=aws.elb.request_count&limit=-62147425&offset=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo"
          ],
          "query": [
            {
              "key": "ids",
              "value": "id1, id2, id3",
              "description": "A comma separated list of the IDs of the service level objectives objects."
            },
            {
              "key": "query",
              "value": "monitor",
              "description": "The query string to filter results based on SLO names."
            },
            {
              "key": "tags_query",
              "value": "env:prod",
              "description": "The query string to filter results based on a single SLO tag."
            },
            {
              "key": "metrics_query",
              "value": "aws.elb.request_count",
              "description": "The query string to filter results based on SLO numerator and denominator."
            },
            {
              "key": "limit",
              "value": "-62147425",
              "description": "The number of SLOs to return in the response."
            },
            {
              "key": "offset",
              "value": "-62147425",
              "description": "The specific offset to use as the beginning of the returned response."
            }
          ]
        }
      },
      "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?ids=id1, id2, id3&query=monitor&tags_query=env:prod&metrics_query=aws.elb.request_count&limit=-62147425&offset=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo"
          ],
          "query": [
            {
              "key": "ids",
              "value": "id1, id2, id3",
              "description": "A comma separated list of the IDs of the service level objectives objects."
            },
            {
              "key": "query",
              "value": "monitor",
              "description": "The query string to filter results based on SLO names."
            },
            {
              "key": "tags_query",
              "value": "env:prod",
              "description": "The query string to filter results based on a single SLO tag."
            },
            {
              "key": "metrics_query",
              "value": "aws.elb.request_count",
              "description": "The query string to filter results based on SLO numerator and denominator."
            },
            {
              "key": "limit",
              "value": "-62147425",
              "description": "The number of SLOs to return in the response."
            },
            {
              "key": "offset",
              "value": "-62147425",
              "description": "The specific offset to use as the beginning of the returned response."
            }
          ]
        }
      },
      "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?ids=id1, id2, id3&query=monitor&tags_query=env:prod&metrics_query=aws.elb.request_count&limit=-62147425&offset=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "slo"
          ],
          "query": [
            {
              "key": "ids",
              "value": "id1, id2, id3",
              "description": "A comma separated list of the IDs of the service level objectives objects."
            },
            {
              "key": "query",
              "value": "monitor",
              "description": "The query string to filter results based on SLO names."
            },
            {
              "key": "tags_query",
              "value": "env:prod",
              "description": "The query string to filter results based on a single SLO tag."
            },
            {
              "key": "metrics_query",
              "value": "aws.elb.request_count",
              "description": "The query string to filter results based on SLO numerator and denominator."
            },
            {
              "key": "limit",
              "value": "-62147425",
              "description": "The number of SLOs to return in the response."
            },
            {
              "key": "offset",
              "value": "-62147425",
              "description": "The specific offset to use as the beginning of the returned response."
            }
          ]
        }
      },
      "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}"
    }
  ]
}