github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/docs/konnectors.md (about) 1 [Table of contents](README.md#table-of-contents) 2 3 # Konnectors 4 5 It is possible to manage konnectors applications from the stack. The source-code 6 of the konnector is installed on the cozy and the user can manage its execution 7 _via_ our [job system](jobs.md) and the [konnector worker](workers.md). 8 9 ## Install a konnector 10 11 ## The manifest 12 13 An exhaustive manifest specification is available in the [Cozy Apps Registry documentation](https://docs.cozy.io/en/cozy-apps-registry/#properties-meaning-reference) 14 15 ### POST /konnectors/:slug 16 17 Install a konnector, ie download the files and put them in `/konnectors/:slug` 18 in the virtual file system of the user, create an `io.cozy.konnectors` document, 19 register the permissions, etc. 20 21 This endpoint is asynchronous and returns a successful return as soon as the 22 konnector installation has started, meaning we have successfully reached the 23 manifest and started to fetch konnector source code. 24 25 To make this endpoint synchronous, use the header `Accept: text/event-stream`. 26 This will make a eventsource stream sending the manifest and returning when the 27 konnector has been installed or failed. 28 29 #### Status codes 30 31 - 202 Accepted, when the konnector installation has been accepted. 32 - 400 Bad-Request, when the manifest of the konnector could not be processed 33 (for instance, it is not valid JSON). 34 - 404 Not Found, when the manifest or the source of the konnector is not 35 reachable. 36 - 422 Unprocessable Entity, when the sent data is invalid (for example, the 37 slug is invalid or the Source parameter is not a proper or supported url) 38 39 #### Query-String 40 41 | Parameter | Description | 42 | --------- | ----------------------------------------------------------- | 43 | Source | URL from where the app can be downloaded (only for install) | 44 45 #### Request 46 47 ```http 48 POST /konnectors/bank101?Source=git://github.com/cozy/cozy-bank101.git HTTP/1.1 49 Accept: application/vnd.api+json 50 ``` 51 52 #### Response 53 54 ```http 55 HTTP/1.1 202 Accepted 56 Content-Type: application/vnd.api+json 57 ``` 58 59 ```json 60 { 61 "data": [{ 62 "id": "4cfbd8be-8968-11e6-9708-ef55b7c20863", 63 "type": "io.cozy.konnectors", 64 "meta": { 65 "rev": "1-7a1f918147df94580c92b47275e4604a" 66 }, 67 "attributes": { 68 "name": "bank101", 69 "state": "installing", 70 "slug": "bank101", 71 ... 72 }, 73 "links": { 74 "self": "/konnectors/bank101" 75 } 76 }] 77 } 78 ``` 79 80 **Note**: it's possible to choose a git branch by passing it in the fragment 81 like this: 82 83 ```http 84 POST /konnectors/bank101-dev?Source=git://github.com/cozy/cozy-bank101.git%23dev HTTP/1.1 85 ``` 86 87 ### PUT /konnectors/:slug 88 89 Update a konnector source code with the specified slug name. 90 91 This endpoint is asynchronous and returns a successful return as soon as the 92 konnector installation has started, meaning we have successfully reached the 93 manifest and started to fetch konnector source code. 94 95 To make this endpoint synchronous, use the header `Accept: text/event-stream`. 96 This will make a eventsource stream sending the manifest and returning when the 97 konnector has been updated or failed. 98 99 #### Request 100 101 ```http 102 PUT /konnectors/bank101 HTTP/1.1 103 Accept: application/vnd.api+json 104 ``` 105 106 #### Response 107 108 ```http 109 HTTP/1.1 202 Accepted 110 Content-Type: application/vnd.api+json 111 ``` 112 113 ```json 114 { 115 "data": [{ 116 "id": "4cfbd8be-8968-11e6-9708-ef55b7c20863", 117 "type": "io.cozy.konnectors", 118 "meta": { 119 "rev": "1-7a1f918147df94580c92b47275e4604a" 120 }, 121 "attributes": { 122 "name": "bank101", 123 "state": "installing", 124 "slug": "bank101", 125 ... 126 }, 127 "links": { 128 "self": "/konnectors/bank101" 129 } 130 }] 131 } 132 ``` 133 134 #### Status codes 135 136 - 202 Accepted, when the konnector installation has been accepted. 137 - 400 Bad-Request, when the manifest of the konnector could not be processed 138 (for instance, it is not valid JSON). 139 - 404 Not Found, when the konnector with the specified slug was not found or 140 when the manifest or the source of the konnector is not reachable. 141 - 422 Unprocessable Entity, when the sent data is invalid (for example, the 142 slug is invalid or the Source parameter is not a proper or supported url) 143 144 #### Advanced usage 145 146 Two optional query parameters are available for a konnector update: 147 - `PermissionsAcked`: (defaults to `true`) 148 - Tells that the user accepted the permissions/ToS. It is useful if there are 149 newer permissions or Terms Of Service and you want to be sure they were read 150 or accepted. If set to `false`, the update will be blocked and the user will 151 be told that a new konnector version is available.\ 152 > Note: `PermissionsAcked` can be skipped. \ 153 If an instance is in a `context` configured with the parameter 154 `permissions_skip_verification` sets to `true`, permissions 155 verification will be ignored. 156 157 - `Source` (defaults to source url installation): 158 - Use a different source to update this konnector (e.g. to install a `beta` or 159 `dev` konnector version) 160 161 ##### Examples: 162 163 - You have a trainline konnector on a `stable` channel, and you want to update 164 it to a particular `beta` version: 165 166 ```http 167 PUT /konnectors/trainline?Source=https://<konnectors-repository>/trainline/1.0.0-beta HTTP/1.1 168 Accept: application/vnd.api+json 169 ``` 170 171 - You want to attempt the trainline konnector update, but prevent it if new 172 permissions were added 173 174 ```http 175 PUT /konnectors/trainline?PermissionsAcked=false HTTP/1.1 176 Accept: application/vnd.api+json 177 ``` 178 179 You can combine these parameters to use a precise konnector version and stay on 180 another channel (when permissions are different): 181 182 - Install a version (e.g. `1.0.0`). 183 - Ask an update to `stable` channel with `PermissionsAcked` to `false` 184 - `Source` will be `stable`, and your version remains `1.0.0` 185 186 ## List installed konnectors 187 188 ### GET /konnectors/ 189 190 #### Request 191 192 ```http 193 GET /konnectors/ HTTP/1.1 194 Accept: application/vnd.api+json 195 ``` 196 197 #### Response 198 199 ```http 200 HTTP/1.1 200 OK 201 Content-Type: application/vnd.api+json 202 ``` 203 204 ```json 205 { 206 "data": [{ 207 "id": "4cfbd8be-8968-11e6-9708-ef55b7c20863", 208 "type": "io.cozy.konnectors", 209 "meta": { 210 "rev": "1-7a1f918147df94580c92b47275e4604a" 211 }, 212 "attributes": { 213 "name": "bank101", 214 "state": "installing", 215 "slug": "bank101", 216 ... 217 }, 218 "links": { 219 "self": "/konnectors/bank101" 220 } 221 }], 222 "links": {}, 223 "meta": { 224 "count": 1 225 } 226 } 227 ``` 228 229 This endpoint is paginated, default limit is currently `100`. 230 Two flags are available to retreieve the other konnectors if there are more than 231 `100` konnectors installed: 232 - `limit` 233 - `start_key`: The first following doc ID of the next konnectors 234 235 The `links` object contains a `ǹext` generated-link for the next docs. 236 237 #### Request 238 239 ```http 240 GET /konnectors/?limit=50 HTTP/1.1 241 Accept: application/vnd.api+json 242 ``` 243 244 #### Response 245 246 ```http 247 HTTP/1.1 200 OK 248 Content-Type: application/vnd.api+json 249 ``` 250 251 ```json 252 { 253 "data": [{ 254 "id": "4cfbd8be-8968-11e6-9708-ef55b7c20863", 255 "type": "io.cozy.konnectors", 256 "meta": { 257 "rev": "1-7a1f918147df94580c92b47275e4604a" 258 }, 259 "attributes": { 260 "name": "bank101", 261 "state": "installing", 262 "slug": "bank101", 263 ... 264 }, 265 "links": { 266 "self": "/konnectors/bank101" 267 } 268 }, {...}], 269 "links": { 270 "next": "http://alice.example.com/konnectors/?limit=50&start_key=io.cozy.konnectors%2Ffookonnector" 271 }, 272 "meta": { 273 "count": 50 274 } 275 } 276 ``` 277 278 ## Get informations about a konnector 279 280 ### GET /konnectors/:slug 281 282 This route is used to retrieve informations about a konnector installed on the cozy. By calling this route, the konnector will be updated synchronously. 283 284 285 #### Request 286 287 ```http 288 GET /konnectors/pajemploi HTTP/1.1 289 Accept: application/vnd.api+json 290 ``` 291 292 #### Response 293 294 ```http 295 HTTP/1.1 200 OK 296 Content-Type: application/vnd.api+json 297 ``` 298 299 ```json 300 { 301 "data": { 302 "type": "io.cozy.konnectors", 303 "id": "io.cozy.konnectors/pajemploi", 304 "attributes": { 305 "name": "Pajemploi", 306 "editor": "Cozy", 307 "icon": "icon.svg", 308 "type": "konnector", 309 "language": "node", 310 ... 311 }, 312 "meta": { 313 "rev": "8-1197cab1c9ecc89cef676567410cf7c5" 314 }, 315 "links": { 316 "self": "/konnectors/pajemploi", 317 "icon": "/konnectors/pajemploi/icon/1.5.2", 318 "permissions": "/permissions/konnectors/pajemploi" 319 } 320 } 321 } 322 ``` 323 324 ## Download the code of a konnector 325 326 This endpoint is used by the flagship app to download the code of a konnector, 327 in order to install it on the user's device. 328 329 ### GET /konnectors/:slug/download & GET /konnectors/:slug/download/:version 330 331 The first route will download a tarball of the source code of the latest 332 installed version of the konnector. The second route will force a specific 333 version of the konnector (and a 412 Precondition failed may be sent if the code 334 of this specific version is not available). 335 336 #### Request 337 338 ```http 339 GET /konnectors/pajemploi/download/3.0.1 HTTP/1.1 340 Authorization: Bearer flagship-token 341 Host: cozy.example.net 342 ``` 343 344 #### Response 345 346 ```http 347 HTTP/1.1 200 OK 348 Content-Type: application/gzip 349 ``` 350 351 When the konnector has been installed from the registry, the stack will respond 352 with a redirect to the registry. In that case, the downloaded tarball can be 353 gzipped or not (the registry allows both). When the konnector is installed from 354 another source, the stack will create a gzipped tarball and send it to the 355 client. 356 357 ## Uninstall a konnector 358 359 ### DELETE /konnectors/:slug 360 361 #### Request 362 363 ```http 364 DELETE /konnectors/bank101 HTTP/1.1 365 ``` 366 367 #### Response 368 369 ```http 370 HTTP/1.1 204 No Content 371 ``` 372 373 Or, if the konnector has still some accounts configured: 374 375 ```http 376 HTTP/1.1 202 Accepted 377 ``` 378 379 In this case, the stack will accept the uninstall request, then it will clean 380 the accounts (locally and remotely), and only after that, the konnector will be 381 removed. 382 383 ## Add a trigger 384 385 ### POST /konnectors/:slug/trigger 386 387 This endpoint creates a @cron trigger for the given konnector. The manifest is 388 used to generate the crontab. 389 390 #### Query-String 391 392 | Parameter | Description | 393 | --------- | ----------------------------------------------------------------------------- | 394 | AccountID | The identifier of the io.cozy.accounts that will be used to run the konnector | 395 | ExecNow | `true` if you want to run a job just after the trigger creation | 396 397 398 #### Request 399 400 ```http 401 POST /konnectors/pajemploi/trigger?AccountID=4eee63e069690139df83543d7eb8149c HTTP/1.1 402 ``` 403 404 #### Response 405 406 ```http 407 HTTP/1.1 201 Created 408 Content-Type: application/vnd.api+json 409 ``` 410 411 ```json 412 { 413 "data": { 414 "type": "io.cozy.triggers", 415 "id": "8cfeef1069690139df84543d7eb8149c", 416 "attributes": { 417 "type": "@cron", 418 "arguments": "0 9 3 * * 1", 419 "worker": "konnector", 420 "message": { 421 "account": "4eee63e069690139df83543d7eb8149c", 422 "konnector": "pajemploi" 423 } 424 }, 425 "links": { 426 "self": "/jobs/triggers/8cfeef1069690139df84543d7eb8149c" 427 } 428 } 429 } 430 ``` 431 432 ## Send konnector logs to cozy-stack 433 434 ### POST /konnectors/:slug/logs 435 436 Send client-side logs to cozy-stack so they can be stored in the server's 437 logging system. 438 439 #### Status codes 440 441 - 204 No Content, when all the log lines have been processed. 442 - 400 Bad-Request, when the JSON body is invalid. 443 - 404 Not Found, when no konnectors with the given slug could be found. 444 - 422 Unprocessable Entity, when the sent data is invalid (for example, the 445 slug is invalid or log level does not exist) 446 447 #### Request 448 449 ```http 450 POST /konnectors/pajemploi/logs HTTP/1.1 451 Accept: application/vnd.api+json 452 ``` 453 454 ```json 455 [ 456 { "timestamp": "2022-10-27T17:13:37.293Z", "level": "info", "msg": "Connecting to remote site..." }, 457 { "timestamp": "2022-10-27T17:13:38.382Z", "level": "error", "msg": "LOGIN_FAILED" } 458 ] 459 ``` 460 461 #### Response 462 463 ```http 464 HTTP/1.1 204 No Content 465 ``` 466