Skip to content

Commit 1b3a14a

Browse files
committed
Sync docs (#20)
* sync api documentation updated * upgrade api sync docs
1 parent 463f60c commit 1b3a14a

File tree

3 files changed

+166
-2
lines changed

3 files changed

+166
-2
lines changed

core/controllers/task/job.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ module.exports = (server) => {
4040
createJob
4141
)
4242

43+
//
44+
// new version
45+
//
46+
server.post('/task/:task/job',
47+
server.auth.bearerMiddleware,
48+
router.resolve.customerSessionToEntity(),
49+
router.requireCredential('user'),
50+
router.resolve.idToEntityByCustomer({ param: 'task', required: true }),
51+
router.ensureAllowed({ entity: { name: 'task' } }),
52+
createJob
53+
)
54+
4355
server.post('/:customer/task/:task/secret/:secret/job',
4456
router.resolve.idToEntity({ param: 'task', required: true }),
4557
router.requireSecret('task'),

docs/sync/README.md

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,39 @@ This can be achived using the API in sync mode. The only restriction is the task
1717
___
1818

1919

20-
## API Paths
20+
## Paths
2121

2222
| Method | Path | Description | ACL |
2323
| ---- | ----| ----| ----|
2424
| POST | /${customer}/task/${id}/job | [Run task](#waiting-output) | user |
2525

2626

27+
## Arguments
28+
29+
By default the sync api will respond with the final output of the task execution. when a job finishes the output value is parsed and then stored withing the job document in the output field.
30+
31+
| Name | Values | Description |
32+
| ---- | ---- | ---- |
33+
| result | empty/null. is ignored | Result is another field stored with the job execution data in the database. This includes the execution log, the output, the lastline. |
34+
| full | empty/null. is ignored | This is the full job document. This is the same value that can be obtained doing a GET request to the jobs api |
35+
| parse | empty or a Number/Integer > 0 | The output of a job is always stored in the database as an array of Task Arguments strings. The parse option will use the index number 0 of the output and parse it as JSON. In some cases you might need to return a specific index of the output array. Using parse, set it to the a number from 0 to N, representing the index of the output array. If the index is not present or if it is unreadable the raw output will be returned |
36+
37+
38+
## Response
39+
40+
By default the response will be the raw task outputs without parsing
41+
42+
| State | HTTP Status Code |
43+
| ---- | ---- |
44+
| success | 200 |
45+
| failure | 500 |
46+
47+
2748
### NOTES
2849

2950
* Single **Task execution** is supported. Workflows execution is **NOT Possible** at this moment.
3051

31-
___
52+
______
3253

3354

3455
## Examples
@@ -45,3 +66,133 @@ curl -s -X POST "https://sync.theeye.io/${customer}/task/${taskId}/job?access_to
4566

4667

4768
```
69+
70+
### sample failure
71+
72+
73+
```bash
74+
75+
curl -i -X POST 'https://sync.theeye.io/${customer_id}/task/${task_id}/job?access_token=${token}' \
76+
--header 'content-type: application/json' \
77+
--data '{"task_arguments":[200]}'
78+
79+
```
80+
81+
82+
```http
83+
84+
HTTP/1.1 500 Internal Server Error
85+
X-Powered-By: Express
86+
Access-Control-Allow-Origin: *
87+
Access-Control-Allow-Methods: GET,PUT,PATCH,POST,DELETE,OPTIONS
88+
Access-Control-Allow-Credentials: true
89+
Access-Control-Allow-Headers: Origin, Accept, User-Agent, Accept-Charset, Cache-Control, Accept-Encoding, Content-Type, Authorization, Content-Length, X-Requested-With
90+
Content-Type: application/json; charset=utf-8
91+
Content-Length: 135
92+
ETag: W/"87-+Fzdxc2Q7NsFIfhclF3lcqgSScY"
93+
Date: Fri, 28 Jan 2022 16:59:54 GMT
94+
Connection: keep-alive
95+
Keep-Alive: timeout=5
96+
97+
["{\"message\":\"Validation Error. Invalid Argument Value\",\"statusCode\":418,\"name\":\"ClientError\",\"code\":\"\",\"status\":418}"]
98+
99+
100+
```
101+
102+
### sample success
103+
104+
105+
```bash
106+
107+
curl -i -X POST 'https://sync.theeye.io/${customer_id}/task/${task_id}/job?access_token=${token}' \
108+
--header 'content-type: application/json' \
109+
--data '{"task_arguments":[100]}'
110+
111+
```
112+
113+
```http
114+
115+
HTTP/1.1 200 OK
116+
X-Powered-By: Express
117+
Access-Control-Allow-Origin: *
118+
Access-Control-Allow-Methods: GET,PUT,PATCH,POST,DELETE,OPTIONS
119+
Access-Control-Allow-Credentials: true
120+
Access-Control-Allow-Headers: Origin, Accept, User-Agent, Accept-Charset, Cache-Control, Accept-Encoding, Content-Type, Authorization, Content-Length, X-Requested-With
121+
Content-Type: application/json; charset=utf-8
122+
Content-Length: 62
123+
ETag: W/"3e-Earn8PE7JwarkhTciq4Sn4inI3g"
124+
Date: Fri, 28 Jan 2022 17:00:22 GMT
125+
Connection: keep-alive
126+
Keep-Alive: timeout=5
127+
128+
["{\"name\":\"tomer\",\"date\":\"2022-01-28T17:00:22.676Z\"}"]
129+
130+
```
131+
132+
133+
### sample success using parse
134+
135+
[Download and Import this task](/sync/Rest_API_Response.json ":ignore")
136+
137+
138+
Get the ID and replace in the requests below
139+
140+
```bash
141+
142+
curl -i -X POST 'https://sync.theeye.io/${customer_id}/task/${task_id}/job?parse&access_token=${token}' \
143+
--header 'content-type: application/json' \
144+
--data '{"task_arguments":[100]}'
145+
146+
```
147+
148+
149+
```http
150+
151+
HTTP/1.1 200 OK
152+
X-Powered-By: Express
153+
Access-Control-Allow-Origin: *
154+
Access-Control-Allow-Methods: GET,PUT,PATCH,POST,DELETE,OPTIONS
155+
Access-Control-Allow-Credentials: true
156+
Access-Control-Allow-Headers: Origin, Accept, User-Agent, Accept-Charset, Cache-Control, Accept-Encoding, Content-Type, Authorization, Content-Length, X-Requested-With
157+
Content-Type: application/json; charset=utf-8
158+
Content-Length: 50
159+
ETag: W/"32-QGrCXrCY2sEcc1V/fL6omhdvPKY"
160+
Date: Fri, 28 Jan 2022 16:26:41 GMT
161+
Connection: keep-alive
162+
Keep-Alive: timeout=5
163+
164+
{"name":"tomer","date":"2022-01-28T16:26:41.201Z"}
165+
166+
```
167+
168+
### sample failure using parse
169+
170+
171+
```bash
172+
173+
curl -i -X POST 'https://sync.theeye.io/${customer_id}/task/${task_id}/job?parse&access_token=${token}' \
174+
--header 'content-type: application/json' \
175+
--data '{"task_arguments":[200]}'
176+
177+
```
178+
179+
180+
```http
181+
182+
HTTP/1.1 418 I'm a Teapot
183+
X-Powered-By: Express
184+
Access-Control-Allow-Origin: *
185+
Access-Control-Allow-Methods: GET,PUT,PATCH,POST,DELETE,OPTIONS
186+
Access-Control-Allow-Credentials: true
187+
Access-Control-Allow-Headers: Origin, Accept, User-Agent, Accept-Charset, Cache-Control, Accept-Encoding, Content-Type, Authorization, Content-Length, X-Requested-With
188+
Content-Type: application/json; charset=utf-8
189+
Content-Length: 115
190+
ETag: W/"73-FBmPIgGdDNzn6NM27joxlSUMWp4"
191+
Date: Fri, 28 Jan 2022 16:56:47 GMT
192+
Connection: keep-alive
193+
Keep-Alive: timeout=5
194+
195+
{"message":"Validation Error. Invalid Argument Value","statusCode":418,"name":"ClientError","code":"","status":418}
196+
197+
```
198+

docs/sync/Rest_API_Response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"task":{"order":0,"enable":true,"type":"script","public":false,"tags":[],"grace_time":0,"task_arguments":[{"id":1,"order":0,"type":"input","label":"number","value":"","help":"","readonly":false,"required":true,"multiple":false,"masked":false,"charsmin":0,"charsmax":0,"charset":null,"pattern":"","options":[]}],"arguments_type":"legacy","output_parameters":[],"register_body":false,"execution_count":83,"multitasking":true,"show_result":false,"assigned_users":[],"user_inputs":false,"user_inputs_members":[],"empty_viewers":false,"cancellable":true,"autoremove_completed_jobs_limit":5,"script_arguments":[{"id":1,"order":0,"type":"input","label":"number","value":"","help":"","readonly":false,"required":true,"multiple":false,"masked":false,"charsmin":0,"charsmax":0,"charset":null,"pattern":"","options":[]}],"logging":false,"_type":"ScriptTask","creation_date":"2022-01-28T13:01:43.355Z","last_update":"2022-01-28T16:56:46.292Z","env":{"NODE_ENV":""},"name":"Rest API Response","description":"","timeout":600000,"allows_dynamic_settings":false,"script_runas":"node %script%","template":null,"template_id":null,"source_model_id":"61f3e937c38201da80f96c27"},"file":{"order":0,"filename":"api.js","keyname":"api.js[ts:1643388995376]","mimetype":"text/javascript","extension":"js","size":2079,"description":"","md5":"824a8455060c66ebce1408efb52652dd","public":false,"tags":[],"source_model_id":"61f3e92cc38201da80f96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