Back to Collection Items
#include <CkHttp.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http;
bool success;
http.SetRequestHeader("Authorization","");
CkStringBuilder sbResponseBody;
success = http.QuickGetSb("https://api.squadcast.com/v3/services/:serviceID/tagging-rules",sbResponseBody);
if (success == false) {
std::cout << http.lastErrorText() << "\r\n";
return;
}
CkJsonObject jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
std::cout << "Response Body:" << "\r\n";
std::cout << jResp.emit() << "\r\n";
int respStatusCode = http.get_LastStatus();
std::cout << "Response Status Code = " << respStatusCode << "\r\n";
if (respStatusCode >= 400) {
std::cout << "Response Header:" << "\r\n";
std::cout << http.lastHeader() << "\r\n";
std::cout << "Failed." << "\r\n";
return;
}
// 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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
const char *expression = 0;
const char *Foo = 0;
const char *Severity = 0;
const char *Tag2 = 0;
const char *Id = jResp.stringOf("data.id");
const char *Created_at = jResp.stringOf("data.created_at");
const char *Updated_at = jResp.stringOf("data.updated_at");
const char *Deleted_at = jResp.stringOf("data.deleted_at");
const char *Service_id = jResp.stringOf("data.service_id");
const char *Organization_id = jResp.stringOf("data.organization_id");
int i = 0;
int count_i = jResp.SizeOfArray("data.rules");
while (i < count_i) {
jResp.put_I(i);
expression = jResp.stringOf("data.rules[i].expression");
Foo = jResp.stringOf("data.rules[i].tags.foo");
Severity = jResp.stringOf("data.rules[i].tags.severity");
Tag2 = jResp.stringOf("data.rules[i].tags.tag2");
i = i + 1;
}
}
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}"
}
]
}