Chilkat Online Tools

VB.NET / Datadog API Collection / Update a Cloud Workload Security Agent rule

Back to Collection Items

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

Dim http As New Chilkat.Http
Dim success As Boolean

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

Dim json As New Chilkat.JsonObject
json.UpdateString("data.attributes.description","<string>")
json.UpdateString("data.attributes.enabled","<boolean>")
json.UpdateString("data.attributes.expression","<string>")
json.UpdateString("data.type","agent_rule")

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

Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)

Dim resp As Chilkat.HttpResponse = http.PTextSb("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 (http.LastMethodSuccess = False) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


Dim sbResponseBody As New Chilkat.StringBuilder
resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

Debug.WriteLine("Response Body:")
Debug.WriteLine(jResp.Emit())

Dim respStatusCode As Integer = resp.StatusCode
Debug.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Header:")
    Debug.WriteLine(resp.Header)
    Debug.WriteLine("Failed.")

    Exit Sub
End If



' 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




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

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