Chilkat Online Tools

SQL Server / Squadcast API V3 / Get All Services

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'name', ''

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', ''

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://api.squadcast.com/v3/services', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

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

    DECLARE @id nvarchar(4000)

    DECLARE @name nvarchar(4000)

    DECLARE @slug nvarchar(4000)

    DECLARE @email nvarchar(4000)

    DECLARE @escalation_policy_id nvarchar(4000)

    DECLARE @organization_id nvarchar(4000)

    DECLARE @api_key nvarchar(4000)

    DECLARE @description nvarchar(4000)

    DECLARE @depends nvarchar(4000)

    DECLARE @Id nvarchar(4000)

    DECLARE @Name nvarchar(4000)

    DECLARE @Description nvarchar(4000)

    DECLARE @Slug nvarchar(4000)

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'data[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'data[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @slug OUT, 'data[i].slug'
        EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'data[i].email'
        EXEC sp_OAMethod @jResp, 'StringOf', @escalation_policy_id OUT, 'data[i].escalation_policy_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @organization_id OUT, 'data[i].organization_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @api_key OUT, 'data[i].api_key'
        EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'data[i].description'
        EXEC sp_OAMethod @jResp, 'StringOf', @depends OUT, 'data[i].depends'
        EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'data[i].escalation_policy.id'
        EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'data[i].escalation_policy.name'
        EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'data[i].escalation_policy.description'
        EXEC sp_OAMethod @jResp, 'StringOf', @Slug OUT, 'data[i].escalation_policy.slug'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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}"
    }
  ]
}