Chilkat Online Tools

TCL / Squadcast API V3 / Get Tagging Rules

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]

CkHttp_SetRequestHeader $http "Authorization" ""

set sbResponseBody [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http "https://api.squadcast.com/v3/services/:serviceID/tagging-rules" $sbResponseBody]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttp_lastHeader $http]
    puts "Failed."
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)

# {
#   "data": {
#     "id": "5d89e22915e52fa3f8620d37",
#     "created_at": "2019-09-24T09:30:17.463Z",
#     "updated_at": "2019-09-24T09:30:17.463Z",
#     "deleted_at": null,
#     "service_id": "5d81d9687000fb6b9def7e35",
#     "organization_id": "5d81d9187000fb6b9def7e32",
#     "rules": [
#       {
#         "expression": "re(current.labels.alertname, \"^CPUThrottlingHigh.*\") && re(past.labels.alertname, \"^CPUThrottlingHigh.*\")",
#         "tags": {
#           "foo": "bar",
#           "severity": "asa",
#           "tag2": "as"
#         }
#       }
#     ]
#   }
# }

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

set Id [CkJsonObject_stringOf $jResp "data.id"]
set Created_at [CkJsonObject_stringOf $jResp "data.created_at"]
set Updated_at [CkJsonObject_stringOf $jResp "data.updated_at"]
set Deleted_at [CkJsonObject_stringOf $jResp "data.deleted_at"]
set Service_id [CkJsonObject_stringOf $jResp "data.service_id"]
set Organization_id [CkJsonObject_stringOf $jResp "data.organization_id"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "data.rules"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set expression [CkJsonObject_stringOf $jResp "data.rules[i].expression"]
    set Foo [CkJsonObject_stringOf $jResp "data.rules[i].tags.foo"]
    set Severity [CkJsonObject_stringOf $jResp "data.rules[i].tags.severity"]
    set Tag2 [CkJsonObject_stringOf $jResp "data.rules[i].tags.tag2"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp

Curl Command

curl -X GET
	-H "Authorization: "
https://api.squadcast.com/v3/services/:serviceID/tagging-rules

Postman Collection Item JSON

{
  "name": "Get Tagging Rules",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/services/:serviceID/tagging-rules",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services",
        ":serviceID",
        "tagging-rules"
      ],
      "variable": [
        {
          "key": "serviceID",
          "value": "<string>",
          "type": "string",
          "description": "(Required) service id"
        }
      ]
    },
    "description": "This endpoint returns the default tagging rules for the service if not already created.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID/tagging-rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID",
            "tagging-rules"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": {\n  \"id\": \"5d89e22915e52fa3f8620d37\",\n  \"created_at\": \"2019-09-24T09:30:17.463Z\",\n  \"updated_at\": \"2019-09-24T09:30:17.463Z\",\n  \"deleted_at\": null,\n  \"service_id\": \"5d81d9687000fb6b9def7e35\",\n  \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n  \"rules\": [\n   {\n    \"expression\": \"re(current.labels.alertname, \\\"^CPUThrottlingHigh.*\\\") && re(past.labels.alertname, \\\"^CPUThrottlingHigh.*\\\")\",\n    \"tags\": {\n     \"foo\": \"bar\",\n     \"severity\": \"asa\",\n     \"tag2\": \"as\"\n    }\n   }\n  ]\n }\n}"
    }
  ]
}