Chilkat Online Tools

SQL Server / Squadcast API V3 / Update Service

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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "name": "<string>",
    --   "description": "<string>",
    --   "escalation_policy_id": "<string>",
    --   "email_prefix": "<string>"
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'name', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'escalation_policy_id', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'email_prefix', '<string>'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', ''
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://api.squadcast.com/v3/services/:serviceID', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    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 @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

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

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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 @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        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": "New name",
    --     "slug": "payment-api-service",
    --     "email": "support@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"
    --     }
    --   }
    -- }

    -- 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)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'data.id'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'data.name'
    DECLARE @Slug nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Slug OUT, 'data.slug'
    DECLARE @v_Email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'data.email'
    DECLARE @Escalation_policy_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Escalation_policy_id OUT, 'data.escalation_policy_id'
    DECLARE @Organization_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Organization_id OUT, 'data.organization_id'
    DECLARE @Api_key nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Api_key OUT, 'data.api_key'
    DECLARE @Description nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'data.description'
    DECLARE @Depends nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Depends OUT, 'data.depends'
    DECLARE @Escalation_policyId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Escalation_policyId OUT, 'data.escalation_policy.id'
    DECLARE @Escalation_policyName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Escalation_policyName OUT, 'data.escalation_policy.name'
    DECLARE @Escalation_policyDescription nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Escalation_policyDescription OUT, 'data.escalation_policy.description'
    DECLARE @Escalation_policySlug nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Escalation_policySlug OUT, 'data.escalation_policy.slug'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -X PUT
	-H "Authorization: "
	-H "Content-Type: application/json"
	-d '{
    "name": "<string>",
    "description": "<string>",
    "escalation_policy_id": "<string>",
    "email_prefix": "<string>"
}'
https://api.squadcast.com/v3/services/:serviceID

Postman Collection Item JSON

{
  "name": "Update Service",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "PUT",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"name\": \"<string>\",\n    \"description\": \"<string>\",\n    \"escalation_policy_id\": \"<string>\",\n    \"email_prefix\": \"<string>\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/services/:serviceID",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services",
        ":serviceID"
      ],
      "variable": [
        {
          "key": "serviceID",
          "value": "<string>",
          "type": "string",
          "description": "(Required) service id"
        }
      ]
    },
    "description": "Update the basic service details and change escalation policy for the service.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `service-write` scope."
  },
  "response": [
    {
      "name": "Internal Server Error",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"New name\",\n    \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n    \"description\": \"New updated description\",\n    \"email_prefix\": \"support\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"New name\",\n    \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n    \"description\": \"New updated description\",\n    \"email_prefix\": \"support\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"New name\",\n    \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n    \"description\": \"New updated description\",\n    \"email_prefix\": \"support\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "Not Found",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"New name\",\n    \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n    \"description\": \"New updated description\",\n    \"email_prefix\": \"support\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"New name\",\n    \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n    \"description\": \"New updated description\",\n    \"email_prefix\": \"support\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "OK",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"New name\",\n    \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n    \"description\": \"New updated description\",\n    \"email_prefix\": \"support\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": {\n  \"id\": \"5e8edb24668e003cb0b18ba1\",\n  \"name\": \"New name\",\n  \"slug\": \"payment-api-service\",\n  \"email\": \"support@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}"
    },
    {
      "name": "Conflict",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"New name\",\n    \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n    \"description\": \"New updated description\",\n    \"email_prefix\": \"support\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Conflict",
      "code": 409,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    }
  ]
}