Chilkat Online Tools

unicodeC / Squadcast API V3 / Get Incident by ID

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *id;
    const wchar_t *v_type;
    const wchar_t *timeOfAssignment;
    const wchar_t *action;
    const wchar_t *assignedTo;
    const wchar_t *time;
    const wchar_t *reason;
    const wchar_t *additionalInfo;
    const wchar_t *Id;
    const wchar_t *Service_id;
    const wchar_t *Alert_source_id;
    const wchar_t *Organization_id;
    int IncidentNumber;
    const wchar_t *Message;
    const wchar_t *Description;
    const wchar_t *Status;
    const wchar_t *TimeOfCreation;
    const wchar_t *Tags;
    int Time;
    const wchar_t *UserId;
    const wchar_t *EscalationPolicyId;
    const wchar_t *SquadId;
    int TtrTime;
    const wchar_t *TtrUserId;
    const wchar_t *TtrEscalationPolicyId;
    const wchar_t *TtrSquadId;
    const wchar_t *Pinned_messages;
    BOOL Deleted;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api.squadcast.com/v3/incidents/:incidentID",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

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

    // {
    //   "data": {
    //     "id": "5d81d9bc60e42f6b99ca4307",
    //     "service_id": "5d81d9687000fb6b9def7e35",
    //     "alert_source_id": "5a9002f082bb573a2bc779eb",
    //     "organization_id": "5d81d9187000fb6b9def7e32",
    //     "incidentNumber": 3,
    //     "message": "[warning] CPUThrottlingHigh",
    //     "assignedTo": [
    //       {
    //         "id": "5d81d9407000fb6b9def7e33",
    //         "type": "escalationpolicy",
    //         "timeOfAssignment": "2019-09-18T07:16:12.218Z"
    //       },
    //       {
    //         "id": "5d81d9187000fb6b9def7e31",
    //         "type": "user",
    //         "timeOfAssignment": "2019-09-20T11:06:37.838Z"
    //       }
    //     ],
    //     "description": "Message: 64% throttling of CPU in namespace kube-system for container autoscaler in pod calico-typha-horizontal-autoscaler-5ff7f558cc-qlm2t.\nRunbook url: https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/runbook.md#alert-name-cputhrottlinghigh\nLabels\n  Alertname: CPUThrottlingHigh\n  Container name: autoscaler\n  Namespace: kube-system\n  Pod name: calico-typha-horizontal-autoscaler-5ff7f558cc-qlm2t\n  Prometheus: monitoring/monitoring-prometheus-oper-prometheus\n  Severity: warning\n  Generator URL: http://monitoring-prometheus-oper-prometheus.monitoring:9090/graph?g0.expr=100+%2A+sum+by%28container_name%2C+pod_name%2C+namespace%29+%28increase%28container_cpu_cfs_throttled_periods_total%7Bcontainer_name%21%3D%22%22%7D%5B5m%5D%29%29+%2F+sum+by%28container_name%2C+pod_name%2C+namespace%29+%28increase%28container_cpu_cfs_periods_total%5B5m%5D%29%29+%3E+25&g0.tab=1",
    //     "status": "resolved",
    //     "timeOfCreation": "2019-09-18T07:16:12.218Z",
    //     "tags": null,
    //     "logs": [
    //       {
    //         "action": "triggered",
    //         "assignedTo": "escalationpolicy",
    //         "id": "5d81d9407000fb6b9def7e33",
    //         "time": "2019-09-18T07:16:12.215Z",
    //         "reason": "",
    //         "additionalInfo": null
    //       },
    //       {
    //         "action": "acknowledged",
    //         "assignedTo": "user",
    //         "id": "5d81d9187000fb6b9def7e31",
    //         "time": "2019-09-20T11:06:37.838Z",
    //         "reason": "",
    //         "additionalInfo": null
    //       },
    //       {
    //         "action": "resolved",
    //         "assignedTo": "user",
    //         "id": "5d81d9187000fb6b9def7e31",
    //         "time": "2019-09-20T11:06:40.724Z",
    //         "reason": "",
    //         "additionalInfo": null
    //       }
    //     ],
    //     "analytics": {
    //       "tta": {
    //         "time": 186625623,
    //         "userId": "5d81d9187000fb6b9def7e31",
    //         "escalationPolicyId": "5d81d9407000fb6b9def7e33",
    //         "squadId": "000000000000000000000000"
    //       },
    //       "ttr": {
    //         "time": 186628509,
    //         "userId": "5d81d9187000fb6b9def7e31",
    //         "escalationPolicyId": "5d81d9407000fb6b9def7e33",
    //         "squadId": "000000000000000000000000"
    //       }
    //     },
    //     "pinned_messages": null,
    //     "deleted": false,
    //     "relevantUsers": [
    //     ],
    //     "relevantEscalationPolicies": [
    //     ],
    //     "relevantSquads": [
    //     ],
    //     "relevantSchedules": [
    //     ],
    //     "relevantPeopleLogs": [
    //     ],
    //     "responseNotes": [
    //     ]
    //   }
    // }

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

    Id = CkJsonObjectW_stringOf(jResp,L"data.id");
    Service_id = CkJsonObjectW_stringOf(jResp,L"data.service_id");
    Alert_source_id = CkJsonObjectW_stringOf(jResp,L"data.alert_source_id");
    Organization_id = CkJsonObjectW_stringOf(jResp,L"data.organization_id");
    IncidentNumber = CkJsonObjectW_IntOf(jResp,L"data.incidentNumber");
    Message = CkJsonObjectW_stringOf(jResp,L"data.message");
    Description = CkJsonObjectW_stringOf(jResp,L"data.description");
    Status = CkJsonObjectW_stringOf(jResp,L"data.status");
    TimeOfCreation = CkJsonObjectW_stringOf(jResp,L"data.timeOfCreation");
    Tags = CkJsonObjectW_stringOf(jResp,L"data.tags");
    Time = CkJsonObjectW_IntOf(jResp,L"data.analytics.tta.time");
    UserId = CkJsonObjectW_stringOf(jResp,L"data.analytics.tta.userId");
    EscalationPolicyId = CkJsonObjectW_stringOf(jResp,L"data.analytics.tta.escalationPolicyId");
    SquadId = CkJsonObjectW_stringOf(jResp,L"data.analytics.tta.squadId");
    TtrTime = CkJsonObjectW_IntOf(jResp,L"data.analytics.ttr.time");
    TtrUserId = CkJsonObjectW_stringOf(jResp,L"data.analytics.ttr.userId");
    TtrEscalationPolicyId = CkJsonObjectW_stringOf(jResp,L"data.analytics.ttr.escalationPolicyId");
    TtrSquadId = CkJsonObjectW_stringOf(jResp,L"data.analytics.ttr.squadId");
    Pinned_messages = CkJsonObjectW_stringOf(jResp,L"data.pinned_messages");
    Deleted = CkJsonObjectW_BoolOf(jResp,L"data.deleted");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.assignedTo");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        id = CkJsonObjectW_stringOf(jResp,L"data.assignedTo[i].id");
        v_type = CkJsonObjectW_stringOf(jResp,L"data.assignedTo[i].type");
        timeOfAssignment = CkJsonObjectW_stringOf(jResp,L"data.assignedTo[i].timeOfAssignment");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.logs");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        action = CkJsonObjectW_stringOf(jResp,L"data.logs[i].action");
        assignedTo = CkJsonObjectW_stringOf(jResp,L"data.logs[i].assignedTo");
        id = CkJsonObjectW_stringOf(jResp,L"data.logs[i].id");
        time = CkJsonObjectW_stringOf(jResp,L"data.logs[i].time");
        reason = CkJsonObjectW_stringOf(jResp,L"data.logs[i].reason");
        additionalInfo = CkJsonObjectW_stringOf(jResp,L"data.logs[i].additionalInfo");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.relevantUsers");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.relevantEscalationPolicies");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.relevantSquads");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.relevantSchedules");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.relevantPeopleLogs");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.responseNotes");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://api.squadcast.com/v3/incidents/:incidentID

Postman Collection Item JSON

{
  "name": "Get Incident by ID",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{sq_pb_auth_header}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/incidents/:incidentID",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "incidents",
        ":incidentID"
      ],
      "variable": [
        {
          "key": "incidentID",
          "value": "5d81d9bc60e42f6b99ca4307"
        }
      ]
    },
    "description": "- This endpoint is used to get the incident details by ID.\n- Requires `access_token` as a `Bearer {{token}}` in the `Authorization` header."
  },
  "response": [
    {
      "name": "400 Bad Request",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/incidents/:incidentID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "incidents",
            ":incidentID"
          ],
          "variable": [
            {
              "key": "incidentID",
              "value": "5d81d9bc60e42f6b99ca4307"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx/1.17.7"
        },
        {
          "key": "Date",
          "value": "Tue, 07 Jul 2020 21:06:25 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15724800; includeSubDomains"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 400,\n        \"error_message\": \"invalid incident id\"\n    }\n}"
    },
    {
      "name": "404 Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/incidents/:incidentID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "incidents",
            ":incidentID"
          ],
          "variable": [
            {
              "key": "incidentID",
              "value": "5d81d9bc60e42f6b99ca4307"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx/1.17.7"
        },
        {
          "key": "Date",
          "value": "Tue, 07 Jul 2020 21:06:25 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15724800; includeSubDomains"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 404,\n        \"error_message\": \"incident not found\"\n    }\n}"
    },
    {
      "name": "401 Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/incidents/:incidentID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "incidents",
            ":incidentID"
          ],
          "variable": [
            {
              "key": "incidentID",
              "value": "5d81d9bc60e42f6b99ca4307"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx/1.17.7"
        },
        {
          "key": "Date",
          "value": "Tue, 07 Jul 2020 21:06:25 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15724800; includeSubDomains"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 401,\n        \"error_message\": \"<string>\"\n    }\n}"
    },
    {
      "name": "403 - Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/incidents/:incidentID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "incidents",
            ":incidentID"
          ],
          "variable": [
            {
              "key": "incidentID",
              "value": "5d81d9bc60e42f6b99ca4307"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx/1.17.7"
        },
        {
          "key": "Date",
          "value": "Tue, 07 Jul 2020 21:06:25 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15724800; includeSubDomains"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 403,\n        \"error_message\": \"<string>\"\n    }\n}"
    },
    {
      "name": "200 OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/incidents/:incidentID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "incidents",
            ":incidentID"
          ],
          "variable": [
            {
              "key": "incidentID",
              "value": "5d81d9bc60e42f6b99ca4307"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx/1.17.7"
        },
        {
          "key": "Date",
          "value": "Tue, 07 Jul 2020 21:06:25 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15724800; includeSubDomains"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": {\n        \"id\": \"5d81d9bc60e42f6b99ca4307\",\n        \"service_id\": \"5d81d9687000fb6b9def7e35\",\n        \"alert_source_id\": \"5a9002f082bb573a2bc779eb\",\n        \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n        \"incidentNumber\": 3,\n        \"message\": \"[warning] CPUThrottlingHigh\",\n        \"assignedTo\": [\n            {\n                \"id\": \"5d81d9407000fb6b9def7e33\",\n                \"type\": \"escalationpolicy\",\n                \"timeOfAssignment\": \"2019-09-18T07:16:12.218Z\"\n            },\n            {\n                \"id\": \"5d81d9187000fb6b9def7e31\",\n                \"type\": \"user\",\n                \"timeOfAssignment\": \"2019-09-20T11:06:37.838Z\"\n            }\n        ],\n        \"description\": \"Message: 64% throttling of CPU in namespace kube-system for container autoscaler in pod calico-typha-horizontal-autoscaler-5ff7f558cc-qlm2t.\\nRunbook url: https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/runbook.md#alert-name-cputhrottlinghigh\\nLabels\\n  Alertname: CPUThrottlingHigh\\n  Container name: autoscaler\\n  Namespace: kube-system\\n  Pod name: calico-typha-horizontal-autoscaler-5ff7f558cc-qlm2t\\n  Prometheus: monitoring/monitoring-prometheus-oper-prometheus\\n  Severity: warning\\n  Generator URL: http://monitoring-prometheus-oper-prometheus.monitoring:9090/graph?g0.expr=100+%2A+sum+by%28container_name%2C+pod_name%2C+namespace%29+%28increase%28container_cpu_cfs_throttled_periods_total%7Bcontainer_name%21%3D%22%22%7D%5B5m%5D%29%29+%2F+sum+by%28container_name%2C+pod_name%2C+namespace%29+%28increase%28container_cpu_cfs_periods_total%5B5m%5D%29%29+%3E+25&g0.tab=1\",\n        \"status\": \"resolved\",\n        \"timeOfCreation\": \"2019-09-18T07:16:12.218Z\",\n        \"tags\": null,\n        \"logs\": [\n            {\n                \"action\": \"triggered\",\n                \"assignedTo\": \"escalationpolicy\",\n                \"id\": \"5d81d9407000fb6b9def7e33\",\n                \"time\": \"2019-09-18T07:16:12.215Z\",\n                \"reason\": \"\",\n                \"additionalInfo\": null\n            },\n            {\n                \"action\": \"acknowledged\",\n                \"assignedTo\": \"user\",\n                \"id\": \"5d81d9187000fb6b9def7e31\",\n                \"time\": \"2019-09-20T11:06:37.838Z\",\n                \"reason\": \"\",\n                \"additionalInfo\": null\n            },\n            {\n                \"action\": \"resolved\",\n                \"assignedTo\": \"user\",\n                \"id\": \"5d81d9187000fb6b9def7e31\",\n                \"time\": \"2019-09-20T11:06:40.724Z\",\n                \"reason\": \"\",\n                \"additionalInfo\": null\n            }\n        ],\n        \"analytics\": {\n            \"tta\": {\n                \"time\": 186625623,\n                \"userId\": \"5d81d9187000fb6b9def7e31\",\n                \"escalationPolicyId\": \"5d81d9407000fb6b9def7e33\",\n                \"squadId\": \"000000000000000000000000\"\n            },\n            \"ttr\": {\n                \"time\": 186628509,\n                \"userId\": \"5d81d9187000fb6b9def7e31\",\n                \"escalationPolicyId\": \"5d81d9407000fb6b9def7e33\",\n                \"squadId\": \"000000000000000000000000\"\n            }\n        },\n        \"pinned_messages\": null,\n        \"deleted\": false,\n        \"relevantUsers\": [],\n        \"relevantEscalationPolicies\": [],\n        \"relevantSquads\": [],\n        \"relevantSchedules\": [],\n        \"relevantPeopleLogs\": [],\n        \"responseNotes\": []\n    }\n}"
    }
  ]
}