-
Notifications
You must be signed in to change notification settings - Fork 54
/
CreateCase.go
56 lines (49 loc) · 1.75 KB
/
CreateCase.go
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
47
48
49
50
51
52
53
54
55
56
// Create a case returns "CREATED" 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() {
// there is a valid "user" in the system
UserDataID := os.Getenv("USER_DATA_ID")
body := datadogV2.CaseCreateRequest{
Data: datadogV2.CaseCreate{
Attributes: datadogV2.CaseCreateAttributes{
Priority: datadogV2.CASEPRIORITY_NOT_DEFINED.Ptr(),
Title: "Security breach investigation in 0cfbc5cbc676ee71",
Type: datadogV2.CASETYPE_STANDARD,
},
Relationships: &datadogV2.CaseCreateRelationships{
Assignee: *datadogV2.NewNullableNullableUserRelationship(&datadogV2.NullableUserRelationship{
Data: *datadogV2.NewNullableNullableUserRelationshipData(&datadogV2.NullableUserRelationshipData{
Id: UserDataID,
Type: datadogV2.USERRESOURCETYPE_USER,
}),
}),
Project: datadogV2.ProjectRelationship{
Data: datadogV2.ProjectRelationshipData{
Id: "d4bbe1af-f36e-42f1-87c1-493ca35c320e",
Type: datadogV2.PROJECTRESOURCETYPE_PROJECT,
},
},
},
Type: datadogV2.CASERESOURCETYPE_CASE,
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewCaseManagementApi(apiClient)
resp, r, err := api.CreateCase(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CaseManagementApi.CreateCase`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `CaseManagementApi.CreateCase`:\n%s\n", responseContent)
}