Chilkat Online Tools

unicodeCpp / Datadog API Collection / Update STS Service Account

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>

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

    CkHttpW http;
    bool success;

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

    CkJsonObjectW json;
    json.UpdateString(L"data.attributes.automute",L"<boolean>");
    json.UpdateString(L"data.attributes.client_email",L"<string>");
    json.UpdateString(L"data.attributes.host_filters[0]",L"<string>");
    json.UpdateString(L"data.attributes.host_filters[1]",L"<string>");
    json.UpdateString(L"data.attributes.is_cspm_enabled",L"<boolean>");
    json.UpdateString(L"data.id",L"<string>");
    json.UpdateString(L"data.type",L"gcp_service_account");

    http.SetRequestHeader(L"Content-Type",L"application/json");
    http.SetRequestHeader(L"Accept",L"application/json");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponseW *resp = http.PTextSb(L"PATCH",L"https://api.app.ddog-gov.com/api/v2/integration/gcp/accounts/:account_id",sbRequestBody,L"utf-8",L"application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = resp->get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp->header());
        wprintf(L"Failed.\n");
        delete resp;
        return;
    }

    delete resp;

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const wchar_t *strVal = 0;

    const wchar_t *Automute = jResp.stringOf(L"data.attributes.automute");
    const wchar_t *Client_email = jResp.stringOf(L"data.attributes.client_email");
    const wchar_t *Is_cspm_enabled = jResp.stringOf(L"data.attributes.is_cspm_enabled");
    const wchar_t *Id = jResp.stringOf(L"data.id");
    const wchar_t *v_Type = jResp.stringOf(L"data.type");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"data.attributes.host_filters");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"data.attributes.host_filters[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"data.meta.accessible_projects");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"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}"
    }
  ]
}