Chilkat Online Tools

Swift3 / Datadog API Collection / Update STS Service Account

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.

    // {
    //   "data": {
    //     "attributes": {
    //       "automute": "<boolean>",
    //       "client_email": "<string>",
    //       "host_filters": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "is_cspm_enabled": "<boolean>"
    //     },
    //     "id": "<string>",
    //     "type": "gcp_service_account"
    //   }
    // }

    let json = CkoJsonObject()!
    json.update("data.attributes.automute", value: "<boolean>")
    json.update("data.attributes.client_email", value: "<string>")
    json.update("data.attributes.host_filters[0]", value: "<string>")
    json.update("data.attributes.host_filters[1]", value: "<string>")
    json.update("data.attributes.is_cspm_enabled", value: "<boolean>")
    json.update("data.id", value: "<string>")
    json.update("data.type", value: "gcp_service_account")

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

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

    var resp: CkoHttpResponse? = http.pTextSb("PATCH", url: "https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts/:account_id", 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": {
    //     "attributes": {
    //       "automute": "<boolean>",
    //       "client_email": "<string>",
    //       "host_filters": [
    //         "<string>",
    //         "<string>"
    //       ],
    //       "is_cspm_enabled": "<boolean>"
    //     },
    //     "id": "<string>",
    //     "meta": {
    //       "accessible_projects": [
    //         "<string>",
    //         "<string>"
    //       ]
    //     },
    //     "type": "gcp_service_account"
    //   }
    // }

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

    var strVal: String?

    var Automute: String? = jResp.string(of: "data.attributes.automute")
    var Client_email: String? = jResp.string(of: "data.attributes.client_email")
    var Is_cspm_enabled: String? = jResp.string(of: "data.attributes.is_cspm_enabled")
    var Id: String? = jResp.string(of: "data.id")
    var v_Type: String? = jResp.string(of: "data.type")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "data.attributes.host_filters").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "data.attributes.host_filters[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "data.meta.accessible_projects").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "data.meta.accessible_projects[i]")
        i = i + 1
    }


}

Curl Command

curl -X PATCH
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "attributes": {
      "automute": "<boolean>",
      "client_email": "<string>",
      "host_filters": [
        "<string>",
        "<string>"
      ],
      "is_cspm_enabled": "<boolean>"
    },
    "id": "<string>",
    "type": "gcp_service_account"
  }
}'
https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts/:account_id

Postman Collection Item JSON

{
  "name": "Update STS Service Account",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"automute\": \"<boolean>\",\n      \"client_email\": \"<string>\",\n      \"host_filters\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"is_cspm_enabled\": \"<boolean>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"gcp_service_account\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/integration/gcp/accounts/:account_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "integration",
        "gcp",
        "accounts",
        ":account_id"
      ],
      "variable": [
        {
          "key": "account_id",
          "value": "<string>"
        }
      ]
    },
    "description": "Update an STS enabled service account."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"automute\": \"<boolean>\",\n      \"client_email\": \"<string>\",\n      \"host_filters\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"is_cspm_enabled\": \"<boolean>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"gcp_service_account\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/integration/gcp/accounts/:account_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts",
            ":account_id"
          ],
          "variable": [
            {
              "key": "account_id"
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"attributes\": {\n      \"automute\": \"<boolean>\",\n      \"client_email\": \"<string>\",\n      \"host_filters\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"is_cspm_enabled\": \"<boolean>\"\n    },\n    \"id\": \"<string>\",\n    \"meta\": {\n      \"accessible_projects\": [\n        \"<string>\",\n        \"<string>\"\n      ]\n    },\n    \"type\": \"gcp_service_account\"\n  }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"automute\": \"<boolean>\",\n      \"client_email\": \"<string>\",\n      \"host_filters\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"is_cspm_enabled\": \"<boolean>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"gcp_service_account\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/integration/gcp/accounts/:account_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts",
            ":account_id"
          ],
          "variable": [
            {
              "key": "account_id"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Not Authorized",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"automute\": \"<boolean>\",\n      \"client_email\": \"<string>\",\n      \"host_filters\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"is_cspm_enabled\": \"<boolean>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"gcp_service_account\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/integration/gcp/accounts/:account_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts",
            ":account_id"
          ],
          "variable": [
            {
              "key": "account_id"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Not Found",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"automute\": \"<boolean>\",\n      \"client_email\": \"<string>\",\n      \"host_filters\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"is_cspm_enabled\": \"<boolean>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"gcp_service_account\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/integration/gcp/accounts/:account_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts",
            ":account_id"
          ],
          "variable": [
            {
              "key": "account_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "PATCH",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"automute\": \"<boolean>\",\n      \"client_email\": \"<string>\",\n      \"host_filters\": [\n        \"<string>\",\n        \"<string>\"\n      ],\n      \"is_cspm_enabled\": \"<boolean>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"gcp_service_account\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/integration/gcp/accounts/:account_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "integration",
            "gcp",
            "accounts",
            ":account_id"
          ],
          "variable": [
            {
              "key": "account_id"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}