|
| 1 | +// Bulk write datastore items returns "OK" response |
| 2 | + |
| 3 | +import com.datadog.api.client.ApiClient; |
| 4 | +import com.datadog.api.client.ApiException; |
| 5 | +import com.datadog.api.client.v2.api.ActionsDatastoresApi; |
| 6 | +import com.datadog.api.client.v2.model.BulkPutAppsDatastoreItemsRequest; |
| 7 | +import com.datadog.api.client.v2.model.BulkPutAppsDatastoreItemsRequestData; |
| 8 | +import com.datadog.api.client.v2.model.BulkPutAppsDatastoreItemsRequestDataAttributes; |
| 9 | +import com.datadog.api.client.v2.model.DatastoreItemsDataType; |
| 10 | +import com.datadog.api.client.v2.model.PutAppsDatastoreItemResponseArray; |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.Map; |
| 13 | + |
| 14 | +public class Example { |
| 15 | + public static void main(String[] args) { |
| 16 | + ApiClient defaultClient = ApiClient.getDefaultApiClient(); |
| 17 | + ActionsDatastoresApi apiInstance = new ActionsDatastoresApi(defaultClient); |
| 18 | + |
| 19 | + // there is a valid "datastore" in the system |
| 20 | + String DATASTORE_DATA_ID = System.getenv("DATASTORE_DATA_ID"); |
| 21 | + |
| 22 | + BulkPutAppsDatastoreItemsRequest body = |
| 23 | + new BulkPutAppsDatastoreItemsRequest() |
| 24 | + .data( |
| 25 | + new BulkPutAppsDatastoreItemsRequestData() |
| 26 | + .attributes( |
| 27 | + new BulkPutAppsDatastoreItemsRequestDataAttributes() |
| 28 | + .values( |
| 29 | + Arrays.asList( |
| 30 | + Map.ofEntries( |
| 31 | + Map.entry("id", "cust_3141"), |
| 32 | + Map.entry("name", "Johnathan")), |
| 33 | + Map.ofEntries( |
| 34 | + Map.entry("id", "cust_3142"), Map.entry("name", "Mary"))))) |
| 35 | + .type(DatastoreItemsDataType.ITEMS)); |
| 36 | + |
| 37 | + try { |
| 38 | + PutAppsDatastoreItemResponseArray result = |
| 39 | + apiInstance.bulkWriteDatastoreItems(DATASTORE_DATA_ID, body); |
| 40 | + System.out.println(result); |
| 41 | + } catch (ApiException e) { |
| 42 | + System.err.println("Exception when calling ActionsDatastoresApi#bulkWriteDatastoreItems"); |
| 43 | + System.err.println("Status code: " + e.getCode()); |
| 44 | + System.err.println("Reason: " + e.getResponseBody()); |
| 45 | + System.err.println("Response headers: " + e.getResponseHeaders()); |
| 46 | + e.printStackTrace(); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments