Chilkat Online Tools

delphiDll / Datadog API Collection / Update a Cloud Workload Security Agent rule

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
AgentConstraint: PWideChar;
Category: PWideChar;
CreationAuthorUuId: PWideChar;
CreationDate: PWideChar;
Handle: PWideChar;
Name: PWideChar;
DefaultRule: PWideChar;
Description: PWideChar;
Enabled: PWideChar;
Expression: PWideChar;
AttributesName: PWideChar;
UpdateAuthorUuId: PWideChar;
UpdateDate: PWideChar;
UpdatedAt: PWideChar;
UpdaterHandle: PWideChar;
UpdaterName: PWideChar;
Version: PWideChar;
Id: PWideChar;
v_Type: PWideChar;

begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

http := CkHttp_Create();

// 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": {
//       "description": "<string>",
//       "enabled": "<boolean>",
//       "expression": "<string>"
//     },
//     "type": "agent_rule"
//   }
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'data.attributes.description','<string>');
CkJsonObject_UpdateString(json,'data.attributes.enabled','<boolean>');
CkJsonObject_UpdateString(json,'data.attributes.expression','<string>');
CkJsonObject_UpdateString(json,'data.type','agent_rule');

CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'Accept','application/json');

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);

resp := CkHttp_PTextSb(http,'PATCH','https://api.app.ddog-gov.com/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id',sbRequestBody,'utf-8','application/json',False,False);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "data": {
//     "attributes": {
//       "agentConstraint": "<string>",
//       "category": "<string>",
//       "creationAuthorUuId": "<string>",
//       "creationDate": "<long>",
//       "creator": {
//         "handle": "<string>",
//         "name": "<string>"
//       },
//       "defaultRule": "<boolean>",
//       "description": "<string>",
//       "enabled": "<boolean>",
//       "expression": "<string>",
//       "name": "<string>",
//       "updateAuthorUuId": "<string>",
//       "updateDate": "<long>",
//       "updatedAt": "<long>",
//       "updater": {
//         "handle": "<string>",
//         "name": "<string>"
//       },
//       "version": "<long>"
//     },
//     "id": "<string>",
//     "type": "agent_rule"
//   }
// }

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

AgentConstraint := CkJsonObject__stringOf(jResp,'data.attributes.agentConstraint');
Category := CkJsonObject__stringOf(jResp,'data.attributes.category');
CreationAuthorUuId := CkJsonObject__stringOf(jResp,'data.attributes.creationAuthorUuId');
CreationDate := CkJsonObject__stringOf(jResp,'data.attributes.creationDate');
Handle := CkJsonObject__stringOf(jResp,'data.attributes.creator.handle');
Name := CkJsonObject__stringOf(jResp,'data.attributes.creator.name');
DefaultRule := CkJsonObject__stringOf(jResp,'data.attributes.defaultRule');
Description := CkJsonObject__stringOf(jResp,'data.attributes.description');
Enabled := CkJsonObject__stringOf(jResp,'data.attributes.enabled');
Expression := CkJsonObject__stringOf(jResp,'data.attributes.expression');
AttributesName := CkJsonObject__stringOf(jResp,'data.attributes.name');
UpdateAuthorUuId := CkJsonObject__stringOf(jResp,'data.attributes.updateAuthorUuId');
UpdateDate := CkJsonObject__stringOf(jResp,'data.attributes.updateDate');
UpdatedAt := CkJsonObject__stringOf(jResp,'data.attributes.updatedAt');
UpdaterHandle := CkJsonObject__stringOf(jResp,'data.attributes.updater.handle');
UpdaterName := CkJsonObject__stringOf(jResp,'data.attributes.updater.name');
Version := CkJsonObject__stringOf(jResp,'data.attributes.version');
Id := CkJsonObject__stringOf(jResp,'data.id');
v_Type := CkJsonObject__stringOf(jResp,'data.type');

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -X PATCH
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "attributes": {
      "description": "<string>",
      "enabled": "<boolean>",
      "expression": "<string>"
    },
    "type": "agent_rule"
  }
}'
https://api.app.ddog-gov.com/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id

Postman Collection Item JSON

{
  "name": "Update a Cloud Workload Security Agent rule",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"attributes\": {\n      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\"\n    },\n    \"type\": \"agent_rule\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "security_monitoring",
        "cloud_workload_security",
        "agent_rules",
        ":agent_rule_id"
      ],
      "variable": [
        {
          "key": "agent_rule_id",
          "value": "<string>"
        }
      ]
    },
    "description": "Update a specific Agent rule.\nReturns the Agent rule object when the request is successful."
  },
  "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      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\"\n    },\n    \"type\": \"agent_rule\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules",
            ":agent_rule_id"
          ],
          "variable": [
            {
              "key": "agent_rule_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"attributes\": {\n      \"agentConstraint\": \"<string>\",\n      \"category\": \"<string>\",\n      \"creationAuthorUuId\": \"<string>\",\n      \"creationDate\": \"<long>\",\n      \"creator\": {\n        \"handle\": \"<string>\",\n        \"name\": \"<string>\"\n      },\n      \"defaultRule\": \"<boolean>\",\n      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\",\n      \"name\": \"<string>\",\n      \"updateAuthorUuId\": \"<string>\",\n      \"updateDate\": \"<long>\",\n      \"updatedAt\": \"<long>\",\n      \"updater\": {\n        \"handle\": \"<string>\",\n        \"name\": \"<string>\"\n      },\n      \"version\": \"<long>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"agent_rule\"\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      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\"\n    },\n    \"type\": \"agent_rule\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules",
            ":agent_rule_id"
          ],
          "variable": [
            {
              "key": "agent_rule_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      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\"\n    },\n    \"type\": \"agent_rule\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules",
            ":agent_rule_id"
          ],
          "variable": [
            {
              "key": "agent_rule_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      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\"\n    },\n    \"type\": \"agent_rule\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules",
            ":agent_rule_id"
          ],
          "variable": [
            {
              "key": "agent_rule_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": "Concurrent Modification",
      "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      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\"\n    },\n    \"type\": \"agent_rule\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules",
            ":agent_rule_id"
          ],
          "variable": [
            {
              "key": "agent_rule_id"
            }
          ]
        }
      },
      "status": "Conflict",
      "code": 409,
      "_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      \"description\": \"<string>\",\n      \"enabled\": \"<boolean>\",\n      \"expression\": \"<string>\"\n    },\n    \"type\": \"agent_rule\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/security_monitoring/cloud_workload_security/agent_rules/:agent_rule_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "security_monitoring",
            "cloud_workload_security",
            "agent_rules",
            ":agent_rule_id"
          ],
          "variable": [
            {
              "key": "agent_rule_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}"
    }
  ]
}