Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Chilkat.Http http = new Chilkat.Http();
bool success;
Chilkat.JsonObject queryParams = new Chilkat.JsonObject();
queryParams.UpdateString("start_hr","1991-02-02T07:22:34.204Z");
queryParams.UpdateString("end_hr","1991-02-02T07:22:34.204Z");
http.SetRequestHeader("Accept","application/json;datetime-format=rfc3339");
Chilkat.HttpResponse resp = http.QuickRequestParams("GET","https://api.app.ddog-gov.com/api/v1/usage/logs-by-retention",queryParams);
if (http.LastMethodSuccess == false) {
Debug.WriteLine(http.LastErrorText);
return;
}
Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);
Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;
Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());
int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
Debug.WriteLine("Response Header:");
Debug.WriteLine(resp.Header);
Debug.WriteLine("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "usage": [
// {
// "indexed_events_count": -19100091,
// "live_indexed_events_count": 86823319,
// "org_name": "laboris consequat elit",
// "public_id": "eiusmod sunt",
// "rehydrated_indexed_events_count": -3866440,
// "retention": "consequat irure proident sunt"
// },
// {
// "indexed_events_count": 16211658,
// "live_indexed_events_count": 70559803,
// "org_name": "et non ex",
// "public_id": "quis dolor officia aute nisi",
// "rehydrated_indexed_events_count": -6567363,
// "retention": "amet nisi laboris"
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
int indexed_events_count;
int live_indexed_events_count;
string org_name;
string public_id;
int rehydrated_indexed_events_count;
string retention;
int i = 0;
int count_i = jResp.SizeOfArray("usage");
while (i < count_i) {
jResp.I = i;
indexed_events_count = jResp.IntOf("usage[i].indexed_events_count");
live_indexed_events_count = jResp.IntOf("usage[i].live_indexed_events_count");
org_name = jResp.StringOf("usage[i].org_name");
public_id = jResp.StringOf("usage[i].public_id");
rehydrated_indexed_events_count = jResp.IntOf("usage[i].rehydrated_indexed_events_count");
retention = jResp.StringOf("usage[i].retention");
i = i + 1;
}
Curl Command
curl -G -d "start_hr=1991-02-02T07%3A22%3A34.204Z"
-d "end_hr=1991-02-02T07%3A22%3A34.204Z"
-H "Accept: application/json;datetime-format=rfc3339"
https://api.app.ddog-gov.com/api/v1/usage/logs-by-retention
Postman Collection Item JSON
{
"name": "Get hourly logs usage by retention",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json;datetime-format=rfc3339"
}
],
"url": {
"raw": "{{baseUrl}}/api/v1/usage/logs-by-retention?start_hr=1991-02-02T07:22:34.204Z&end_hr=1991-02-02T07:22:34.204Z",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"usage",
"logs-by-retention"
],
"query": [
{
"key": "start_hr",
"value": "1991-02-02T07:22:34.204Z",
"description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
},
{
"key": "end_hr",
"value": "1991-02-02T07:22:34.204Z",
"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 indexed logs by retention period.\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). Refer to [Migrating from the V1 Hourly Usage APIs to V2](https://docs.datadoghq.com/account_management/guide/hourly-usage-migration/) for the associated migration guide."
},
"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/v1/usage/logs-by-retention?start_hr=1991-02-02T07:22:34.204Z&end_hr=1991-02-02T07:22:34.204Z",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"usage",
"logs-by-retention"
],
"query": [
{
"key": "start_hr",
"value": "1991-02-02T07:22:34.204Z",
"description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
},
{
"key": "end_hr",
"value": "1991-02-02T07:22:34.204Z",
"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 \"usage\": [\n {\n \"indexed_events_count\": -19100091,\n \"live_indexed_events_count\": 86823319,\n \"org_name\": \"laboris consequat elit\",\n \"public_id\": \"eiusmod sunt\",\n \"rehydrated_indexed_events_count\": -3866440,\n \"retention\": \"consequat irure proident sunt\"\n },\n {\n \"indexed_events_count\": 16211658,\n \"live_indexed_events_count\": 70559803,\n \"org_name\": \"et non ex\",\n \"public_id\": \"quis dolor officia aute nisi\",\n \"rehydrated_indexed_events_count\": -6567363,\n \"retention\": \"amet nisi laboris\"\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/v1/usage/logs-by-retention?start_hr=1991-02-02T07:22:34.204Z&end_hr=1991-02-02T07:22:34.204Z",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"usage",
"logs-by-retention"
],
"query": [
{
"key": "start_hr",
"value": "1991-02-02T07:22:34.204Z",
"description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
},
{
"key": "end_hr",
"value": "1991-02-02T07:22:34.204Z",
"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 \"Bad Request\",\n \"Bad Request\"\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/v1/usage/logs-by-retention?start_hr=1991-02-02T07:22:34.204Z&end_hr=1991-02-02T07:22:34.204Z",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"usage",
"logs-by-retention"
],
"query": [
{
"key": "start_hr",
"value": "1991-02-02T07:22:34.204Z",
"description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
},
{
"key": "end_hr",
"value": "1991-02-02T07:22:34.204Z",
"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 \"Bad Request\",\n \"Bad Request\"\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/v1/usage/logs-by-retention?start_hr=1991-02-02T07:22:34.204Z&end_hr=1991-02-02T07:22:34.204Z",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"usage",
"logs-by-retention"
],
"query": [
{
"key": "start_hr",
"value": "1991-02-02T07:22:34.204Z",
"description": "(Required) Datetime in ISO-8601 format, UTC, precise to hour: `[YYYY-MM-DDThh]` for usage beginning at this hour."
},
{
"key": "end_hr",
"value": "1991-02-02T07:22:34.204Z",
"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 \"Bad Request\",\n \"Bad Request\"\n ]\n}"
}
]
}