com.datadog.api.client.v2.api.EventsApi Maven / Gradle / Ivy
package com.datadog.api.client.v2.api;
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.ApiResponse;
import com.datadog.api.client.PaginationIterable;
import com.datadog.api.client.Pair;
import com.datadog.api.client.v2.model.EventCreateRequestPayload;
import com.datadog.api.client.v2.model.EventCreateResponsePayload;
import com.datadog.api.client.v2.model.EventResponse;
import com.datadog.api.client.v2.model.EventsListRequest;
import com.datadog.api.client.v2.model.EventsListResponse;
import com.datadog.api.client.v2.model.EventsRequestPage;
import com.datadog.api.client.v2.model.EventsSort;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.core.GenericType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@jakarta.annotation.Generated(
value = "https://github.com/DataDog/datadog-api-client-java/blob/master/.generator")
public class EventsApi {
private ApiClient apiClient;
public EventsApi() {
this(ApiClient.getDefaultApiClient());
}
public EventsApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Get the API client.
*
* @return API client
*/
public ApiClient getApiClient() {
return apiClient;
}
/**
* Set the API client.
*
* @param apiClient an instance of API client
*/
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Post an event.
*
* See {@link #createEventWithHttpInfo}.
*
* @param body Event request object (required)
* @return EventCreateResponsePayload
* @throws ApiException if fails to make API call
*/
public EventCreateResponsePayload createEvent(EventCreateRequestPayload body)
throws ApiException {
return createEventWithHttpInfo(body).getData();
}
/**
* Post an event.
*
*
See {@link #createEventWithHttpInfoAsync}.
*
* @param body Event request object (required)
* @return CompletableFuture<EventCreateResponsePayload>
*/
public CompletableFuture createEventAsync(
EventCreateRequestPayload body) {
return createEventWithHttpInfoAsync(body)
.thenApply(
response -> {
return response.getData();
});
}
/**
* This endpoint allows you to post events.
*
* ✅ Only events with the change
category are in General
* Availability. See Change Tracking for
* more details.
*
*
❌ For use cases involving other event categories, please use the V1 endpoint.
*
* @param body Event request object (required)
* @return ApiResponse<EventCreateResponsePayload>
* @throws ApiException if fails to make API call
* @http.response.details
*
* Response details
* Status Code Description Response Headers
* 200 OK -
* 400 Bad request -
* 403 Forbidden -
* 429 Too many requests -
*
*/
public ApiResponse createEventWithHttpInfo(
EventCreateRequestPayload body) throws ApiException {
Object localVarPostBody = body;
// verify the required parameter 'body' is set
if (body == null) {
throw new ApiException(400, "Missing the required parameter 'body' when calling createEvent");
}
// create path and map variables
String localVarPath = "/api/v2/events";
Map localVarHeaderParams = new HashMap();
Invocation.Builder builder =
apiClient.createBuilder(
"v2.EventsApi.createEvent",
localVarPath,
new ArrayList(),
localVarHeaderParams,
new HashMap(),
new String[] {"application/json"},
new String[] {"apiKeyAuth", "appKeyAuth"});
return apiClient.invokeAPI(
"POST",
builder,
localVarHeaderParams,
new String[] {"application/json"},
localVarPostBody,
new HashMap(),
false,
new GenericType() {});
}
/**
* Post an event.
*
* See {@link #createEventWithHttpInfo}.
*
* @param body Event request object (required)
* @return CompletableFuture<ApiResponse<EventCreateResponsePayload>>
*/
public CompletableFuture> createEventWithHttpInfoAsync(
EventCreateRequestPayload body) {
Object localVarPostBody = body;
// verify the required parameter 'body' is set
if (body == null) {
CompletableFuture> result = new CompletableFuture<>();
result.completeExceptionally(
new ApiException(400, "Missing the required parameter 'body' when calling createEvent"));
return result;
}
// create path and map variables
String localVarPath = "/api/v2/events";
Map localVarHeaderParams = new HashMap();
Invocation.Builder builder;
try {
builder =
apiClient.createBuilder(
"v2.EventsApi.createEvent",
localVarPath,
new ArrayList(),
localVarHeaderParams,
new HashMap(),
new String[] {"application/json"},
new String[] {"apiKeyAuth", "appKeyAuth"});
} catch (ApiException ex) {
CompletableFuture> result = new CompletableFuture<>();
result.completeExceptionally(ex);
return result;
}
return apiClient.invokeAPIAsync(
"POST",
builder,
localVarHeaderParams,
new String[] {"application/json"},
localVarPostBody,
new HashMap(),
false,
new GenericType() {});
}
/** Manage optional parameters to listEvents. */
public static class ListEventsOptionalParameters {
private String filterQuery;
private String filterFrom;
private String filterTo;
private EventsSort sort;
private String pageCursor;
private Integer pageLimit;
/**
* Set filterQuery.
*
* @param filterQuery Search query following events syntax. (optional)
* @return ListEventsOptionalParameters
*/
public ListEventsOptionalParameters filterQuery(String filterQuery) {
this.filterQuery = filterQuery;
return this;
}
/**
* Set filterFrom.
*
* @param filterFrom Minimum timestamp for requested events, in milliseconds. (optional)
* @return ListEventsOptionalParameters
*/
public ListEventsOptionalParameters filterFrom(String filterFrom) {
this.filterFrom = filterFrom;
return this;
}
/**
* Set filterTo.
*
* @param filterTo Maximum timestamp for requested events, in milliseconds. (optional)
* @return ListEventsOptionalParameters
*/
public ListEventsOptionalParameters filterTo(String filterTo) {
this.filterTo = filterTo;
return this;
}
/**
* Set sort.
*
* @param sort Order of events in results. (optional)
* @return ListEventsOptionalParameters
*/
public ListEventsOptionalParameters sort(EventsSort sort) {
this.sort = sort;
return this;
}
/**
* Set pageCursor.
*
* @param pageCursor List following results with a cursor provided in the previous query.
* (optional)
* @return ListEventsOptionalParameters
*/
public ListEventsOptionalParameters pageCursor(String pageCursor) {
this.pageCursor = pageCursor;
return this;
}
/**
* Set pageLimit.
*
* @param pageLimit Maximum number of events in the response. (optional, default to 10)
* @return ListEventsOptionalParameters
*/
public ListEventsOptionalParameters pageLimit(Integer pageLimit) {
this.pageLimit = pageLimit;
return this;
}
}
/**
* Get a list of events.
*
* See {@link #listEventsWithHttpInfo}.
*
* @return EventsListResponse
* @throws ApiException if fails to make API call
*/
public EventsListResponse listEvents() throws ApiException {
return listEventsWithHttpInfo(new ListEventsOptionalParameters()).getData();
}
/**
* Get a list of events.
*
*
See {@link #listEventsWithHttpInfoAsync}.
*
* @return CompletableFuture<EventsListResponse>
*/
public CompletableFuture listEventsAsync() {
return listEventsWithHttpInfoAsync(new ListEventsOptionalParameters())
.thenApply(
response -> {
return response.getData();
});
}
/**
* Get a list of events.
*
* See {@link #listEventsWithHttpInfo}.
*
* @param parameters Optional parameters for the request.
* @return EventsListResponse
* @throws ApiException if fails to make API call
*/
public EventsListResponse listEvents(ListEventsOptionalParameters parameters)
throws ApiException {
return listEventsWithHttpInfo(parameters).getData();
}
/**
* Get a list of events.
*
*
See {@link #listEventsWithHttpInfoAsync}.
*
* @param parameters Optional parameters for the request.
* @return CompletableFuture<EventsListResponse>
*/
public CompletableFuture listEventsAsync(
ListEventsOptionalParameters parameters) {
return listEventsWithHttpInfoAsync(parameters)
.thenApply(
response -> {
return response.getData();
});
}
/**
* Get a list of events.
*
* See {@link #listEventsWithHttpInfo}.
*
* @return PaginationIterable<EventResponse>
*/
public PaginationIterable listEventsWithPagination() {
ListEventsOptionalParameters parameters = new ListEventsOptionalParameters();
return listEventsWithPagination(parameters);
}
/**
* Get a list of events.
*
* See {@link #listEventsWithHttpInfo}.
*
* @return EventsListResponse
*/
public PaginationIterable listEventsWithPagination(
ListEventsOptionalParameters parameters) {
String resultsPath = "getData";
String valueGetterPath = "getMeta.getPage.getAfter";
String valueSetterPath = "pageCursor";
Boolean valueSetterParamOptional = true;
Integer limit;
if (parameters.pageLimit == null) {
limit = 10;
parameters.pageLimit(limit);
} else {
limit = parameters.pageLimit;
}
LinkedHashMap args = new LinkedHashMap();
args.put("optionalParams", parameters);
PaginationIterable iterator =
new PaginationIterable(
this,
"listEvents",
resultsPath,
valueGetterPath,
valueSetterPath,
valueSetterParamOptional,
true,
limit,
args);
return iterator;
}
/**
* List endpoint returns events that match an events search query. Results are
* paginated similarly to logs.
*
* Use this endpoint to see your latest events.
*
* @param parameters Optional parameters for the request.
* @return ApiResponse<EventsListResponse>
* @throws ApiException if fails to make API call
* @http.response.details
*
* Response details
* Status Code Description Response Headers
* 200 OK -
* 400 Bad Request -
* 403 Not Authorized -
* 429 Too many requests -
*
*/
public ApiResponse listEventsWithHttpInfo(
ListEventsOptionalParameters parameters) throws ApiException {
Object localVarPostBody = null;
String filterQuery = parameters.filterQuery;
String filterFrom = parameters.filterFrom;
String filterTo = parameters.filterTo;
EventsSort sort = parameters.sort;
String pageCursor = parameters.pageCursor;
Integer pageLimit = parameters.pageLimit;
// create path and map variables
String localVarPath = "/api/v2/events";
List localVarQueryParams = new ArrayList();
Map localVarHeaderParams = new HashMap();
localVarQueryParams.addAll(apiClient.parameterToPairs("", "filter[query]", filterQuery));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "filter[from]", filterFrom));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "filter[to]", filterTo));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "sort", sort));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[cursor]", pageCursor));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[limit]", pageLimit));
Invocation.Builder builder =
apiClient.createBuilder(
"v2.EventsApi.listEvents",
localVarPath,
localVarQueryParams,
localVarHeaderParams,
new HashMap(),
new String[] {"application/json"},
new String[] {"AuthZ", "apiKeyAuth", "appKeyAuth"});
return apiClient.invokeAPI(
"GET",
builder,
localVarHeaderParams,
new String[] {},
localVarPostBody,
new HashMap(),
false,
new GenericType() {});
}
/**
* Get a list of events.
*
* See {@link #listEventsWithHttpInfo}.
*
* @param parameters Optional parameters for the request.
* @return CompletableFuture<ApiResponse<EventsListResponse>>
*/
public CompletableFuture> listEventsWithHttpInfoAsync(
ListEventsOptionalParameters parameters) {
Object localVarPostBody = null;
String filterQuery = parameters.filterQuery;
String filterFrom = parameters.filterFrom;
String filterTo = parameters.filterTo;
EventsSort sort = parameters.sort;
String pageCursor = parameters.pageCursor;
Integer pageLimit = parameters.pageLimit;
// create path and map variables
String localVarPath = "/api/v2/events";
List localVarQueryParams = new ArrayList();
Map localVarHeaderParams = new HashMap();
localVarQueryParams.addAll(apiClient.parameterToPairs("", "filter[query]", filterQuery));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "filter[from]", filterFrom));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "filter[to]", filterTo));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "sort", sort));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[cursor]", pageCursor));
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[limit]", pageLimit));
Invocation.Builder builder;
try {
builder =
apiClient.createBuilder(
"v2.EventsApi.listEvents",
localVarPath,
localVarQueryParams,
localVarHeaderParams,
new HashMap(),
new String[] {"application/json"},
new String[] {"AuthZ", "apiKeyAuth", "appKeyAuth"});
} catch (ApiException ex) {
CompletableFuture> result = new CompletableFuture<>();
result.completeExceptionally(ex);
return result;
}
return apiClient.invokeAPIAsync(
"GET",
builder,
localVarHeaderParams,
new String[] {},
localVarPostBody,
new HashMap(),
false,
new GenericType() {});
}
/** Manage optional parameters to searchEvents. */
public static class SearchEventsOptionalParameters {
private EventsListRequest body;
/**
* Set body.
*
* @param body (optional)
* @return SearchEventsOptionalParameters
*/
public SearchEventsOptionalParameters body(EventsListRequest body) {
this.body = body;
return this;
}
}
/**
* Search events.
*
* See {@link #searchEventsWithHttpInfo}.
*
* @return EventsListResponse
* @throws ApiException if fails to make API call
*/
public EventsListResponse searchEvents() throws ApiException {
return searchEventsWithHttpInfo(new SearchEventsOptionalParameters()).getData();
}
/**
* Search events.
*
*
See {@link #searchEventsWithHttpInfoAsync}.
*
* @return CompletableFuture<EventsListResponse>
*/
public CompletableFuture searchEventsAsync() {
return searchEventsWithHttpInfoAsync(new SearchEventsOptionalParameters())
.thenApply(
response -> {
return response.getData();
});
}
/**
* Search events.
*
* See {@link #searchEventsWithHttpInfo}.
*
* @param parameters Optional parameters for the request.
* @return EventsListResponse
* @throws ApiException if fails to make API call
*/
public EventsListResponse searchEvents(SearchEventsOptionalParameters parameters)
throws ApiException {
return searchEventsWithHttpInfo(parameters).getData();
}
/**
* Search events.
*
*
See {@link #searchEventsWithHttpInfoAsync}.
*
* @param parameters Optional parameters for the request.
* @return CompletableFuture<EventsListResponse>
*/
public CompletableFuture searchEventsAsync(
SearchEventsOptionalParameters parameters) {
return searchEventsWithHttpInfoAsync(parameters)
.thenApply(
response -> {
return response.getData();
});
}
/**
* Search events.
*
* See {@link #searchEventsWithHttpInfo}.
*
* @return PaginationIterable<EventResponse>
*/
public PaginationIterable searchEventsWithPagination() {
SearchEventsOptionalParameters parameters = new SearchEventsOptionalParameters();
return searchEventsWithPagination(parameters);
}
/**
* Search events.
*
* See {@link #searchEventsWithHttpInfo}.
*
* @return EventsListResponse
*/
public PaginationIterable searchEventsWithPagination(
SearchEventsOptionalParameters parameters) {
String resultsPath = "getData";
String valueGetterPath = "getMeta.getPage.getAfter";
String valueSetterPath = "body.getPage.setCursor";
Boolean valueSetterParamOptional = true;
Integer limit;
if (parameters.body == null) {
parameters.body(new EventsListRequest());
}
if (parameters.body.getPage() == null) {
parameters.body.setPage(new EventsRequestPage());
}
if (parameters.body.getPage().getLimit() == null) {
limit = 10;
parameters.body.getPage().setLimit(limit);
} else {
limit = parameters.body.getPage().getLimit();
}
LinkedHashMap args = new LinkedHashMap();
args.put("optionalParams", parameters);
PaginationIterable iterator =
new PaginationIterable(
this,
"searchEvents",
resultsPath,
valueGetterPath,
valueSetterPath,
valueSetterParamOptional,
true,
limit,
args);
return iterator;
}
/**
* List endpoint returns events that match an events search query. Results are
* paginated similarly to logs.
*
* Use this endpoint to build complex events filtering and search.
*
* @param parameters Optional parameters for the request.
* @return ApiResponse<EventsListResponse>
* @throws ApiException if fails to make API call
* @http.response.details
*
* Response details
* Status Code Description Response Headers
* 200 OK -
* 400 Bad Request -
* 403 Not Authorized -
* 429 Too many requests -
*
*/
public ApiResponse searchEventsWithHttpInfo(
SearchEventsOptionalParameters parameters) throws ApiException {
Object localVarPostBody = parameters.body;
// create path and map variables
String localVarPath = "/api/v2/events/search";
Map localVarHeaderParams = new HashMap();
Invocation.Builder builder =
apiClient.createBuilder(
"v2.EventsApi.searchEvents",
localVarPath,
new ArrayList(),
localVarHeaderParams,
new HashMap(),
new String[] {"application/json"},
new String[] {"apiKeyAuth", "appKeyAuth"});
return apiClient.invokeAPI(
"POST",
builder,
localVarHeaderParams,
new String[] {"application/json"},
localVarPostBody,
new HashMap(),
false,
new GenericType() {});
}
/**
* Search events.
*
* See {@link #searchEventsWithHttpInfo}.
*
* @param parameters Optional parameters for the request.
* @return CompletableFuture<ApiResponse<EventsListResponse>>
*/
public CompletableFuture> searchEventsWithHttpInfoAsync(
SearchEventsOptionalParameters parameters) {
Object localVarPostBody = parameters.body;
// create path and map variables
String localVarPath = "/api/v2/events/search";
Map localVarHeaderParams = new HashMap();
Invocation.Builder builder;
try {
builder =
apiClient.createBuilder(
"v2.EventsApi.searchEvents",
localVarPath,
new ArrayList(),
localVarHeaderParams,
new HashMap(),
new String[] {"application/json"},
new String[] {"apiKeyAuth", "appKeyAuth"});
} catch (ApiException ex) {
CompletableFuture> result = new CompletableFuture<>();
result.completeExceptionally(ex);
return result;
}
return apiClient.invokeAPIAsync(
"POST",
builder,
localVarHeaderParams,
new String[] {"application/json"},
localVarPostBody,
new HashMap(),
false,
new GenericType() {});
}
}