Chilkat Online Tools

Python / Datadog API Collection / Update 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")

sbRequestBody = chilkat2.StringBuilder()
json.EmitSb(sbRequestBody)

# resp is a CkHttpResponse
resp = http.PTextSb("PUT","https://api.app.ddog-gov.com/api/v1/dashboard/lists/manual/:list_id",sbRequestBody,"utf-8","application/json",False,False)
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 PUT
	-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/:list_id

Postman Collection Item JSON

{
  "name": "Update a dashboard list",
  "request": {
    "method": "PUT",
    "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/:list_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "dashboard",
        "lists",
        "manual",
        ":list_id"
      ],
      "variable": [
        {
          "key": "list_id",
          "value": "-62147425"
        }
      ]
    },
    "description": "Update the name of a dashboard list."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "PUT",
        "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/:list_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual",
            ":list_id"
          ],
          "variable": [
            {
              "key": "list_id"
            }
          ]
        }
      },
      "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": "PUT",
        "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/:list_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual",
            ":list_id"
          ],
          "variable": [
            {
              "key": "list_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": "Forbidden",
      "originalRequest": {
        "method": "PUT",
        "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/:list_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual",
            ":list_id"
          ],
          "variable": [
            {
              "key": "list_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": "PUT",
        "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/:list_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual",
            ":list_id"
          ],
          "variable": [
            {
              "key": "list_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": "PUT",
        "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/:list_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "lists",
            "manual",
            ":list_id"
          ],
          "variable": [
            {
              "key": "list_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}"
    }
  ]
}