Chilkat Online Tools

DataFlex / Datadog API Collection / Update a shared dashboard

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sDefault_value
    String sName
    String sPrefix
    Integer j
    Integer iCount_j
    String sStrVal
    String sDashboard_id
    String sDashboard_type
    String sHandle
    String sName
    String sCreated_at
    String sLive_span
    Boolean iGlobal_time_selectable_enabled
    String sPublic_url
    String sShare_type
    String sToken
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

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

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

    // {
    //   "global_time": {
    //     "live_span": "1h"
    //   },
    //   "share_list": [
    //     "test@datadoghq.com",
    //     "test2@datadoghq.com"
    //   ],
    //   "share_type": "invite"
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "global_time.live_span" "1h" To iSuccess
    Get ComUpdateString Of hoJson "share_list[0]" "test@datadoghq.com" To iSuccess
    Get ComUpdateString Of hoJson "share_list[1]" "test2@datadoghq.com" To iSuccess
    Get ComUpdateString Of hoJson "share_type" "invite" To iSuccess

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "PUT" "https://api.app.ddog-gov.com/api/v1/dashboard/public/:token" vSbRequestBody "utf-8" "application/json" False False To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    // {
    //   "dashboard_id": "123-abc-456",
    //   "dashboard_type": "custom_timeboard",
    //   "author": {
    //     "handle": "test@datadoghq.com",
    //     "name": "consequat irure sit"
    //   },
    //   "created_at": "2008-04-06T04:45:45.510Z",
    //   "global_time": {
    //     "live_span": "1h"
    //   },
    //   "global_time_selectable_enabled": false,
    //   "public_url": "fugiat esse mollit adipisicing",
    //   "selectable_template_vars": [
    //     {
    //       "default_value": "*",
    //       "name": "exampleVar",
    //       "prefix": "test",
    //       "visible_tags": [
    //         "selectableValue1",
    //         "selectableValue2"
    //       ]
    //     }
    //   ],
    //   "share_list": [
    //     "test@datadoghq.com",
    //     "test2@email.com"
    //   ],
    //   "share_type": "open",
    //   "token": "dolor fugiat consectetur ex"
    // }

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

    Get ComStringOf Of hoJResp "dashboard_id" To sDashboard_id
    Get ComStringOf Of hoJResp "dashboard_type" To sDashboard_type
    Get ComStringOf Of hoJResp "author.handle" To sHandle
    Get ComStringOf Of hoJResp "author.name" To sName
    Get ComStringOf Of hoJResp "created_at" To sCreated_at
    Get ComStringOf Of hoJResp "global_time.live_span" To sLive_span
    Get ComBoolOf Of hoJResp "global_time_selectable_enabled" To iGlobal_time_selectable_enabled
    Get ComStringOf Of hoJResp "public_url" To sPublic_url
    Get ComStringOf Of hoJResp "share_type" To sShare_type
    Get ComStringOf Of hoJResp "token" To sToken
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "selectable_template_vars" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "selectable_template_vars[i].default_value" To sDefault_value
        Get ComStringOf Of hoJResp "selectable_template_vars[i].name" To sName
        Get ComStringOf Of hoJResp "selectable_template_vars[i].prefix" To sPrefix
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "selectable_template_vars[i].visible_tags" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "selectable_template_vars[i].visible_tags[j]" To sStrVal
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "share_list" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "share_list[i]" To sStrVal
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -X PUT
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "global_time": {
    "live_span": "1h"
  },
  "share_list": [
    "test@datadoghq.com",
    "test2@datadoghq.com"
  ],
  "share_type": "invite"
}'
https://api.app.ddog-gov.com/api/v1/dashboard/public/:token

Postman Collection Item JSON

{
  "name": "Update a shared dashboard",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "dashboard",
        "public",
        ":token"
      ],
      "variable": [
        {
          "key": "token",
          "value": "tempor Ut sed velit"
        }
      ]
    },
    "description": "Update a shared dashboard associated with the specified token."
  },
  "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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"dashboard_id\": \"123-abc-456\",\n  \"dashboard_type\": \"custom_timeboard\",\n  \"author\": {\n    \"handle\": \"test@datadoghq.com\",\n    \"name\": \"consequat irure sit\"\n  },\n  \"created_at\": \"2008-04-06T04:45:45.510Z\",\n  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"global_time_selectable_enabled\": false,\n  \"public_url\": \"fugiat esse mollit adipisicing\",\n  \"selectable_template_vars\": [\n    {\n      \"default_value\": \"*\",\n      \"name\": \"exampleVar\",\n      \"prefix\": \"test\",\n      \"visible_tags\": [\n        \"selectableValue1\",\n        \"selectableValue2\"\n      ]\n    }\n  ],\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@email.com\"\n  ],\n  \"share_type\": \"open\",\n  \"token\": \"dolor fugiat consectetur ex\"\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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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": "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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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": "Item 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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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  \"global_time\": {\n    \"live_span\": \"1h\"\n  },\n  \"share_list\": [\n    \"test@datadoghq.com\",\n    \"test2@datadoghq.com\"\n  ],\n  \"share_type\": \"invite\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/dashboard/public/:token",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "dashboard",
            "public",
            ":token"
          ],
          "variable": [
            {
              "key": "token"
            }
          ]
        }
      },
      "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}"
    }
  ]
}