Chilkat Online Tools

PowerBuilder / Datadog API Collection / Create embed

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Dash_name
string ls_Dash_url
string ls_Embed_id
string ls_Graph_title
string ls_Html
integer li_Revoked
integer li_Shared_by

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "graph_json": "",
//   "legend": "no",
//   "size": "medium",
//   "timeframe": "1_hour",
//   "title": "Embed created through API"
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("graph_json","")
loo_Json.UpdateString("legend","no")
loo_Json.UpdateString("size","medium")
loo_Json.UpdateString("timeframe","1_hour")
loo_Json.UpdateString("title","Embed created through API")

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

loo_Resp = loo_Http.PostJson3("https://api.app.ddog-gov.com/api/v1/graph/embed","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "dash_name": "proident ut commodo",
//   "dash_url": "sint elit",
//   "embed_id": "velit",
//   "graph_title": "Excepteur ea consectetur sunt sint",
//   "html": "non cupidatat in veniam",
//   "revoked": false,
//   "shared_by": 76702863
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

ls_Dash_name = loo_JResp.StringOf("dash_name")
ls_Dash_url = loo_JResp.StringOf("dash_url")
ls_Embed_id = loo_JResp.StringOf("embed_id")
ls_Graph_title = loo_JResp.StringOf("graph_title")
ls_Html = loo_JResp.StringOf("html")
li_Revoked = loo_JResp.BoolOf("revoked")
li_Shared_by = loo_JResp.IntOf("shared_by")


destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "graph_json": "",
  "legend": "no",
  "size": "medium",
  "timeframe": "1_hour",
  "title": "Embed created through API"
}'
https://api.app.ddog-gov.com/api/v1/graph/embed

Postman Collection Item JSON

{
  "name": "Create embed",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"graph_json\": \"\",\n  \"legend\": \"no\",\n  \"size\": \"medium\",\n  \"timeframe\": \"1_hour\",\n  \"title\": \"Embed created through API\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/graph/embed",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "graph",
        "embed"
      ]
    },
    "description": "Creates a new embeddable graph.\n\nNote: If an embed already exists for the exact same query in a given organization,\nthe older embed is returned instead of creating a new embed.\n\nIf you are interested in using template variables, see\n[Embeddable Graphs with Template Variables](https://docs.datadoghq.com/dashboards/faq/embeddable-graphs-with-template-variables)."
  },
  "response": [
    {
      "name": "Payload accepted",
      "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  \"graph_json\": \"\",\n  \"legend\": \"no\",\n  \"size\": \"medium\",\n  \"timeframe\": \"1_hour\",\n  \"title\": \"Embed created through API\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/embed",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "embed"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"dash_name\": \"proident ut commodo\",\n  \"dash_url\": \"sint elit\",\n  \"embed_id\": \"velit\",\n  \"graph_title\": \"Excepteur ea consectetur sunt sint\",\n  \"html\": \"non cupidatat in veniam\",\n  \"revoked\": false,\n  \"shared_by\": 76702863\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  \"graph_json\": \"\",\n  \"legend\": \"no\",\n  \"size\": \"medium\",\n  \"timeframe\": \"1_hour\",\n  \"title\": \"Embed created through API\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/embed",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "embed"
          ]
        }
      },
      "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": "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  \"graph_json\": \"\",\n  \"legend\": \"no\",\n  \"size\": \"medium\",\n  \"timeframe\": \"1_hour\",\n  \"title\": \"Embed created through API\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/embed",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "embed"
          ]
        }
      },
      "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  \"graph_json\": \"\",\n  \"legend\": \"no\",\n  \"size\": \"medium\",\n  \"timeframe\": \"1_hour\",\n  \"title\": \"Embed created through API\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/embed",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "embed"
          ]
        }
      },
      "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}"
    }
  ]
}