Chilkat Online Tools

DataFlex / Datadog API Collection / Take graph snapshots

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sGraph_def
    String sMetric_query
    String sSnapshot_url
    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

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateString Of hoQueryParams "metric_query" "tempor Ut sed velit" To iSuccess
    Get ComUpdateInt Of hoQueryParams "start" -62147425 To iSuccess
    Get ComUpdateInt Of hoQueryParams "end" -62147425 To iSuccess
    Get ComUpdateString Of hoQueryParams "event_query" "tempor Ut sed velit" To iSuccess
    Get ComUpdateString Of hoQueryParams "graph_def" "tempor Ut sed velit" To iSuccess
    Get ComUpdateString Of hoQueryParams "title" "tempor Ut sed velit" To iSuccess
    Get ComUpdateInt Of hoQueryParams "height" -62147425 To iSuccess
    Get ComUpdateInt Of hoQueryParams "width" -62147425 To iSuccess

    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v1/graph/snapshot" vQueryParams 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)

    // {
    //   "graph_def": "aliquip pariatur non",
    //   "metric_query": "sit veniam dolore Ut",
    //   "snapshot_url": "https://app.datadoghq.com/s/f12345678/aaa-bbb-ccc"
    // }

    // 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 "graph_def" To sGraph_def
    Get ComStringOf Of hoJResp "metric_query" To sMetric_query
    Get ComStringOf Of hoJResp "snapshot_url" To sSnapshot_url


End_Procedure

Curl Command

curl -G -d "metric_query=tempor%20Ut%20sed%20velit"
	-d "start=-62147425"
	-d "end=-62147425"
	-d "event_query=tempor%20Ut%20sed%20velit"
	-d "graph_def=tempor%20Ut%20sed%20velit"
	-d "title=tempor%20Ut%20sed%20velit"
	-d "height=-62147425"
	-d "width=-62147425"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v1/graph/snapshot

Postman Collection Item JSON

{
  "name": "Take graph snapshots",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v1/graph/snapshot?metric_query=tempor Ut sed velit&start=-62147425&end=-62147425&event_query=tempor Ut sed velit&graph_def=tempor Ut sed velit&title=tempor Ut sed velit&height=-62147425&width=-62147425",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v1",
        "graph",
        "snapshot"
      ],
      "query": [
        {
          "key": "metric_query",
          "value": "tempor Ut sed velit",
          "description": "The metric query."
        },
        {
          "key": "start",
          "value": "-62147425",
          "description": "(Required) The POSIX timestamp of the start of the query in seconds."
        },
        {
          "key": "end",
          "value": "-62147425",
          "description": "(Required) The POSIX timestamp of the end of the query in seconds."
        },
        {
          "key": "event_query",
          "value": "tempor Ut sed velit",
          "description": "A query that adds event bands to the graph."
        },
        {
          "key": "graph_def",
          "value": "tempor Ut sed velit",
          "description": "A JSON document defining the graph. `graph_def` can be used instead of `metric_query`.\nThe JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar)\nand should be formatted to a single line then URL encoded."
        },
        {
          "key": "title",
          "value": "tempor Ut sed velit",
          "description": "A title for the graph. If no title is specified, the graph does not have a title."
        },
        {
          "key": "height",
          "value": "-62147425",
          "description": "The height of the graph. If no height is specified, the graph's original height is used."
        },
        {
          "key": "width",
          "value": "-62147425",
          "description": "The width of the graph. If no width is specified, the graph's original width is used."
        }
      ]
    },
    "description": "Take graph snapshots.\n**Note**: When a snapshot is created, there is some delay before it is available."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/snapshot?metric_query=tempor Ut sed velit&start=-62147425&end=-62147425&event_query=tempor Ut sed velit&graph_def=tempor Ut sed velit&title=tempor Ut sed velit&height=-62147425&width=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "snapshot"
          ],
          "query": [
            {
              "key": "metric_query",
              "value": "tempor Ut sed velit",
              "description": "The metric query."
            },
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the start of the query in seconds."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the end of the query in seconds."
            },
            {
              "key": "event_query",
              "value": "tempor Ut sed velit",
              "description": "A query that adds event bands to the graph."
            },
            {
              "key": "graph_def",
              "value": "tempor Ut sed velit",
              "description": "A JSON document defining the graph. `graph_def` can be used instead of `metric_query`.\nThe JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar)\nand should be formatted to a single line then URL encoded."
            },
            {
              "key": "title",
              "value": "tempor Ut sed velit",
              "description": "A title for the graph. If no title is specified, the graph does not have a title."
            },
            {
              "key": "height",
              "value": "-62147425",
              "description": "The height of the graph. If no height is specified, the graph's original height is used."
            },
            {
              "key": "width",
              "value": "-62147425",
              "description": "The width of the graph. If no width is specified, the graph's original width is used."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"graph_def\": \"aliquip pariatur non\",\n  \"metric_query\": \"sit veniam dolore Ut\",\n  \"snapshot_url\": \"https://app.datadoghq.com/s/f12345678/aaa-bbb-ccc\"\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/snapshot?metric_query=tempor Ut sed velit&start=-62147425&end=-62147425&event_query=tempor Ut sed velit&graph_def=tempor Ut sed velit&title=tempor Ut sed velit&height=-62147425&width=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "snapshot"
          ],
          "query": [
            {
              "key": "metric_query",
              "value": "tempor Ut sed velit",
              "description": "The metric query."
            },
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the start of the query in seconds."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the end of the query in seconds."
            },
            {
              "key": "event_query",
              "value": "tempor Ut sed velit",
              "description": "A query that adds event bands to the graph."
            },
            {
              "key": "graph_def",
              "value": "tempor Ut sed velit",
              "description": "A JSON document defining the graph. `graph_def` can be used instead of `metric_query`.\nThe JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar)\nand should be formatted to a single line then URL encoded."
            },
            {
              "key": "title",
              "value": "tempor Ut sed velit",
              "description": "A title for the graph. If no title is specified, the graph does not have a title."
            },
            {
              "key": "height",
              "value": "-62147425",
              "description": "The height of the graph. If no height is specified, the graph's original height is used."
            },
            {
              "key": "width",
              "value": "-62147425",
              "description": "The width of the graph. If no width is specified, the graph's original width is used."
            }
          ]
        }
      },
      "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": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/snapshot?metric_query=tempor Ut sed velit&start=-62147425&end=-62147425&event_query=tempor Ut sed velit&graph_def=tempor Ut sed velit&title=tempor Ut sed velit&height=-62147425&width=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "snapshot"
          ],
          "query": [
            {
              "key": "metric_query",
              "value": "tempor Ut sed velit",
              "description": "The metric query."
            },
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the start of the query in seconds."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the end of the query in seconds."
            },
            {
              "key": "event_query",
              "value": "tempor Ut sed velit",
              "description": "A query that adds event bands to the graph."
            },
            {
              "key": "graph_def",
              "value": "tempor Ut sed velit",
              "description": "A JSON document defining the graph. `graph_def` can be used instead of `metric_query`.\nThe JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar)\nand should be formatted to a single line then URL encoded."
            },
            {
              "key": "title",
              "value": "tempor Ut sed velit",
              "description": "A title for the graph. If no title is specified, the graph does not have a title."
            },
            {
              "key": "height",
              "value": "-62147425",
              "description": "The height of the graph. If no height is specified, the graph's original height is used."
            },
            {
              "key": "width",
              "value": "-62147425",
              "description": "The width of the graph. If no width is specified, the graph's original width is used."
            }
          ]
        }
      },
      "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": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v1/graph/snapshot?metric_query=tempor Ut sed velit&start=-62147425&end=-62147425&event_query=tempor Ut sed velit&graph_def=tempor Ut sed velit&title=tempor Ut sed velit&height=-62147425&width=-62147425",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v1",
            "graph",
            "snapshot"
          ],
          "query": [
            {
              "key": "metric_query",
              "value": "tempor Ut sed velit",
              "description": "The metric query."
            },
            {
              "key": "start",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the start of the query in seconds."
            },
            {
              "key": "end",
              "value": "-62147425",
              "description": "(Required) The POSIX timestamp of the end of the query in seconds."
            },
            {
              "key": "event_query",
              "value": "tempor Ut sed velit",
              "description": "A query that adds event bands to the graph."
            },
            {
              "key": "graph_def",
              "value": "tempor Ut sed velit",
              "description": "A JSON document defining the graph. `graph_def` can be used instead of `metric_query`.\nThe JSON document uses the [grammar defined here](https://docs.datadoghq.com/graphing/graphing_json/#grammar)\nand should be formatted to a single line then URL encoded."
            },
            {
              "key": "title",
              "value": "tempor Ut sed velit",
              "description": "A title for the graph. If no title is specified, the graph does not have a title."
            },
            {
              "key": "height",
              "value": "-62147425",
              "description": "The height of the graph. If no height is specified, the graph's original height is used."
            },
            {
              "key": "width",
              "value": "-62147425",
              "description": "The width of the graph. If no width is specified, the graph's original width is used."
            }
          ]
        }
      },
      "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}"
    }
  ]
}