Chilkat Online Tools

unicodeC / Datadog API Collection / Create an Azure integration

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;

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

    http = CkHttpW_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.

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

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"app_service_plan_filters",L"key:value,filter:example");
    CkJsonObjectW_UpdateBool(json,L"automute",TRUE);
    CkJsonObjectW_UpdateString(json,L"client_id",L"testc7f6-1234-5678-9101-3fcbf464test");
    CkJsonObjectW_UpdateString(json,L"client_secret",L"testingx./Sw*g/Y33t..R1cH+hScMDt");
    CkJsonObjectW_UpdateBool(json,L"cspm_enabled",TRUE);
    CkJsonObjectW_UpdateBool(json,L"custom_metrics_enabled",TRUE);
    CkJsonObjectW_UpdateString(json,L"errors[0]",L"*");
    CkJsonObjectW_UpdateString(json,L"host_filters",L"key:value,filter:example");
    CkJsonObjectW_UpdateString(json,L"new_client_id",L"new1c7f6-1234-5678-9101-3fcbf464test");
    CkJsonObjectW_UpdateString(json,L"new_tenant_name",L"new1c44-1234-5678-9101-cc00736ftest");
    CkJsonObjectW_UpdateString(json,L"tenant_name",L"testc44-1234-5678-9101-cc00736ftest");

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

    resp = CkHttpW_PostJson3(http,L"https://api.app.ddog-gov.com/api/v1/integration/azure",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

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

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

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

Postman Collection Item JSON

{
  "name": "Create an Azure integration",
  "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": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "integration",
        "azure"
      ]
    },
    "description": "Create a Datadog-Azure integration.\n\nUsing the `POST` method updates your integration configuration by adding your new\nconfiguration to the existing one in your Datadog organization.\n\nUsing the `PUT` method updates your integration configuration by replacing your\ncurrent configuration with the new one sent to your Datadog organization."
  },
  "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": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure"
          ]
        }
      },
      "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": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure"
          ]
        }
      },
      "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": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure"
          ]
        }
      },
      "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": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "integration",
            "azure"
          ]
        }
      },
      "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}"
    }
  ]
}