Chilkat Online Tools

VB6 / Datadog API Collection / Get a notebook

Back to Collection Items

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

Dim http As New ChilkatHttp
Dim success As Long

http.SetRequestHeader "Accept","application/json"

Dim sbResponseBody As New ChilkatStringBuilder
success = http.QuickGetSb("https://api.app.ddog-gov.com/api/v1/notebooks/:notebook_id",sbResponseBody)
If (success = 0) Then
    Debug.Print http.LastErrorText
    Exit Sub
End If

Dim jResp As New ChilkatJsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0

Debug.Print "Response Body:"
Debug.Print jResp.Emit()

Dim respStatusCode As Long
respStatusCode = http.LastStatus
Debug.Print "Response Status Code = " & respStatusCode
If (respStatusCode >= 400) Then
    Debug.Print "Response Header:"
    Debug.Print http.LastHeader
    Debug.Print "Failed."
    Exit Sub
End If

' 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

Dim id As String
Dim v_type As String
Dim DefinitionType As String
Dim Text As String

Dim Id As Long
Id = jResp.IntOf("data.id")
Dim v_Type As String
v_Type = jResp.StringOf("data.type")
Dim Live_span As String
Live_span = jResp.StringOf("data.attributes.time.live_span")
Dim Name As String
Name = jResp.StringOf("data.attributes.name")
Dim Created_at As String
Created_at = jResp.StringOf("data.attributes.author.created_at")
Dim Disabled As Long
Disabled = jResp.BoolOf("data.attributes.author.disabled")
Dim v_Email As String
v_Email = jResp.StringOf("data.attributes.author.email")
Dim Handle As String
Handle = jResp.StringOf("data.attributes.author.handle")
Dim Icon As String
Icon = jResp.StringOf("data.attributes.author.icon")
Dim AuthorName As String
AuthorName = jResp.StringOf("data.attributes.author.name")
Dim Status As String
Status = jResp.StringOf("data.attributes.author.status")
Dim Title As String
Title = jResp.StringOf("data.attributes.author.title")
Dim Verified As Long
Verified = jResp.BoolOf("data.attributes.author.verified")
Dim Created As String
Created = jResp.StringOf("data.attributes.created")
Dim Is_template As Long
Is_template = jResp.BoolOf("data.attributes.metadata.is_template")
Dim Take_snapshots As Long
Take_snapshots = jResp.BoolOf("data.attributes.metadata.take_snapshots")
Dim MetadataType As String
MetadataType = jResp.StringOf("data.attributes.metadata.type")
Dim Modified As String
Modified = jResp.StringOf("data.attributes.modified")
Dim AttributesStatus As String
AttributesStatus = jResp.StringOf("data.attributes.status")
Dim i As Long
i = 0
Dim count_i As Long
count_i = jResp.SizeOfArray("data.attributes.cells")
Do While i < count_i
    jResp.I = i
    id = jResp.StringOf("data.attributes.cells[i].id")
    v_type = jResp.StringOf("data.attributes.cells[i].type")
    DefinitionType = jResp.StringOf("data.attributes.cells[i].attributes.definition.type")
    Text = jResp.StringOf("data.attributes.cells[i].attributes.definition.text")
    i = i + 1
Loop

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}"
    }
  ]
}