Chilkat Online Tools

SQL Server / Datadog API Collection / Get a notebook

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

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

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

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.app.ddog-gov.com/api/v1/notebooks/:notebook_id', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    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 @http, 'LastStatus', @respStatusCode OUT

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

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    DECLARE @id nvarchar(4000)

    DECLARE @v_type nvarchar(4000)

    DECLARE @DefinitionType nvarchar(4000)

    DECLARE @Text nvarchar(4000)

    DECLARE @Id int
    EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'data.id'
    DECLARE @v_Type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'data.type'
    DECLARE @Live_span nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Live_span OUT, 'data.attributes.time.live_span'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'data.attributes.name'
    DECLARE @Created_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Created_at OUT, 'data.attributes.author.created_at'
    DECLARE @Disabled int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Disabled OUT, 'data.attributes.author.disabled'
    DECLARE @v_Email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'data.attributes.author.email'
    DECLARE @Handle nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Handle OUT, 'data.attributes.author.handle'
    DECLARE @Icon nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Icon OUT, 'data.attributes.author.icon'
    DECLARE @AuthorName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @AuthorName OUT, 'data.attributes.author.name'
    DECLARE @Status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Status OUT, 'data.attributes.author.status'
    DECLARE @Title nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Title OUT, 'data.attributes.author.title'
    DECLARE @Verified int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Verified OUT, 'data.attributes.author.verified'
    DECLARE @Created nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Created OUT, 'data.attributes.created'
    DECLARE @Is_template int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Is_template OUT, 'data.attributes.metadata.is_template'
    DECLARE @Take_snapshots int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Take_snapshots OUT, 'data.attributes.metadata.take_snapshots'
    DECLARE @MetadataType nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @MetadataType OUT, 'data.attributes.metadata.type'
    DECLARE @Modified nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Modified OUT, 'data.attributes.modified'
    DECLARE @AttributesStatus nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @AttributesStatus OUT, 'data.attributes.status'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data.attributes.cells'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'data.attributes.cells[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'data.attributes.cells[i].type'
        EXEC sp_OAMethod @jResp, 'StringOf', @DefinitionType OUT, 'data.attributes.cells[i].attributes.definition.type'
        EXEC sp_OAMethod @jResp, 'StringOf', @Text OUT, 'data.attributes.cells[i].attributes.definition.text'
        SELECT @i = @i + 1
      END

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


END
GO

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