Chilkat Online Tools

Perl / Datadog API Collection / Create a dashboard list

Back to Collection Items

use chilkat();

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

$http = chilkat::CkHttp->new();

# 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 = chilkat::CkJsonObject->new();
$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",0);
$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 HttpResponse
$resp = $http->PostJson3("https://api.app.ddog-gov.com/api/v1/dashboard/lists/manual","application/json",$json);
if ($http->get_LastMethodSuccess() == 0) {
    print $http->lastErrorText() . "\r\n";
    exit;
}

$sbResponseBody = chilkat::CkStringBuilder->new();
$resp->GetBodySb($sbResponseBody);

$jResp = chilkat::CkJsonObject->new();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(0);

print "Response Body:" . "\r\n";
print $jResp->emit() . "\r\n";

$respStatusCode = $resp->get_StatusCode();
print "Response Status Code = " . $respStatusCode . "\r\n";
if ($respStatusCode >= 400) {
    print "Response Header:" . "\r\n";
    print $resp->header() . "\r\n";
    print "Failed." . "\r\n";

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