Chilkat Online Tools

DataFlex / Datadog API Collection / Get hourly usage for Lambda traced invocations

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 sOrg_name
    String sProduct_family
    String sPublic_id
    String sRegion
    String sUsage_type
    String sId
    String sV_type
    Integer j
    Integer iCount_j
    String sTimestamp
    String sValue
    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

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateString Of hoQueryParams "start_hr" "<dateTime>" To iSuccess
    Get ComUpdateString Of hoQueryParams "end_hr" "<dateTime>" To iSuccess

    Send ComSetRequestHeader To hoHttp "Accept" "application/json;datetime-format=rfc3339"

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

    // {
    //   "data": [
    //     {
    //       "attributes": {
    //         "org_name": "<string>",
    //         "product_family": "<string>",
    //         "public_id": "<string>",
    //         "region": "<string>",
    //         "timeseries": [
    //           {
    //             "timestamp": "<dateTime>",
    //             "value": "<long>"
    //           },
    //           {
    //             "timestamp": "<dateTime>",
    //             "value": "<long>"
    //           }
    //         ],
    //         "usage_type": "observability_pipelines_bytes_processed"
    //       },
    //       "id": "<string>",
    //       "type": "usage_timeseries"
    //     },
    //     {
    //       "attributes": {
    //         "org_name": "<string>",
    //         "product_family": "<string>",
    //         "public_id": "<string>",
    //         "region": "<string>",
    //         "timeseries": [
    //           {
    //             "timestamp": "<dateTime>",
    //             "value": "<long>"
    //           },
    //           {
    //             "timestamp": "<dateTime>",
    //             "value": "<long>"
    //           }
    //         ],
    //         "usage_type": "lambda_traced_invocations_count"
    //       },
    //       "id": "<string>",
    //       "type": "usage_timeseries"
    //     }
    //   ]
    // }

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

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "data" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "data[i].attributes.org_name" To sOrg_name
        Get ComStringOf Of hoJResp "data[i].attributes.product_family" To sProduct_family
        Get ComStringOf Of hoJResp "data[i].attributes.public_id" To sPublic_id
        Get ComStringOf Of hoJResp "data[i].attributes.region" To sRegion
        Get ComStringOf Of hoJResp "data[i].attributes.usage_type" To sUsage_type
        Get ComStringOf Of hoJResp "data[i].id" To sId
        Get ComStringOf Of hoJResp "data[i].type" To sV_type
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "data[i].attributes.timeseries" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "data[i].attributes.timeseries[j].timestamp" To sTimestamp
            Get ComStringOf Of hoJResp "data[i].attributes.timeseries[j].value" To sValue
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -G -d "start_hr=%3CdateTime%3E"
	-d "end_hr=%3CdateTime%3E"
	-H "Accept: application/json;datetime-format=rfc3339"
https://api.app.ddog-gov.com/api/v2/usage/lambda_traced_invocations

Postman Collection Item JSON

{
  "name": "Get hourly usage for Lambda traced invocations",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json;datetime-format=rfc3339"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/usage/lambda_traced_invocations?start_hr=<dateTime>&end_hr=<dateTime>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "usage",
        "lambda_traced_invocations"
      ],
      "query": [
        {
          "key": "start_hr",
          "value": "<dateTime>",
          "description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
        },
        {
          "key": "end_hr",
          "value": "<dateTime>",
          "description": "Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage ending\n**before** this hour."
        }
      ]
    },
    "description": "Get hourly usage for lambda traced invocations.\n**Note:** hourly usage data for all products is now available in the [Get hourly usage by product family API](https://docs.datadoghq.com/api/latest/usage-metering/#get-hourly-usage-by-product-family)"
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json;datetime-format=rfc3339"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/usage/lambda_traced_invocations?start_hr=<dateTime>&end_hr=<dateTime>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "usage",
            "lambda_traced_invocations"
          ],
          "query": [
            {
              "key": "start_hr",
              "value": "<dateTime>",
              "description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
            },
            {
              "key": "end_hr",
              "value": "<dateTime>",
              "description": "Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage ending\n**before** this hour."
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json;datetime-format=rfc3339"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": [\n    {\n      \"attributes\": {\n        \"org_name\": \"<string>\",\n        \"product_family\": \"<string>\",\n        \"public_id\": \"<string>\",\n        \"region\": \"<string>\",\n        \"timeseries\": [\n          {\n            \"timestamp\": \"<dateTime>\",\n            \"value\": \"<long>\"\n          },\n          {\n            \"timestamp\": \"<dateTime>\",\n            \"value\": \"<long>\"\n          }\n        ],\n        \"usage_type\": \"observability_pipelines_bytes_processed\"\n      },\n      \"id\": \"<string>\",\n      \"type\": \"usage_timeseries\"\n    },\n    {\n      \"attributes\": {\n        \"org_name\": \"<string>\",\n        \"product_family\": \"<string>\",\n        \"public_id\": \"<string>\",\n        \"region\": \"<string>\",\n        \"timeseries\": [\n          {\n            \"timestamp\": \"<dateTime>\",\n            \"value\": \"<long>\"\n          },\n          {\n            \"timestamp\": \"<dateTime>\",\n            \"value\": \"<long>\"\n          }\n        ],\n        \"usage_type\": \"lambda_traced_invocations_count\"\n      },\n      \"id\": \"<string>\",\n      \"type\": \"usage_timeseries\"\n    }\n  ]\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json;datetime-format=rfc3339"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/usage/lambda_traced_invocations?start_hr=<dateTime>&end_hr=<dateTime>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "usage",
            "lambda_traced_invocations"
          ],
          "query": [
            {
              "key": "start_hr",
              "value": "<dateTime>",
              "description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
            },
            {
              "key": "end_hr",
              "value": "<dateTime>",
              "description": "Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage ending\n**before** this hour."
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json;datetime-format=rfc3339"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Forbidden - User is not authorized",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json;datetime-format=rfc3339"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/usage/lambda_traced_invocations?start_hr=<dateTime>&end_hr=<dateTime>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "usage",
            "lambda_traced_invocations"
          ],
          "query": [
            {
              "key": "start_hr",
              "value": "<dateTime>",
              "description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
            },
            {
              "key": "end_hr",
              "value": "<dateTime>",
              "description": "Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage ending\n**before** this hour."
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json;datetime-format=rfc3339"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Too many requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json;datetime-format=rfc3339"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/usage/lambda_traced_invocations?start_hr=<dateTime>&end_hr=<dateTime>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "usage",
            "lambda_traced_invocations"
          ],
          "query": [
            {
              "key": "start_hr",
              "value": "<dateTime>",
              "description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
            },
            {
              "key": "end_hr",
              "value": "<dateTime>",
              "description": "Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage ending\n**before** this hour."
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json;datetime-format=rfc3339"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}