autoit / Squadcast API V3 / Create or Update Deduplication Rules
Back to Collection Items
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess
; Use this online tool to generate code from sample JSON: Generate Code to Create JSON
; The following JSON is sent in the request body.
; {
; "rules": [
; {
; "expression": "<string>",
; "time_window": "<string>"
; },
; {
; "expression": "<string>",
; "time_window": "<string>"
; }
; ]
; }
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("rules[0].expression","<string>")
$oJson.UpdateString("rules[0].time_window","<string>")
$oJson.UpdateString("rules[1].expression","<string>")
$oJson.UpdateString("rules[1].time_window","<string>")
$oHttp.SetRequestHeader "Authorization",""
$oHttp.SetRequestHeader "Content-Type","application/json"
Local $oResp = $oHttp.PostJson3("https://api.squadcast.com/v3/services/:serviceID/deduplication-rules","application/json",$oJson)
If ($oHttp.LastMethodSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "data": {
; "id": "5e905b9ffe3e978d6ac34cc9",
; "created_at": "2020-04-10T11:42:23.646Z",
; "updated_at": "2020-04-10T11:42:23.646Z",
; "deleted_at": null,
; "service_id": "5e8edb24668e003cb0b18ba1",
; "organization_id": "5d81d9187000fb6b9def7e32",
; "rules": [
; {
; "expression": "re(current.labels.alertname, \"^CPUThrottlingHigh.*\") && re(past.labels.alertname, \"^CPUThrottlingHigh.*\")",
; "time_window": 300
; },
; {
; "expression": "re(current.labels.alertname, \"^DeploymentReplicasNotUpdated.*\") && re(past.labels.alertname, \"^DeploymentReplicasNotUpdated.*\")",
; "time_window": 300
; }
; ]
; }
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Local $sExpression
Local $iTime_window
Local $sId = $oJResp.StringOf("data.id")
Local $sCreated_at = $oJResp.StringOf("data.created_at")
Local $sUpdated_at = $oJResp.StringOf("data.updated_at")
Local $sDeleted_at = $oJResp.StringOf("data.deleted_at")
Local $sService_id = $oJResp.StringOf("data.service_id")
Local $sOrganization_id = $oJResp.StringOf("data.organization_id")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("data.rules")
While $i < $iCount_i
$oJResp.I = $i
$sExpression = $oJResp.StringOf("data.rules[i].expression")
$iTime_window = $oJResp.IntOf("data.rules[i].time_window")
$i = $i + 1
Wend
Curl Command
curl -X POST
-H "Authorization: "
-H "Content-Type: application/json"
-d '{
"rules": [
{
"expression": "<string>",
"time_window": "<string>"
},
{
"expression": "<string>",
"time_window": "<string>"
}
]
}'
https://api.squadcast.com/v3/services/:serviceID/deduplication-rules
Postman Collection Item JSON
{
"name": "Create or Update Deduplication Rules",
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Authorization",
"value": ""
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"rules\": [\n {\n \"expression\": \"<string>\",\n \"time_window\": \"<string>\"\n },\n {\n \"expression\": \"<string>\",\n \"time_window\": \"<string>\"\n }\n ]\n}"
},
"url": {
"raw": "{{baseUrl}}/services/:serviceID/deduplication-rules",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
":serviceID",
"deduplication-rules"
],
"variable": [
{
"key": "serviceID",
"value": "<string>",
"type": "string",
"description": "(Required) service id"
}
]
},
"description": "This endpoint creates or updates the deduplication rules for the given service.\nIf default rules not found it creates otherwise it updates the new rules.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `write` scope.\n"
},
"response": [
{
"name": "Created",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"rules\": [\n {\n \"expression\": \"re(current.labels.alertname, \\\"^CPUThrottlingHigh.*\\\") && re(past.labels.alertname, \\\"^CPUThrottlingHigh.*\\\")\",\n \"time_window\": 300\n },\n {\n \"expression\": \"re(current.labels.alertname, \\\"^DeploymentReplicasNotUpdated.*\\\") && re(past.labels.alertname, \\\"^DeploymentReplicasNotUpdated.*\\\")\",\n \"time_window\": 300\n }\n ]\n}"
},
"url": {
"raw": "{{baseUrl}}/services/:serviceID/deduplication-rules",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
":serviceID",
"deduplication-rules"
],
"variable": [
{
"key": "serviceID"
}
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"id\": \"5e905b9ffe3e978d6ac34cc9\",\n \"created_at\": \"2020-04-10T11:42:23.646Z\",\n \"updated_at\": \"2020-04-10T11:42:23.646Z\",\n \"deleted_at\": null,\n \"service_id\": \"5e8edb24668e003cb0b18ba1\",\n \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n \"rules\": [\n {\n \"expression\": \"re(current.labels.alertname, \\\"^CPUThrottlingHigh.*\\\") && re(past.labels.alertname, \\\"^CPUThrottlingHigh.*\\\")\",\n \"time_window\": 300\n },\n {\n \"expression\": \"re(current.labels.alertname, \\\"^DeploymentReplicasNotUpdated.*\\\") && re(past.labels.alertname, \\\"^DeploymentReplicasNotUpdated.*\\\")\",\n \"time_window\": 300\n }\n ]\n }\n}"
}
]
}