Chilkat Online Tools

Swift3 / Squadcast API V3 / Update Service

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

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

    let json = CkoJsonObject()!
    json.update("name", value: "<string>")
    json.update("description", value: "<string>")
    json.update("escalation_policy_id", value: "<string>")
    json.update("email_prefix", value: "<string>")

    http.setRequestHeader("Authorization", value: "")
    http.setRequestHeader("Content-Type", value: "application/json")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)

    var resp: CkoHttpResponse? = http.pTextSb("PUT", url: "https://api.squadcast.com/v3/services/:serviceID", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp!.getBodySb(sbResponseBody)

    let jResp = CkoJsonObject()!
    jResp.loadSb(sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = resp!.statusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp!.header!)")
        print("Failed.")
        resp = nil
        return
    }

    resp = nil

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

    var Id: String? = jResp.string(of: "data.id")
    var Name: String? = jResp.string(of: "data.name")
    var Slug: String? = jResp.string(of: "data.slug")
    var v_Email: String? = jResp.string(of: "data.email")
    var Escalation_policy_id: String? = jResp.string(of: "data.escalation_policy_id")
    var Organization_id: String? = jResp.string(of: "data.organization_id")
    var Api_key: String? = jResp.string(of: "data.api_key")
    var Description: String? = jResp.string(of: "data.description")
    var Depends: String? = jResp.string(of: "data.depends")
    var Escalation_policyId: String? = jResp.string(of: "data.escalation_policy.id")
    var Escalation_policyName: String? = jResp.string(of: "data.escalation_policy.name")
    var Escalation_policyDescription: String? = jResp.string(of: "data.escalation_policy.description")
    var Escalation_policySlug: String? = jResp.string(of: "data.escalation_policy.slug")

}

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