Chilkat Online Tools

Foxpro / Squadcast API V3 / Get All Services

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loQueryParams
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcId
LOCAL lcName
LOCAL lcSlug
LOCAL lcEmail
LOCAL lcEscalation_policy_id
LOCAL lcOrganization_id
LOCAL lcApi_key
LOCAL lcDescription
LOCAL lcDepends
LOCAL lcId
LOCAL lcName
LOCAL lcDescription
LOCAL lcSlug
LOCAL i
LOCAL lnCount_i

* 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')

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loQueryParams = CreateObject('Chilkat.JsonObject')
loQueryParams.UpdateString("name","")

loHttp.SetRequestHeader("Authorization","")

loResp = loHttp.QuickRequestParams("GET","https://api.squadcast.com/v3/services",loQueryParams)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loQueryParams
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loQueryParams
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

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

* {
*   "data": [
*     {
*       "id": "5e8edb24668e003cb0b18ba1",
*       "name": "Payment API Service",
*       "slug": "payment-api-service",
*       "email": "unique_string@gopherhut.incidents.squadcast.com",
*       "escalation_policy_id": "5d81d9407000fb6b9def7e33",
*       "organization_id": "5d81d9187000fb6b9def7e32",
*       "api_key": "2f81ac8b2362990dd220f8bb4f7cd30ccc3dac43",
*       "description": "Payment API Service monitor",
*       "depends": null,
*       "escalation_policy": {
*         "id": "5d81d9407000fb6b9def7e33",
*         "name": "Example Escalation Policy",
*         "description": "On-Boarding Example",
*         "slug": "example-escalation-policy"
*       }
*     },
*     {
*       "id": "5e8edb24668e003cb0b18ba2",
*       "name": "Notification Service",
*       "slug": "notification-api-service",
*       "email": "unique_string@gopherhut.incidents.squadcast.com",
*       "escalation_policy_id": "5d81d9407000fb6b9def7e33",
*       "organization_id": "5d81d9187000fb6b9def7e32",
*       "api_key": "2f81ac8b2362990dd220f8bb4f7cd30ccc3d43",
*       "description": "Notification API Service monitor",
*       "depends": null,
*       "escalation_policy": {
*         "id": "5d81d9407000fb6b9def7e33",
*         "name": "Example Escalation Policy",
*         "description": "On-Boarding Example",
*         "slug": "example-escalation-policy"
*       }
*     }
*   ]
* }

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

i = 0
lnCount_i = loJResp.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcId = loJResp.StringOf("data[i].id")
    lcName = loJResp.StringOf("data[i].name")
    lcSlug = loJResp.StringOf("data[i].slug")
    lcEmail = loJResp.StringOf("data[i].email")
    lcEscalation_policy_id = loJResp.StringOf("data[i].escalation_policy_id")
    lcOrganization_id = loJResp.StringOf("data[i].organization_id")
    lcApi_key = loJResp.StringOf("data[i].api_key")
    lcDescription = loJResp.StringOf("data[i].description")
    lcDepends = loJResp.StringOf("data[i].depends")
    lcId = loJResp.StringOf("data[i].escalation_policy.id")
    lcName = loJResp.StringOf("data[i].escalation_policy.name")
    lcDescription = loJResp.StringOf("data[i].escalation_policy.description")
    lcSlug = loJResp.StringOf("data[i].escalation_policy.slug")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loQueryParams
RELEASE loSbResponseBody
RELEASE loJResp

Curl Command

curl -G -d "name="
	-H "Authorization: "
https://api.squadcast.com/v3/services

Postman Collection Item JSON

{
  "name": "Get All Services",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/services?name=",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services"
      ],
      "query": [
        {
          "key": "name",
          "value": ""
        }
      ]
    },
    "description": "Returns all the active services for the organization.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope.\n\nQuery Param:\n\n`name`: get a service by name"
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": [\n  {\n   \"id\": \"5e8edb24668e003cb0b18ba1\",\n   \"name\": \"Payment API Service\",\n   \"slug\": \"payment-api-service\",\n   \"email\": \"unique_string@gopherhut.incidents.squadcast.com\",\n   \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n   \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n   \"api_key\": \"2f81ac8b2362990dd220f8bb4f7cd30ccc3dac43\",\n   \"description\": \"Payment API Service monitor\",\n   \"depends\": null,\n   \"escalation_policy\": {\n    \"id\": \"5d81d9407000fb6b9def7e33\",\n    \"name\": \"Example Escalation Policy\",\n    \"description\": \"On-Boarding Example\",\n    \"slug\": \"example-escalation-policy\"\n   }\n  },\n  {\n   \"id\": \"5e8edb24668e003cb0b18ba2\",\n   \"name\": \"Notification Service\",\n   \"slug\": \"notification-api-service\",\n   \"email\": \"unique_string@gopherhut.incidents.squadcast.com\",\n   \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n   \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n   \"api_key\": \"2f81ac8b2362990dd220f8bb4f7cd30ccc3d43\",\n   \"description\": \"Notification API Service monitor\",\n   \"depends\": null,\n   \"escalation_policy\": {\n    \"id\": \"5d81d9407000fb6b9def7e33\",\n    \"name\": \"Example Escalation Policy\",\n    \"description\": \"On-Boarding Example\",\n    \"slug\": \"example-escalation-policy\"\n   }\n  }\n ]\n}"
    }
  ]
}