Chilkat Online Tools

delphiDll / Datadog API Collection / Create Scanning Group

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
strVal: PWideChar;
id: PWideChar;
v_type: PWideChar;
Description: PWideChar;
Query: PWideChar;
Is_enabled: PWideChar;
Name: PWideChar;
Id: PWideChar;
DataId: PWideChar;
v_Type: PWideChar;
dataType: PWideChar;
Version: PWideChar;
i: Integer;
count_i: Integer;

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": {
//     "type": "sensitive_data_scanner_group",
//     "attributes": {
//       "description": "<string>",
//       "filter": {
//         "query": "<string>"
//       },
//       "is_enabled": "<boolean>",
//       "name": "<string>",
//       "product_list": [
//         "logs",
//         "logs"
//       ]
//     },
//     "relationships": {
//       "configuration": {
//         "data": {
//           "id": "<string>",
//           "type": "sensitive_data_scanner_configuration"
//         }
//       },
//       "rules": {
//         "data": [
//           {
//             "id": "<string>",
//             "type": "sensitive_data_scanner_rule"
//           },
//           {
//             "id": "<string>",
//             "type": "sensitive_data_scanner_rule"
//           }
//         ]
//       }
//     }
//   },
//   "meta": {
//     "version": "<long>"
//   }
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'data.type','sensitive_data_scanner_group');
CkJsonObject_UpdateString(json,'data.attributes.description','<string>');
CkJsonObject_UpdateString(json,'data.attributes.filter.query','<string>');
CkJsonObject_UpdateString(json,'data.attributes.is_enabled','<boolean>');
CkJsonObject_UpdateString(json,'data.attributes.name','<string>');
CkJsonObject_UpdateString(json,'data.attributes.product_list[0]','logs');
CkJsonObject_UpdateString(json,'data.attributes.product_list[1]','logs');
CkJsonObject_UpdateString(json,'data.relationships.configuration.data.id','<string>');
CkJsonObject_UpdateString(json,'data.relationships.configuration.data.type','sensitive_data_scanner_configuration');
CkJsonObject_UpdateString(json,'data.relationships.rules.data[0].id','<string>');
CkJsonObject_UpdateString(json,'data.relationships.rules.data[0].type','sensitive_data_scanner_rule');
CkJsonObject_UpdateString(json,'data.relationships.rules.data[1].id','<string>');
CkJsonObject_UpdateString(json,'data.relationships.rules.data[1].type','sensitive_data_scanner_rule');
CkJsonObject_UpdateString(json,'meta.version','<long>');

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

resp := CkHttp_PostJson3(http,'https://api.app.ddog-gov.com/api/v2/sensitive-data-scanner/config/groups','application/json',json);
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": {
//       "description": "<string>",
//       "filter": {
//         "query": "<string>"
//       },
//       "is_enabled": "<boolean>",
//       "name": "<string>",
//       "product_list": [
//         "logs",
//         "logs"
//       ]
//     },
//     "id": "<string>",
//     "relationships": {
//       "configuration": {
//         "data": {
//           "id": "<string>",
//           "type": "sensitive_data_scanner_configuration"
//         }
//       },
//       "rules": {
//         "data": [
//           {
//             "id": "<string>",
//             "type": "sensitive_data_scanner_rule"
//           },
//           {
//             "id": "<string>",
//             "type": "sensitive_data_scanner_rule"
//           }
//         ]
//       }
//     },
//     "type": "sensitive_data_scanner_group"
//   },
//   "meta": {
//     "version": "<long>"
//   }
// }

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

Description := CkJsonObject__stringOf(jResp,'data.attributes.description');
Query := CkJsonObject__stringOf(jResp,'data.attributes.filter.query');
Is_enabled := CkJsonObject__stringOf(jResp,'data.attributes.is_enabled');
Name := CkJsonObject__stringOf(jResp,'data.attributes.name');
Id := CkJsonObject__stringOf(jResp,'data.id');
DataId := CkJsonObject__stringOf(jResp,'data.relationships.configuration.data.id');
v_Type := CkJsonObject__stringOf(jResp,'data.relationships.configuration.data.type');
dataType := CkJsonObject__stringOf(jResp,'data.type');
Version := CkJsonObject__stringOf(jResp,'meta.version');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'data.attributes.product_list');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'data.attributes.product_list[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'data.relationships.rules.data');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    id := CkJsonObject__stringOf(jResp,'data.relationships.rules.data[i].id');
    v_type := CkJsonObject__stringOf(jResp,'data.relationships.rules.data[i].type');
    i := i + 1;
  end;

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

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "data": {
    "type": "sensitive_data_scanner_group",
    "attributes": {
      "description": "<string>",
      "filter": {
        "query": "<string>"
      },
      "is_enabled": "<boolean>",
      "name": "<string>",
      "product_list": [
        "logs",
        "logs"
      ]
    },
    "relationships": {
      "configuration": {
        "data": {
          "id": "<string>",
          "type": "sensitive_data_scanner_configuration"
        }
      },
      "rules": {
        "data": [
          {
            "id": "<string>",
            "type": "sensitive_data_scanner_rule"
          },
          {
            "id": "<string>",
            "type": "sensitive_data_scanner_rule"
          }
        ]
      }
    }
  },
  "meta": {
    "version": "<long>"
  }
}'
https://api.app.ddog-gov.com/api/v2/sensitive-data-scanner/config/groups

Postman Collection Item JSON

{
  "name": "Create Scanning Group",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"data\": {\n    \"type\": \"sensitive_data_scanner_group\",\n    \"attributes\": {\n      \"description\": \"<string>\",\n      \"filter\": {\n        \"query\": \"<string>\"\n      },\n      \"is_enabled\": \"<boolean>\",\n      \"name\": \"<string>\",\n      \"product_list\": [\n        \"logs\",\n        \"logs\"\n      ]\n    },\n    \"relationships\": {\n      \"configuration\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"sensitive_data_scanner_configuration\"\n        }\n      },\n      \"rules\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          }\n        ]\n      }\n    }\n  },\n  \"meta\": {\n    \"version\": \"<long>\"\n  }\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v2/sensitive-data-scanner/config/groups",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "sensitive-data-scanner",
        "config",
        "groups"
      ]
    },
    "description": "Create a scanning group.\nThe request MAY include a configuration relationship.\nA rules relationship can be omitted entirely, but if it is included it MUST be\nnull or an empty array (rules cannot be created at the same time).\nThe new group will be ordered last within the configuration."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "POST",
        "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    \"type\": \"sensitive_data_scanner_group\",\n    \"attributes\": {\n      \"description\": \"<string>\",\n      \"filter\": {\n        \"query\": \"<string>\"\n      },\n      \"is_enabled\": \"<boolean>\",\n      \"name\": \"<string>\",\n      \"product_list\": [\n        \"logs\",\n        \"logs\"\n      ]\n    },\n    \"relationships\": {\n      \"configuration\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"sensitive_data_scanner_configuration\"\n        }\n      },\n      \"rules\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          }\n        ]\n      }\n    }\n  },\n  \"meta\": {\n    \"version\": \"<long>\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/sensitive-data-scanner/config/groups",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "sensitive-data-scanner",
            "config",
            "groups"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"attributes\": {\n      \"description\": \"<string>\",\n      \"filter\": {\n        \"query\": \"<string>\"\n      },\n      \"is_enabled\": \"<boolean>\",\n      \"name\": \"<string>\",\n      \"product_list\": [\n        \"logs\",\n        \"logs\"\n      ]\n    },\n    \"id\": \"<string>\",\n    \"relationships\": {\n      \"configuration\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"sensitive_data_scanner_configuration\"\n        }\n      },\n      \"rules\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          }\n        ]\n      }\n    },\n    \"type\": \"sensitive_data_scanner_group\"\n  },\n  \"meta\": {\n    \"version\": \"<long>\"\n  }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "POST",
        "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    \"type\": \"sensitive_data_scanner_group\",\n    \"attributes\": {\n      \"description\": \"<string>\",\n      \"filter\": {\n        \"query\": \"<string>\"\n      },\n      \"is_enabled\": \"<boolean>\",\n      \"name\": \"<string>\",\n      \"product_list\": [\n        \"logs\",\n        \"logs\"\n      ]\n    },\n    \"relationships\": {\n      \"configuration\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"sensitive_data_scanner_configuration\"\n        }\n      },\n      \"rules\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          }\n        ]\n      }\n    }\n  },\n  \"meta\": {\n    \"version\": \"<long>\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/sensitive-data-scanner/config/groups",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "sensitive-data-scanner",
            "config",
            "groups"
          ]
        }
      },
      "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": "Authentication Error",
      "originalRequest": {
        "method": "POST",
        "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    \"type\": \"sensitive_data_scanner_group\",\n    \"attributes\": {\n      \"description\": \"<string>\",\n      \"filter\": {\n        \"query\": \"<string>\"\n      },\n      \"is_enabled\": \"<boolean>\",\n      \"name\": \"<string>\",\n      \"product_list\": [\n        \"logs\",\n        \"logs\"\n      ]\n    },\n    \"relationships\": {\n      \"configuration\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"sensitive_data_scanner_configuration\"\n        }\n      },\n      \"rules\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          }\n        ]\n      }\n    }\n  },\n  \"meta\": {\n    \"version\": \"<long>\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/sensitive-data-scanner/config/groups",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "sensitive-data-scanner",
            "config",
            "groups"
          ]
        }
      },
      "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": "Too many requests",
      "originalRequest": {
        "method": "POST",
        "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    \"type\": \"sensitive_data_scanner_group\",\n    \"attributes\": {\n      \"description\": \"<string>\",\n      \"filter\": {\n        \"query\": \"<string>\"\n      },\n      \"is_enabled\": \"<boolean>\",\n      \"name\": \"<string>\",\n      \"product_list\": [\n        \"logs\",\n        \"logs\"\n      ]\n    },\n    \"relationships\": {\n      \"configuration\": {\n        \"data\": {\n          \"id\": \"<string>\",\n          \"type\": \"sensitive_data_scanner_configuration\"\n        }\n      },\n      \"rules\": {\n        \"data\": [\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          },\n          {\n            \"id\": \"<string>\",\n            \"type\": \"sensitive_data_scanner_rule\"\n          }\n        ]\n      }\n    }\n  },\n  \"meta\": {\n    \"version\": \"<long>\"\n  }\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v2/sensitive-data-scanner/config/groups",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "sensitive-data-scanner",
            "config",
            "groups"
          ]
        }
      },
      "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}"
    }
  ]
}