|
| 1 | +// Create an automation rule returns "Created" response |
| 2 | + |
| 3 | +import com.datadog.api.client.ApiClient; |
| 4 | +import com.datadog.api.client.ApiException; |
| 5 | +import com.datadog.api.client.v2.api.CaseManagementApi; |
| 6 | +import com.datadog.api.client.v2.model.AutomationRuleAction; |
| 7 | +import com.datadog.api.client.v2.model.AutomationRuleActionData; |
| 8 | +import com.datadog.api.client.v2.model.AutomationRuleActionType; |
| 9 | +import com.datadog.api.client.v2.model.AutomationRuleCreate; |
| 10 | +import com.datadog.api.client.v2.model.AutomationRuleCreateAttributes; |
| 11 | +import com.datadog.api.client.v2.model.AutomationRuleCreateRequest; |
| 12 | +import com.datadog.api.client.v2.model.AutomationRuleResponse; |
| 13 | +import com.datadog.api.client.v2.model.AutomationRuleTrigger; |
| 14 | +import com.datadog.api.client.v2.model.AutomationRuleTriggerData; |
| 15 | +import com.datadog.api.client.v2.model.AutomationRuleTriggerType; |
| 16 | +import com.datadog.api.client.v2.model.CaseAutomationRuleResourceType; |
| 17 | +import com.datadog.api.client.v2.model.CaseAutomationRuleState; |
| 18 | + |
| 19 | +public class Example { |
| 20 | + public static void main(String[] args) { |
| 21 | + ApiClient defaultClient = ApiClient.getDefaultApiClient(); |
| 22 | + defaultClient.setUnstableOperationEnabled("v2.createCaseAutomationRule", true); |
| 23 | + CaseManagementApi apiInstance = new CaseManagementApi(defaultClient); |
| 24 | + |
| 25 | + AutomationRuleCreateRequest body = |
| 26 | + new AutomationRuleCreateRequest() |
| 27 | + .data( |
| 28 | + new AutomationRuleCreate() |
| 29 | + .attributes( |
| 30 | + new AutomationRuleCreateAttributes() |
| 31 | + .action( |
| 32 | + new AutomationRuleAction() |
| 33 | + .data( |
| 34 | + new AutomationRuleActionData() |
| 35 | + .handle("workflow-handle-123")) |
| 36 | + .type(AutomationRuleActionType.EXECUTE_WORKFLOW)) |
| 37 | + .name("Auto-assign workflow") |
| 38 | + .state(CaseAutomationRuleState.ENABLED) |
| 39 | + .trigger( |
| 40 | + new AutomationRuleTrigger() |
| 41 | + .data(new AutomationRuleTriggerData()) |
| 42 | + .type(AutomationRuleTriggerType.CASE_CREATED))) |
| 43 | + .type(CaseAutomationRuleResourceType.RULE)); |
| 44 | + |
| 45 | + try { |
| 46 | + AutomationRuleResponse result = |
| 47 | + apiInstance.createCaseAutomationRule("e555e290-ed65-49bd-ae18-8acbfcf18db7", body); |
| 48 | + System.out.println(result); |
| 49 | + } catch (ApiException e) { |
| 50 | + System.err.println("Exception when calling CaseManagementApi#createCaseAutomationRule"); |
| 51 | + System.err.println("Status code: " + e.getCode()); |
| 52 | + System.err.println("Reason: " + e.getResponseBody()); |
| 53 | + System.err.println("Response headers: " + e.getResponseHeaders()); |
| 54 | + e.printStackTrace(); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments