Chilkat Online Tools

unicodeC / Datadog API Collection / Create a dashboard list

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;
    const wchar_t *name;
    const wchar_t *v_Email;
    const wchar_t *Handle;
    const wchar_t *Name;
    const wchar_t *created;
    int dashboard_count;
    int id;
    BOOL is_favorite;
    const wchar_t *modified;
    const wchar_t *v_type;

    // 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.

    // {
    //   "name": "My Dashboard",
    //   "author": {
    //     "email": "Excepteur id tempor cillum",
    //     "handle": "culpa nostrud pariatur",
    //     "name": "cillum minim"
    //   },
    //   "created": "1966-02-10T07:56:34.100Z",
    //   "dashboard_count": 38191328,
    //   "id": 17219875,
    //   "is_favorite": false,
    //   "modified": "1943-12-25T04:37:37.575Z",
    //   "type": "manual_dashboard_list"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"name",L"My Dashboard");
    CkJsonObjectW_UpdateString(json,L"author.email",L"Excepteur id tempor cillum");
    CkJsonObjectW_UpdateString(json,L"author.handle",L"culpa nostrud pariatur");
    CkJsonObjectW_UpdateString(json,L"author.name",L"cillum minim");
    CkJsonObjectW_UpdateString(json,L"created",L"1966-02-10T07:56:34.100Z");
    CkJsonObjectW_UpdateInt(json,L"dashboard_count",38191328);
    CkJsonObjectW_UpdateInt(json,L"id",17219875);
    CkJsonObjectW_UpdateBool(json,L"is_favorite",FALSE);
    CkJsonObjectW_UpdateString(json,L"modified",L"1943-12-25T04:37:37.575Z");
    CkJsonObjectW_UpdateString(json,L"type",L"manual_dashboard_list");

    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/dashboard/lists/manual",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);

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

    // {
    //   "name": "My Dashboard",
    //   "author": {
    //     "email": "Excepteur id tempor cillum",
    //     "handle": "culpa nostrud pariatur",
    //     "name": "cillum minim"
    //   },
    //   "created": "1966-02-10T07:56:34.100Z",
    //   "dashboard_count": 38191328,
    //   "id": 17219875,
    //   "is_favorite": false,
    //   "modified": "1943-12-25T04:37:37.575Z",
    //   "type": "manual_dashboard_list"
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    name = CkJsonObjectW_stringOf(jResp,L"name");
    v_Email = CkJsonObjectW_stringOf(jResp,L"author.email");
    Handle = CkJsonObjectW_stringOf(jResp,L"author.handle");
    Name = CkJsonObjectW_stringOf(jResp,L"author.name");
    created = CkJsonObjectW_stringOf(jResp,L"created");
    dashboard_count = CkJsonObjectW_IntOf(jResp,L"dashboard_count");
    id = CkJsonObjectW_IntOf(jResp,L"id");
    is_favorite = CkJsonObjectW_BoolOf(jResp,L"is_favorite");
    modified = CkJsonObjectW_stringOf(jResp,L"modified");
    v_type = CkJsonObjectW_stringOf(jResp,L"type");


    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 '{
  "name": "My Dashboard",
  "author": {
    "email": "Excepteur id tempor cillum",
    "handle": "culpa nostrud pariatur",
    "name": "cillum minim"
  },
  "created": "1966-02-10T07:56:34.100Z",
  "dashboard_count": 38191328,
  "id": 17219875,
  "is_favorite": false,
  "modified": "1943-12-25T04:37:37.575Z",
  "type": "manual_dashboard_list"
}'
https://api.app.ddog-gov.com/api/v1/dashboard/lists/manual

Postman Collection Item JSON

{
  "name": "Create a dashboard list",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"name\": \"My Dashboard\",\n  \"author\": {\n    \"email\": \"Excepteur id tempor cillum\",\n    \"handle\": \"culpa nostrud pariatur\",\n    \"name\": \"cillum minim\"\n  },\n  \"created\": \"1966-02-10T07:56:34.100Z\",\n  \"dashboard_count\": 38191328,\n  \"id\": 17219875,\n  \"is_favorite\": false,\n  \"modified\": \"1943-12-25T04:37:37.575Z\",\n  \"type\": \"manual_dashboard_list\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/dashboard/lists/manual",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "dashboard",
        "lists",
        "manual"
      ]
    },
    "description": "Create an empty dashboard list."
  },
  "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  \"name\": \"My Dashboard\",\n  \"author\": {\n    \"email\": \"Excepteur id tempor cillum\",\n    \"handle\": \"culpa nostrud pariatur\",\n    \"name\": \"cillum minim\"\n  },\n  \"created\": \"1966-02-10T07:56:34.100Z\",\n  \"dashboard_count\": 38191328,\n  \"id\": 17219875,\n  \"is_favorite\": false,\n  \"modified\": \"1943-12-25T04:37:37.575Z\",\n  \"type\": \"manual_dashboard_list\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/lists/manual",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"name\": \"My Dashboard\",\n  \"author\": {\n    \"email\": \"Excepteur id tempor cillum\",\n    \"handle\": \"culpa nostrud pariatur\",\n    \"name\": \"cillum minim\"\n  },\n  \"created\": \"1966-02-10T07:56:34.100Z\",\n  \"dashboard_count\": 38191328,\n  \"id\": 17219875,\n  \"is_favorite\": false,\n  \"modified\": \"1943-12-25T04:37:37.575Z\",\n  \"type\": \"manual_dashboard_list\"\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  \"name\": \"My Dashboard\",\n  \"author\": {\n    \"email\": \"Excepteur id tempor cillum\",\n    \"handle\": \"culpa nostrud pariatur\",\n    \"name\": \"cillum minim\"\n  },\n  \"created\": \"1966-02-10T07:56:34.100Z\",\n  \"dashboard_count\": 38191328,\n  \"id\": 17219875,\n  \"is_favorite\": false,\n  \"modified\": \"1943-12-25T04:37:37.575Z\",\n  \"type\": \"manual_dashboard_list\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/lists/manual",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual"
          ]
        }
      },
      "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": "Forbidden",
      "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  \"name\": \"My Dashboard\",\n  \"author\": {\n    \"email\": \"Excepteur id tempor cillum\",\n    \"handle\": \"culpa nostrud pariatur\",\n    \"name\": \"cillum minim\"\n  },\n  \"created\": \"1966-02-10T07:56:34.100Z\",\n  \"dashboard_count\": 38191328,\n  \"id\": 17219875,\n  \"is_favorite\": false,\n  \"modified\": \"1943-12-25T04:37:37.575Z\",\n  \"type\": \"manual_dashboard_list\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/lists/manual",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual"
          ]
        }
      },
      "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  \"name\": \"My Dashboard\",\n  \"author\": {\n    \"email\": \"Excepteur id tempor cillum\",\n    \"handle\": \"culpa nostrud pariatur\",\n    \"name\": \"cillum minim\"\n  },\n  \"created\": \"1966-02-10T07:56:34.100Z\",\n  \"dashboard_count\": 38191328,\n  \"id\": 17219875,\n  \"is_favorite\": false,\n  \"modified\": \"1943-12-25T04:37:37.575Z\",\n  \"type\": \"manual_dashboard_list\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/lists/manual",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual"
          ]
        }
      },
      "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}"
    }
  ]
}