Create a graph snapshot
https://api.datadoghq.com/api/v2/snapshothttps://api.us3.datadoghq.com/api/v2/snapshothttps://api.us5.datadoghq.com/api/v2/snapshothttps://api.datadoghq.eu/api/v2/snapshothttps://api.ap1.datadoghq.com/api/v2/snapshothttps://api.ap2.datadoghq.com/api/v2/snapshothttps://api.uk1.datadoghq.com/api/v2/snapshothttps://api.ddog-gov.com/api/v2/snapshothttps://api.us2.ddog-gov.com/api/v2/snapshotPrésentation
Create a snapshot of a graph widget. The snapshot is rendered asynchronously; the returned URL can be polled until the image is ready.
Requête
Body Data (required)
data [required]Data envelope for snapshot creation.
attributes [required]Attributes for snapshot creation.
additional_configAdditional configuration options for snapshot creation.
template_variablesList of template variable definitions for snapshot rendering.
name [required]The template variable name.
prefix [required]The tag prefix associated with the template variable. For example, a prefix of host with a value of web-server-1 scopes the snapshot to host:web-server-1.
values [required]The list of scoped values for this template variable.
timeseries_legend_typeThe legend display type for timeseries widgets. A value of none hides the legend entirely; omitting the field lets the frontend choose automatically.
compact, expanded, nonetimezone_offset_minutesTimezone offset in minutes from UTC. Positive values are west of UTC (for example, 300 for UTC-5). Use 0 for UTC.
end [required]End of the time window for the snapshot, in milliseconds since Unix epoch.
heightThe height of the rendered snapshot in pixels.
is_authenticatedWhether the snapshot requires authentication to view. Authenticated snapshots are scoped to the creating organization.
start [required]Start of the time window for the snapshot, in milliseconds since Unix epoch.
ttlThe time-to-live for the snapshot. This value corresponds to storage lifecycle policies that automatically delete the snapshot after the specified period.
30d, 60d, 90d, 1y, 2y, infwidget_definition [required]The widget definition to render as a snapshot. Must include a valid type field and non-empty requests array.
widthThe width of the rendered snapshot in pixels.
type [required]The type identifier for snapshot creation resources.
create_snapshot{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}Réponse
OK
Response body for a snapshot creation request.
data [required]Data envelope for the snapshot creation response.
attributes [required]Attributes of the created snapshot.
url [required]The URL to access the rendered snapshot image.
id [required]The unique identifier of the created snapshot.
type [required]The type identifier for snapshot creation resources.
create_snapshot{
"data": {
"attributes": {
"url": "https://app.datadoghq.com/api/v2/snapshot/view/public/60d/00000000-0000-0000-0000-000000000000/1692464400000-12345678-1234-5678-9abc-def123456789.png"
},
"id": "12345678-1234-5678-9abc-def123456789",
"type": "create_snapshot"
}
}Bad Request
API error response.
errors [required]A list of errors.
detailA human-readable explanation specific to this occurrence of the error.
metaNon-standard meta-information about the error
sourceReferences to the source of the error.
headerA string indicating the name of a single request header which caused the error.
parameterA string indicating which URI query parameter caused the error.
pointerA JSON pointer to the value in the request document that caused the error.
statusStatus code of the response.
titleShort human-readable summary of the error.
{
"errors": [
{
"detail": "Missing required attribute in body",
"meta": {},
"source": {
"header": "Authorization",
"parameter": "limit",
"pointer": "/data/attributes/title"
},
"status": "400",
"title": "Bad Request"
}
]
}Unauthorized
API error response.
errors [required]A list of errors.
detailA human-readable explanation specific to this occurrence of the error.
metaNon-standard meta-information about the error
sourceReferences to the source of the error.
headerA string indicating the name of a single request header which caused the error.
parameterA string indicating which URI query parameter caused the error.
pointerA JSON pointer to the value in the request document that caused the error.
statusStatus code of the response.
titleShort human-readable summary of the error.
{
"errors": [
{
"detail": "Missing required attribute in body",
"meta": {},
"source": {
"header": "Authorization",
"parameter": "limit",
"pointer": "/data/attributes/title"
},
"status": "400",
"title": "Bad Request"
}
]
}Forbidden
API error response.
errors [required]A list of errors.
detailA human-readable explanation specific to this occurrence of the error.
metaNon-standard meta-information about the error
sourceReferences to the source of the error.
headerA string indicating the name of a single request header which caused the error.
parameterA string indicating which URI query parameter caused the error.
pointerA JSON pointer to the value in the request document that caused the error.
statusStatus code of the response.
titleShort human-readable summary of the error.
{
"errors": [
{
"detail": "Missing required attribute in body",
"meta": {},
"source": {
"header": "Authorization",
"parameter": "limit",
"pointer": "/data/attributes/title"
},
"status": "400",
"title": "Bad Request"
}
]
}Not Found
API error response.
errors [required]A list of errors.
detailA human-readable explanation specific to this occurrence of the error.
metaNon-standard meta-information about the error
sourceReferences to the source of the error.
headerA string indicating the name of a single request header which caused the error.
parameterA string indicating which URI query parameter caused the error.
pointerA JSON pointer to the value in the request document that caused the error.
statusStatus code of the response.
titleShort human-readable summary of the error.
{
"errors": [
{
"detail": "Missing required attribute in body",
"meta": {},
"source": {
"header": "Authorization",
"parameter": "limit",
"pointer": "/data/attributes/title"
},
"status": "400",
"title": "Bad Request"
}
]
}Too many requests
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Exemple de code
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/snapshot" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"additional_config": {
"template_variables": [
{
"name": "host",
"prefix": "host",
"values": [
"web-server-1",
"web-server-2"
]
}
],
"timeseries_legend_type": "expanded",
"timezone_offset_minutes": 300
},
"end": 1692464800000,
"height": 185,
"is_authenticated": false,
"start": 1692464000000,
"ttl": "60d",
"widget_definition": {
"requests": [
{
"q": "avg:system.cpu.user{*}"
}
],
"type": "timeseries"
},
"width": 300
},
"type": "create_snapshot"
}
}
EOF// Create a graph snapshot returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)
func main() {
body := datadogV2.CreateSnapshotRequest{
Data: datadogV2.CreateSnapshotDataRequest{
Attributes: datadogV2.CreateSnapshotDataAttributesRequest{
AdditionalConfig: &datadogV2.CreateSnapshotAdditionalConfig{
TemplateVariables: []datadogV2.CreateSnapshotTemplateVariable{
{
Name: "host",
Prefix: "host",
Values: []string{
"web-server-1",
"web-server-2",
},
},
},
TimeseriesLegendType: datadogV2.CREATESNAPSHOTTIMESERIESLEGENDTYPE_EXPANDED.Ptr(),
TimezoneOffsetMinutes: datadog.PtrInt64(300),
},
End: 1692464800000,
Height: datadog.PtrInt64(185),
IsAuthenticated: datadog.PtrBool(false),
Start: 1692464000000,
Ttl: datadogV2.CREATESNAPSHOTTTL_SIXTY_DAYS.Ptr(),
WidgetDefinition: map[string]interface{}{
"requests": "[{'q': 'avg:system.cpu.user{*}'}]",
"type": "timeseries",
},
Width: datadog.PtrInt64(300),
},
Type: datadogV2.CREATESNAPSHOTTYPE_CREATE_SNAPSHOT,
},
}
ctx := datadog.NewDefaultContext(context.Background())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
configuration := datadog.NewConfiguration()
configuration.SetUnstableOperationEnabled("v2.CreateSnapshot", true)
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewReportingAndSharingApi(apiClient)
resp, r, err := api.CreateSnapshot(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `ReportingAndSharingApi.CreateSnapshot`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `ReportingAndSharingApi.CreateSnapshot`:\n%s\n", responseContent)
}
Instructions
First install the library and its dependencies and then save the example to main.go and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"// Create a graph snapshot returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.ReportingAndSharingApi;
import com.datadog.api.client.v2.model.CreateSnapshotAdditionalConfig;
import com.datadog.api.client.v2.model.CreateSnapshotDataAttributesRequest;
import com.datadog.api.client.v2.model.CreateSnapshotDataRequest;
import com.datadog.api.client.v2.model.CreateSnapshotRequest;
import com.datadog.api.client.v2.model.CreateSnapshotResponse;
import com.datadog.api.client.v2.model.CreateSnapshotTTL;
import com.datadog.api.client.v2.model.CreateSnapshotTemplateVariable;
import com.datadog.api.client.v2.model.CreateSnapshotTimeseriesLegendType;
import com.datadog.api.client.v2.model.CreateSnapshotType;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
defaultClient.setUnstableOperationEnabled("v2.createSnapshot", true);
ReportingAndSharingApi apiInstance = new ReportingAndSharingApi(defaultClient);
CreateSnapshotRequest body =
new CreateSnapshotRequest()
.data(
new CreateSnapshotDataRequest()
.attributes(
new CreateSnapshotDataAttributesRequest()
.additionalConfig(
new CreateSnapshotAdditionalConfig()
.templateVariables(
Collections.singletonList(
new CreateSnapshotTemplateVariable()
.name("host")
.prefix("host")
.values(
Arrays.asList("web-server-1", "web-server-2"))))
.timeseriesLegendType(
CreateSnapshotTimeseriesLegendType.EXPANDED)
.timezoneOffsetMinutes(300L))
.end(1692464800000L)
.height(185L)
.isAuthenticated(false)
.start(1692464000000L)
.ttl(CreateSnapshotTTL.SIXTY_DAYS)
.widgetDefinition(
Map.ofEntries(
Map.entry("requests", "[{'q': 'avg:system.cpu.user{*}'}]"),
Map.entry("type", "timeseries")))
.width(300L))
.type(CreateSnapshotType.CREATE_SNAPSHOT));
try {
CreateSnapshotResponse result = apiInstance.createSnapshot(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ReportingAndSharingApi#createSnapshot");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Instructions
First install the library and its dependencies and then save the example to Example.java and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java""""
Create a graph snapshot returns "OK" response
"""
from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.reporting_and_sharing_api import ReportingAndSharingApi
from datadog_api_client.v2.model.create_snapshot_additional_config import CreateSnapshotAdditionalConfig
from datadog_api_client.v2.model.create_snapshot_data_attributes_request import CreateSnapshotDataAttributesRequest
from datadog_api_client.v2.model.create_snapshot_data_request import CreateSnapshotDataRequest
from datadog_api_client.v2.model.create_snapshot_request import CreateSnapshotRequest
from datadog_api_client.v2.model.create_snapshot_template_variable import CreateSnapshotTemplateVariable
from datadog_api_client.v2.model.create_snapshot_timeseries_legend_type import CreateSnapshotTimeseriesLegendType
from datadog_api_client.v2.model.create_snapshot_ttl import CreateSnapshotTTL
from datadog_api_client.v2.model.create_snapshot_type import CreateSnapshotType
body = CreateSnapshotRequest(
data=CreateSnapshotDataRequest(
attributes=CreateSnapshotDataAttributesRequest(
additional_config=CreateSnapshotAdditionalConfig(
template_variables=[
CreateSnapshotTemplateVariable(
name="host",
prefix="host",
values=[
"web-server-1",
"web-server-2",
],
),
],
timeseries_legend_type=CreateSnapshotTimeseriesLegendType.EXPANDED,
timezone_offset_minutes=300,
),
end=1692464800000,
height=185,
is_authenticated=False,
start=1692464000000,
ttl=CreateSnapshotTTL.SIXTY_DAYS,
widget_definition=dict([("requests", "[{'q': 'avg:system.cpu.user{*}'}]"), ("type", "timeseries")]),
width=300,
),
type=CreateSnapshotType.CREATE_SNAPSHOT,
),
)
configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
configuration.unstable_operations["create_snapshot"] = True
with ApiClient(configuration) as api_client:
api_instance = ReportingAndSharingApi(api_client)
response = api_instance.create_snapshot(body=body)
print(response)
Instructions
First install the library and its dependencies and then save the example to example.py and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"# Create a graph snapshot returns "OK" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
config.unstable_operations["v2.create_snapshot".to_sym] = true
end
api_instance = DatadogAPIClient::V2::ReportingAndSharingAPI.new
body = DatadogAPIClient::V2::CreateSnapshotRequest.new({
data: DatadogAPIClient::V2::CreateSnapshotDataRequest.new({
attributes: DatadogAPIClient::V2::CreateSnapshotDataAttributesRequest.new({
additional_config: DatadogAPIClient::V2::CreateSnapshotAdditionalConfig.new({
template_variables: [
DatadogAPIClient::V2::CreateSnapshotTemplateVariable.new({
name: "host",
prefix: "host",
values: [
"web-server-1",
"web-server-2",
],
}),
],
timeseries_legend_type: DatadogAPIClient::V2::CreateSnapshotTimeseriesLegendType::EXPANDED,
timezone_offset_minutes: 300,
}),
_end: 1692464800000,
height: 185,
is_authenticated: false,
start: 1692464000000,
ttl: DatadogAPIClient::V2::CreateSnapshotTTL::SIXTY_DAYS,
widget_definition: {
"requests": "[{'q': 'avg:system.cpu.user{*}'}]", "type": "timeseries",
},
width: 300,
}),
type: DatadogAPIClient::V2::CreateSnapshotType::CREATE_SNAPSHOT,
}),
})
p api_instance.create_snapshot(body)
Instructions
First install the library and its dependencies and then save the example to example.rb and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"// Create a graph snapshot returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_reporting_and_sharing::ReportingAndSharingAPI;
use datadog_api_client::datadogV2::model::CreateSnapshotAdditionalConfig;
use datadog_api_client::datadogV2::model::CreateSnapshotDataAttributesRequest;
use datadog_api_client::datadogV2::model::CreateSnapshotDataRequest;
use datadog_api_client::datadogV2::model::CreateSnapshotRequest;
use datadog_api_client::datadogV2::model::CreateSnapshotTTL;
use datadog_api_client::datadogV2::model::CreateSnapshotTemplateVariable;
use datadog_api_client::datadogV2::model::CreateSnapshotTimeseriesLegendType;
use datadog_api_client::datadogV2::model::CreateSnapshotType;
use serde_json::Value;
use std::collections::BTreeMap;
#[tokio::main]
async fn main() {
let body = CreateSnapshotRequest::new(CreateSnapshotDataRequest::new(
CreateSnapshotDataAttributesRequest::new(
1692464800000,
1692464000000,
BTreeMap::from([("type".to_string(), Value::from("timeseries"))]),
)
.additional_config(
CreateSnapshotAdditionalConfig::new()
.template_variables(vec![CreateSnapshotTemplateVariable::new(
"host".to_string(),
"host".to_string(),
vec!["web-server-1".to_string(), "web-server-2".to_string()],
)])
.timeseries_legend_type(CreateSnapshotTimeseriesLegendType::EXPANDED)
.timezone_offset_minutes(300),
)
.height(185)
.is_authenticated(false)
.ttl(CreateSnapshotTTL::SIXTY_DAYS)
.width(300),
CreateSnapshotType::CREATE_SNAPSHOT,
));
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.create_snapshot", true);
let api = ReportingAndSharingAPI::with_config(configuration);
let resp = api.create_snapshot(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
Instructions
First install the library and its dependencies and then save the example to src/main.rs and run following commands:
DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us3.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us5.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="datadoghq.eu" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ap1.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ap2.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="uk1.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us2.ddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run/**
* Create a graph snapshot returns "OK" response
*/
import { client, v2 } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration({
authMethods: {
AuthZ: {
accessToken: process.env.DD_BEARER_TOKEN as string,
},
},
});
configuration.unstableOperations["v2.createSnapshot"] = true;
const apiInstance = new v2.ReportingAndSharingApi(configuration);
const params: v2.ReportingAndSharingApiCreateSnapshotRequest = {
body: {
data: {
attributes: {
additionalConfig: {
templateVariables: [
{
name: "host",
prefix: "host",
values: ["web-server-1", "web-server-2"],
},
],
timeseriesLegendType: "expanded",
timezoneOffsetMinutes: 300,
},
end: 1692464800000,
height: 185,
isAuthenticated: false,
start: 1692464000000,
ttl: "60d",
widgetDefinition: {
requests: "[{'q': 'avg:system.cpu.user{*}'}]",
type: "timeseries",
},
width: 300,
},
type: "create_snapshot",
},
},
};
apiInstance
.createSnapshot(params)
.then((data: v2.CreateSnapshotResponse) => {
console.log(
"API called successfully. Returned data: " + JSON.stringify(data)
);
})
.catch((error: any) => console.error(error));
Instructions
First install the library and its dependencies and then save the example to example.ts and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"