Chilkat Online Tools

Python / Datadog API Collection / Create a dashboard list

Back to Collection Items

import sys
import chilkat2

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

http = chilkat2.Http()

# 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 = chilkat2.JsonObject()
json.UpdateString("name","My Dashboard")
json.UpdateString("author.email","Excepteur id tempor cillum")
json.UpdateString("author.handle","culpa nostrud pariatur")
json.UpdateString("author.name","cillum minim")
json.UpdateString("created","1966-02-10T07:56:34.100Z")
json.UpdateInt("dashboard_count",38191328)
json.UpdateInt("id",17219875)
json.UpdateBool("is_favorite",False)
json.UpdateString("modified","1943-12-25T04:37:37.575Z")
json.UpdateString("type","manual_dashboard_list")

http.SetRequestHeader("Content-Type","application/json")
http.SetRequestHeader("Accept","application/json")

# resp is a CkHttpResponse
resp = http.PostJson3("https://api.app.ddog-gov.com/api/v1/dashboard/lists/manual","application/json",json)
if (http.LastMethodSuccess == False):
    print(http.LastErrorText)
    sys.exit()

sbResponseBody = chilkat2.StringBuilder()
resp.GetBodySb(sbResponseBody)

jResp = chilkat2.JsonObject()
jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

print("Response Body:")
print(jResp.Emit())

respStatusCode = resp.StatusCode
print("Response Status Code = " + str(respStatusCode))
if (respStatusCode >= 400):
    print("Response Header:")
    print(resp.Header)
    print("Failed.")

    sys.exit()

# 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

name = jResp.StringOf("name")
v_Email = jResp.StringOf("author.email")
Handle = jResp.StringOf("author.handle")
Name = jResp.StringOf("author.name")
created = jResp.StringOf("created")
dashboard_count = jResp.IntOf("dashboard_count")
id = jResp.IntOf("id")
is_favorite = jResp.BoolOf("is_favorite")
modified = jResp.StringOf("modified")
v_type = jResp.StringOf("type")

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