Chilkat Online Tools

SQL Server / Datadog API Collection / Update Azure integration host filters

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "app_service_plan_filters": "key:value,filter:example",
    --   "automute": true,
    --   "client_id": "testc7f6-1234-5678-9101-3fcbf464test",
    --   "client_secret": "testingx./Sw*g/Y33t..R1cH+hScMDt",
    --   "cspm_enabled": true,
    --   "custom_metrics_enabled": true,
    --   "errors": [
    --     "*"
    --   ],
    --   "host_filters": "key:value,filter:example",
    --   "new_client_id": "new1c7f6-1234-5678-9101-3fcbf464test",
    --   "new_tenant_name": "new1c44-1234-5678-9101-cc00736ftest",
    --   "tenant_name": "testc44-1234-5678-9101-cc00736ftest"
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'app_service_plan_filters', 'key:value,filter:example'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'automute', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'client_id', 'testc7f6-1234-5678-9101-3fcbf464test'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'client_secret', 'testingx./Sw*g/Y33t..R1cH+hScMDt'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'cspm_enabled', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'custom_metrics_enabled', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'errors[0]', '*'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'host_filters', 'key:value,filter:example'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'new_client_id', 'new1c7f6-1234-5678-9101-3fcbf464test'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'new_tenant_name', 'new1c44-1234-5678-9101-cc00736ftest'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'tenant_name', 'testc44-1234-5678-9101-cc00736ftest'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.app.ddog-gov.com/api/v1/integration/azure/host_filters', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "app_service_plan_filters": "key:value,filter:example",
  "automute": true,
  "client_id": "testc7f6-1234-5678-9101-3fcbf464test",
  "client_secret": "testingx./Sw*g/Y33t..R1cH+hScMDt",
  "cspm_enabled": true,
  "custom_metrics_enabled": true,
  "errors": [
    "*"
  ],
  "host_filters": "key:value,filter:example",
  "new_client_id": "new1c7f6-1234-5678-9101-3fcbf464test",
  "new_tenant_name": "new1c44-1234-5678-9101-cc00736ftest",
  "tenant_name": "testc44-1234-5678-9101-cc00736ftest"
}'
https://api.app.ddog-gov.com/api/v1/integration/azure/host_filters

Postman Collection Item JSON

{
  "name": "Update Azure integration host filters",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"app_service_plan_filters\": \"key:value,filter:example\",\n  \"automute\": true,\n  \"client_id\": \"testc7f6-1234-5678-9101-3fcbf464test\",\n  \"client_secret\": \"testingx./Sw*g/Y33t..R1cH+hScMDt\",\n  \"cspm_enabled\": true,\n  \"custom_metrics_enabled\": true,\n  \"errors\": [\n    \"*\"\n  ],\n  \"host_filters\": \"key:value,filter:example\",\n  \"new_client_id\": \"new1c7f6-1234-5678-9101-3fcbf464test\",\n  \"new_tenant_name\": \"new1c44-1234-5678-9101-cc00736ftest\",\n  \"tenant_name\": \"testc44-1234-5678-9101-cc00736ftest\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/integration/azure/host_filters",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "integration",
        "azure",
        "host_filters"
      ]
    },
    "description": "Update the defined list of host filters for a given Datadog-Azure integration."
  },
  "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  \"app_service_plan_filters\": \"key:value,filter:example\",\n  \"automute\": true,\n  \"client_id\": \"testc7f6-1234-5678-9101-3fcbf464test\",\n  \"client_secret\": \"testingx./Sw*g/Y33t..R1cH+hScMDt\",\n  \"cspm_enabled\": true,\n  \"custom_metrics_enabled\": true,\n  \"errors\": [\n    \"*\"\n  ],\n  \"host_filters\": \"key:value,filter:example\",\n  \"new_client_id\": \"new1c7f6-1234-5678-9101-3fcbf464test\",\n  \"new_tenant_name\": \"new1c44-1234-5678-9101-cc00736ftest\",\n  \"tenant_name\": \"testc44-1234-5678-9101-cc00736ftest\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/integration/azure/host_filters",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure",
            "host_filters"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{}"
    },
    {
      "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  \"app_service_plan_filters\": \"key:value,filter:example\",\n  \"automute\": true,\n  \"client_id\": \"testc7f6-1234-5678-9101-3fcbf464test\",\n  \"client_secret\": \"testingx./Sw*g/Y33t..R1cH+hScMDt\",\n  \"cspm_enabled\": true,\n  \"custom_metrics_enabled\": true,\n  \"errors\": [\n    \"*\"\n  ],\n  \"host_filters\": \"key:value,filter:example\",\n  \"new_client_id\": \"new1c7f6-1234-5678-9101-3fcbf464test\",\n  \"new_tenant_name\": \"new1c44-1234-5678-9101-cc00736ftest\",\n  \"tenant_name\": \"testc44-1234-5678-9101-cc00736ftest\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/integration/azure/host_filters",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure",
            "host_filters"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\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  \"app_service_plan_filters\": \"key:value,filter:example\",\n  \"automute\": true,\n  \"client_id\": \"testc7f6-1234-5678-9101-3fcbf464test\",\n  \"client_secret\": \"testingx./Sw*g/Y33t..R1cH+hScMDt\",\n  \"cspm_enabled\": true,\n  \"custom_metrics_enabled\": true,\n  \"errors\": [\n    \"*\"\n  ],\n  \"host_filters\": \"key:value,filter:example\",\n  \"new_client_id\": \"new1c7f6-1234-5678-9101-3fcbf464test\",\n  \"new_tenant_name\": \"new1c44-1234-5678-9101-cc00736ftest\",\n  \"tenant_name\": \"testc44-1234-5678-9101-cc00736ftest\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/integration/azure/host_filters",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure",
            "host_filters"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\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  \"app_service_plan_filters\": \"key:value,filter:example\",\n  \"automute\": true,\n  \"client_id\": \"testc7f6-1234-5678-9101-3fcbf464test\",\n  \"client_secret\": \"testingx./Sw*g/Y33t..R1cH+hScMDt\",\n  \"cspm_enabled\": true,\n  \"custom_metrics_enabled\": true,\n  \"errors\": [\n    \"*\"\n  ],\n  \"host_filters\": \"key:value,filter:example\",\n  \"new_client_id\": \"new1c7f6-1234-5678-9101-3fcbf464test\",\n  \"new_tenant_name\": \"new1c44-1234-5678-9101-cc00736ftest\",\n  \"tenant_name\": \"testc44-1234-5678-9101-cc00736ftest\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/integration/azure/host_filters",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure",
            "host_filters"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"Bad Request\",\n    \"Bad Request\"\n  ]\n}"
    }
  ]
}