Chilkat Online Tools

unicodeC / Datadog API Collection / Get a notebook

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *id;
    const wchar_t *v_type;
    const wchar_t *DefinitionType;
    const wchar_t *Text;
    int Id;
    const wchar_t *v_Type;
    const wchar_t *Live_span;
    const wchar_t *Name;
    const wchar_t *Created_at;
    BOOL Disabled;
    const wchar_t *v_Email;
    const wchar_t *Handle;
    const wchar_t *Icon;
    const wchar_t *AuthorName;
    const wchar_t *Status;
    const wchar_t *Title;
    BOOL Verified;
    const wchar_t *Created;
    BOOL Is_template;
    BOOL Take_snapshots;
    const wchar_t *MetadataType;
    const wchar_t *Modified;
    const wchar_t *AttributesStatus;
    int i;
    int count_i;

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

    http = CkHttpW_Create();

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

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api.app.ddog-gov.com/api/v1/notebooks/:notebook_id",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

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

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

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

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

    // {
    //   "data": {
    //     "id": 123456,
    //     "type": "notebooks",
    //     "attributes": {
    //       "cells": [
    //         {
    //           "id": "abcd1234",
    //           "type": "notebook_cells",
    //           "attributes": {
    //             "definition": {
    //               "type": "markdown",
    //               "text": "# Example Header \nexample content"
    //             }
    //           }
    //         },
    //         {
    //           "id": "abcd1234",
    //           "type": "notebook_cells",
    //           "attributes": {
    //             "definition": {
    //               "type": "markdown",
    //               "text": "# Example Header \nexample content"
    //             }
    //           }
    //         }
    //       ],
    //       "time": {
    //         "live_span": "1h"
    //       },
    //       "name": "Example Notebook",
    //       "author": {
    //         "created_at": "1944-02-06T04:58:13.667Z",
    //         "disabled": false,
    //         "email": "tempor exercitation",
    //         "handle": "est eu aliquip officia",
    //         "icon": "nostrud n",
    //         "name": "dolor dolor",
    //         "status": "anim Ut pariatur",
    //         "title": "eu",
    //         "verified": true
    //       },
    //       "created": "2021-02-24T23:14:15.173964+00:00",
    //       "metadata": {
    //         "is_template": false,
    //         "take_snapshots": false,
    //         "type": "investigation"
    //       },
    //       "modified": "2021-02-24T23:15:23.274966+00:00",
    //       "status": "published"
    //     }
    //   }
    // }

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

    Id = CkJsonObjectW_IntOf(jResp,L"data.id");
    v_Type = CkJsonObjectW_stringOf(jResp,L"data.type");
    Live_span = CkJsonObjectW_stringOf(jResp,L"data.attributes.time.live_span");
    Name = CkJsonObjectW_stringOf(jResp,L"data.attributes.name");
    Created_at = CkJsonObjectW_stringOf(jResp,L"data.attributes.author.created_at");
    Disabled = CkJsonObjectW_BoolOf(jResp,L"data.attributes.author.disabled");
    v_Email = CkJsonObjectW_stringOf(jResp,L"data.attributes.author.email");
    Handle = CkJsonObjectW_stringOf(jResp,L"data.attributes.author.handle");
    Icon = CkJsonObjectW_stringOf(jResp,L"data.attributes.author.icon");
    AuthorName = CkJsonObjectW_stringOf(jResp,L"data.attributes.author.name");
    Status = CkJsonObjectW_stringOf(jResp,L"data.attributes.author.status");
    Title = CkJsonObjectW_stringOf(jResp,L"data.attributes.author.title");
    Verified = CkJsonObjectW_BoolOf(jResp,L"data.attributes.author.verified");
    Created = CkJsonObjectW_stringOf(jResp,L"data.attributes.created");
    Is_template = CkJsonObjectW_BoolOf(jResp,L"data.attributes.metadata.is_template");
    Take_snapshots = CkJsonObjectW_BoolOf(jResp,L"data.attributes.metadata.take_snapshots");
    MetadataType = CkJsonObjectW_stringOf(jResp,L"data.attributes.metadata.type");
    Modified = CkJsonObjectW_stringOf(jResp,L"data.attributes.modified");
    AttributesStatus = CkJsonObjectW_stringOf(jResp,L"data.attributes.status");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.attributes.cells");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        id = CkJsonObjectW_stringOf(jResp,L"data.attributes.cells[i].id");
        v_type = CkJsonObjectW_stringOf(jResp,L"data.attributes.cells[i].type");
        DefinitionType = CkJsonObjectW_stringOf(jResp,L"data.attributes.cells[i].attributes.definition.type");
        Text = CkJsonObjectW_stringOf(jResp,L"data.attributes.cells[i].attributes.definition.text");
        i = i + 1;
    }



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

    }

Curl Command

curl -X GET
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/notebooks/:notebook_id

Postman Collection Item JSON

{
  "name": "Get a notebook",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/notebooks/:notebook_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "notebooks",
        ":notebook_id"
      ],
      "variable": [
        {
          "key": "notebook_id",
          "value": "-62147425"
        }
      ]
    },
    "description": "Get a notebook using the specified notebook ID."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/notebooks/:notebook_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "notebooks",
            ":notebook_id"
          ],
          "variable": [
            {
              "key": "notebook_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"id\": 123456,\n    \"type\": \"notebooks\",\n    \"attributes\": {\n      \"cells\": [\n        {\n          \"id\": \"abcd1234\",\n          \"type\": \"notebook_cells\",\n          \"attributes\": {\n            \"definition\": {\n              \"type\": \"markdown\",\n              \"text\": \"# Example Header \\nexample content\"\n            }\n          }\n        },\n        {\n          \"id\": \"abcd1234\",\n          \"type\": \"notebook_cells\",\n          \"attributes\": {\n            \"definition\": {\n              \"type\": \"markdown\",\n              \"text\": \"# Example Header \\nexample content\"\n            }\n          }\n        }\n      ],\n      \"time\": {\n        \"live_span\": \"1h\"\n      },\n      \"name\": \"Example Notebook\",\n      \"author\": {\n        \"created_at\": \"1944-02-06T04:58:13.667Z\",\n        \"disabled\": false,\n        \"email\": \"tempor exercitation\",\n        \"handle\": \"est eu aliquip officia\",\n        \"icon\": \"nostrud n\",\n        \"name\": \"dolor dolor\",\n        \"status\": \"anim Ut pariatur\",\n        \"title\": \"eu\",\n        \"verified\": true\n      },\n      \"created\": \"2021-02-24T23:14:15.173964+00:00\",\n      \"metadata\": {\n        \"is_template\": false,\n        \"take_snapshots\": false,\n        \"type\": \"investigation\"\n      },\n      \"modified\": \"2021-02-24T23:15:23.274966+00:00\",\n      \"status\": \"published\"\n    }\n  }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/notebooks/:notebook_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "notebooks",
            ":notebook_id"
          ],
          "variable": [
            {
              "key": "notebook_id"
            }
          ]
        }
      },
      "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": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/notebooks/:notebook_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "notebooks",
            ":notebook_id"
          ],
          "variable": [
            {
              "key": "notebook_id"
            }
          ]
        }
      },
      "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": "Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/notebooks/:notebook_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "notebooks",
            ":notebook_id"
          ],
          "variable": [
            {
              "key": "notebook_id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/notebooks/:notebook_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "notebooks",
            ":notebook_id"
          ],
          "variable": [
            {
              "key": "notebook_id"
            }
          ]
        }
      },
      "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}"
    }
  ]
}