-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateAnnotation.java
More file actions
46 lines (42 loc) · 1.99 KB
/
CreateAnnotation.java
File metadata and controls
46 lines (42 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Create an annotation returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.AnnotationsApi;
import com.datadog.api.client.v2.model.AnnotationColor;
import com.datadog.api.client.v2.model.AnnotationCreateAttributes;
import com.datadog.api.client.v2.model.AnnotationCreateData;
import com.datadog.api.client.v2.model.AnnotationCreateRequest;
import com.datadog.api.client.v2.model.AnnotationKind;
import com.datadog.api.client.v2.model.AnnotationResponse;
import com.datadog.api.client.v2.model.AnnotationType;
import java.util.Collections;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setUnstableOperationEnabled("v2.createAnnotation", true);
AnnotationsApi apiInstance = new AnnotationsApi(defaultClient);
AnnotationCreateRequest body =
new AnnotationCreateRequest()
.data(
new AnnotationCreateData()
.attributes(
new AnnotationCreateAttributes()
.color(AnnotationColor.BLUE)
.description("Deployed v2.3.1 to production.")
.pageId("dashboard:abc-def-xyz")
.startTime(1704067200000L)
.type(AnnotationKind.POINT_IN_TIME)
.widgetIds(Collections.singletonList("1234567890")))
.type(AnnotationType.ANNOTATION));
try {
AnnotationResponse result = apiInstance.createAnnotation(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AnnotationsApi#createAnnotation");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}