-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_create.go
More file actions
51 lines (44 loc) · 1.39 KB
/
workflow_create.go
File metadata and controls
51 lines (44 loc) · 1.39 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
47
48
49
50
51
package unstructured
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
)
// CreateWorkflowRequest represents the request to create a workflow
type CreateWorkflowRequest struct {
Name string `json:"name"`
SourceID *string `json:"source_id,omitempty"`
DestinationID *string `json:"destination_id,omitempty"`
WorkflowNodes []WorkflowNode `json:"workflow_nodes,omitempty"`
Schedule *string `json:"schedule,omitempty"`
ReprocessAll *bool `json:"reprocess_all,omitempty"`
}
// CreateWorkflow creates a new workflow
func (c *Client) CreateWorkflow(ctx context.Context, in *CreateWorkflowRequest) (*Workflow, error) {
body, err := json.Marshal(struct {
*CreateWorkflowRequest
WorkflowType WorkflowType `json:"workflow_type"`
}{
CreateWorkflowRequest: in,
WorkflowType: WorkflowTypeCustom,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal workflow request: %w", err)
}
req, err := http.NewRequestWithContext(ctx,
http.MethodPost,
c.endpoint.JoinPath("workflows/").String(),
bytes.NewReader(body),
)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
var workflow Workflow
if err := c.do(req, &workflow); err != nil {
return nil, fmt.Errorf("failed to create workflow: %w", err)
}
return &workflow, nil
}