Foxpro / Squadcast API V3 / Create or Update Suppression Rules
Back to Collection Items
LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')
* 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": [
* {
* "field": "message",
* "contains": true,
* "suppress": true,
* "expression": "hello"
* },
* {
* "field": "priority",
* "contains": true,
* "suppress": true,
* "expression": "p1"
* }
* ]
* }
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("rules[0].field","message")
loJson.UpdateBool("rules[0].contains",1)
loJson.UpdateBool("rules[0].suppress",1)
loJson.UpdateString("rules[0].expression","hello")
loJson.UpdateString("rules[1].field","priority")
loJson.UpdateBool("rules[1].contains",1)
loJson.UpdateBool("rules[1].suppress",1)
loJson.UpdateString("rules[1].expression","p1")
* Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"
loResp = loHttp.PostJson3("https://api.squadcast.com/v3/services/:serviceID/suppression-rules","application/json",loJson)
IF (loHttp.LastMethodSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
CANCEL
ENDIF
? STR(loResp.StatusCode)
? loResp.BodyStr
RELEASE loResp
RELEASE loHttp
RELEASE loJson
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"rules": [
{
"field": "message",
"contains": true,
"suppress": true,
"expression": "hello"
},
{
"field": "priority",
"contains": true,
"suppress": true,
"expression": "p1"
}
]
}'
https://api.squadcast.com/v3/services/:serviceID/suppression-rules
Postman Collection Item JSON
{
"name": "Create or Update Suppression Rules",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{sq_pb_auth_header}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"rules\": [\n {\n \"field\": \"message\",\n \"contains\": true,\n \"suppress\": true,\n \"expression\": \"hello\"\n },\n {\n \"field\": \"priority\",\n \"contains\": true,\n \"suppress\": true,\n \"expression\": \"p1\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/services/:serviceID/suppression-rules",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
":serviceID",
"suppression-rules"
],
"variable": [
{
"key": "serviceID",
"value": "5c7cf71ad517f500100b37d6",
"type": "string"
}
]
},
"description": "This endpoint creates or updates the suppression rules for the given service. If default rules not found it creates otherwise it updates the new rules. Requires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `write` scope."
},
"response": [
{
"name": "201 Created",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"rules\": [\n {\n \"description\": \"Suppress low latency alerts.\",\n \"expression\": \"re(payload.policy_name, \\\"low latency\\\")\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/services/:serviceID/suppression-rules",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
":serviceID",
"suppression-rules"
],
"variable": [
{
"key": "serviceID",
"value": "5c7cf71ad517f500100b37d6"
}
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": null,
"cookie": [
],
"body": "{\n \"data\": {\n \"id\": \"5fa50748a2e7e47f1436c0fc\",\n \"created_at\": \"2020-11-06T08:20:24.756Z\",\n \"updated_at\": \"2020-11-11T09:34:35.976Z\",\n \"service_id\": \"5f8ed89e39e4a959da360537\",\n \"organization_id\": \"5db92749f8d4da1473169533\",\n \"rules\": [\n {\n \"description\": \"Suppress low latency alerts.\",\n \"expression\": \"re(payload.policy_name, \\\"low latency\\\")\",\n \"is_basic\": false\n }\n ]\n }\n}"
},
{
"name": "401 Unauthorized",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"rules\": [\n {\n \"description\": \"Suppress low latency alerts.\",\n \"expression\": \"re(payload.policy_name, \\\"low latency\\\")\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/services/:serviceID/suppression-rules",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
":serviceID",
"suppression-rules"
],
"variable": [
{
"key": "serviceID",
"value": "5c7cf71ad517f500100b37d6"
}
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Fri, 18 Sep 2020 06:28:00 GMT"
},
{
"key": "Content-Length",
"value": "63"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 401,\n \"error_message\": \"invalid access token\"\n }\n}"
},
{
"name": "403 Forbidden",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"rules\": [\n {\n \"description\": \"Suppress low latency alerts.\",\n \"expression\": \"re(payload.policy_name, \\\"low latency\\\")\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/services/:serviceID/suppression-rules",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
":serviceID",
"suppression-rules"
],
"variable": [
{
"key": "serviceID",
"value": "5c7cf71ad517f500100b37d6"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Fri, 18 Sep 2020 06:28:00 GMT"
},
{
"key": "Content-Length",
"value": "63"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 403,\n \"error_message\": \"<string>\"\n }\n}"
},
{
"name": "500 Internal Server Error",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"rules\": [\n {\n \"description\": \"Suppress low latency alerts.\",\n \"expression\": \"re(payload.policy_name, \\\"low latency\\\")\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/services/:serviceID/suppression-rules",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
":serviceID",
"suppression-rules"
],
"variable": [
{
"key": "serviceID",
"value": "5c7cf71ad517f500100b37d6"
}
]
}
},
"status": "Internal Server Error",
"code": 500,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Fri, 18 Sep 2020 06:28:00 GMT"
},
{
"key": "Content-Length",
"value": "63"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 500,\n \"error_message\": \"<string>\"\n }\n}"
}
]
}