Skip to content

Commit bf453e6

Browse files
committed
update docs after testing
1 parent 47c3bfe commit bf453e6

File tree

1 file changed

+48
-36
lines changed

1 file changed

+48
-36
lines changed

docs/build/workflows-api.md

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ A Workflow has the following structure:
7979
}
8080
```
8181

82-
When creating a new Workflow, a UUID will be created by the server.
82+
When creating a new Workflow, the server will generate UUIDs for the workflow
83+
and all steps and edges. You can use any id string you like in the creation of
84+
new nodes and edges - so long as id usage is consistent.
8385

84-
When creating new steps or triggers (including when creating a whole new
85-
workflow), ids will be replaced by the server with UUIDs.
86+
When matching a PUT or PATCH request, new steps and edges must be given UUIDs.
8687

8788
You MUST ensure that all steps and triggers referenced by an edge are defined
8889
within the same workflow.
@@ -96,53 +97,64 @@ Access Token (PAT) and `baseUrl` set to your OpenFn instance (ie,
9697
Create new Workflow:
9798

9899
```
99-
post(
100-
`/api/projects/${$.projectId}/workflows`,
101-
{
102-
"name": "My Workflow",
103-
"edges": [
100+
post(`/api/projects/${$.projectId}/workflows`, {
101+
body: {
102+
name: 'My Workflow',
103+
edges: [
104104
{
105-
"source_trigger_id": "c79ce46c-ab0f-4f5b-bf2d-fed52aef2a41",
106-
"target_job_id": "26304a1e-267b-4bc9-940f-171db1905885",
107-
}
105+
source_trigger_id: 'trigger-1',
106+
target_job_id: 'job-1',
107+
condition_type: 'always',
108+
},
108109
],
109-
"jobs": [
110+
jobs: [
110111
{
111-
"id": "26304a1e-267b-4bc9-940f-171db1905885",
112-
"body": "/* job code goes here */",
113-
"adaptor": "@openfn/language-common@latest",
114-
}
112+
id: 'job-1',
113+
name: 'My Job',
114+
body: '/* job code goes here */',
115+
adaptor: '@openfn/language-common@latest',
116+
},
115117
],
116-
"triggers": [
118+
triggers: [
117119
{
118-
"id": "c79ce46c-ab0f-4f5b-bf2d-fed52aef2a41",
119-
"type": "webhook",
120-
"enabled": true
121-
}
120+
id: 'trigger-1',
121+
type: 'webhook',
122+
enabled: true,
123+
},
122124
],
123-
}
124-
)
125+
},
126+
headers: { 'content-type': 'application/json' },
127+
});
125128
```
126129

130+
The resulting workflow with updated UUIDs and metadata will be written to
131+
state.data.workflow
132+
127133
Add a new step to an existing Workflow:
128134

129135
```
130-
patch(
131-
`/api/projects/${$.projectId}/workflows/${$.workflowId}`,
132-
{
133-
"edges": [
136+
fn((state) => {
137+
const jobId = util.uuid()
138+
state.diff = {
139+
edges: [
134140
{
135-
"source_job_id": "c79ce46c-ab0f-4f5b-bf2d-fed52aef2a41",
136-
"target_job_id": "new-job",
137-
}
141+
source_job_id: 'c79ce46c-ab0f-4f5b-bf2d-fed52aef2a41',
142+
target_job_id: jobId,
143+
},
138144
],
139-
"jobs": [
145+
jobs: [
140146
{
141-
"id": "new-job",
142-
"body": "/* job code goes here */",
143-
"adaptor": "@openfn/language-common@latest",
144-
}
147+
id: jobId,
148+
body: '/* job code goes here */',
149+
adaptor: '@openfn/language-common@latest',
150+
},
145151
],
146152
}
147-
)
153+
return state;
154+
})
155+
patch(`/api/projects/${$.projectId}/workflows/${$.workflowId}`, {
156+
body: $.diff,
157+
headers: { 'content-type': 'application/json' },
158+
});
159+
148160
```

0 commit comments

Comments
 (0)