{"_id":"59778bb932f043002002f5de","category":{"_id":"59778bb932f043002002f5d5","version":"59778bb932f043002002f5d3","project":"5425e663ffd4411c319a65b4","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-09-29T20:18:57.785Z","from_sync":false,"order":1,"slug":"reference","title":"Reference"},"project":"5425e663ffd4411c319a65b4","user":"5425e31affd4411c319a65b1","version":{"_id":"59778bb932f043002002f5d3","project":"5425e663ffd4411c319a65b4","__v":1,"createdAt":"2017-07-25T18:19:37.272Z","releaseDate":"2017-07-25T18:19:37.272Z","categories":["59778bb932f043002002f5d4","59778bb932f043002002f5d5"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.5.0","version":"2.5"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-03T23:51:26.547Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":16,"body":"Containers are an abstraction which describes task assignment. A container is an ordered list of tasks. Tasks always belong to exactly one container -- once created and when reassigned. When a task is started by a worker, it is no longer part of that container's tasks. Organizations, teams and workers all correspond to containers as they can all be assigned tasks.\n\nThe generic way to perform assignment operations is by using a container endpoint. \n\nConceptually, a container mutation operation allows you to alter the tasks which are in a container, either by setting the list or by inserting new tasks into the list.\n\nWhen setting tasks in a container, newly included tasks will be removed from other containers. When a task is removed from a container implicitly by omission (for example, setting a container to include tasks A and C when it previously included A, B, and C, thus removing B), this task will be appended to the organization container for the task's executor organization.\n\nLikewise, when inserting tasks into a container, newly included tasks will be removed from other containers.\n\nYou can perform advanced assignment operations by interacting with a container's ```tasks``` array property directly.\n\nA single endpoint allows for these interactions: ```PUT /containers/:containerType/:entityId```, where `containerType` is either ```organizations```, ```teams``` or ```workers``` and `entityId` is the ID of the entity with the given type against which to perform the assignment operations.\n\nThe following examples show all of the possible container assignment cases.\n[block:api-header]\n{\n  \"type\": \"put\",\n  \"title\": \"Insert tasks at index (or append)\"\n}\n[/block]\nYou may insert one or more tasks at a given index by providing the index as the first element in the array, followed by the task IDs. To append to the end, use ```-1``` as your index. To prepend, use ```0```.\n\nFor example, if you want to insert two tasks at position 3 for a given worker, such that all currently assigned tasks at ```index >= 3``` are shifted forward, you would make the following request:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ curl -X PUT \\\"https://onfleet.com/api/v2/containers/workers/2Fwp6wS5wLNjDn36r1LJPscA\\\" \\\\\\n     -u \\\"cd3b3de84cc1ee040bf06512d233719c:\\\" \\\\\\n     -d '{\\\"tasks\\\":[3,\\\"l33lg5WLrja3Tft*MO383Gub\\\",\\\"tsc4jFSETlXBIvi8XotH28Wt\\\"]}'\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"HTTP/1.1 200 OK\",\n      \"language\": \"http\"\n    }\n  ]\n}\n[/block]\nNote that, had one of the provided IDs been found at an index less than ```3```, this ID would have been removed from its original index and inserted as per the request's insertion order.\n[block:api-header]\n{\n  \"type\": \"put\",\n  \"title\": \"Update tasks\"\n}\n[/block]\nYou may also fully replace a container's tasks by omitting the index and providing a complete list of task IDs.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ curl -X PUT \\\"https://onfleet.com/api/v2/containers/workers/2Fwp6wS5wLNjDn36r1LJPscA\\\" \\\\\\n     -u \\\"cd3b3de84cc1ee040bf06512d233719c:\\\" \\\\\\n     -d '{\\\"tasks\\\":[\\\"b3F~z2sU7H*auNKkM6LoiXzP\\\",\\\"1ry863mrjoQaqMNxnrD5YvxH\\\",\\\"l33lg5WLrja3Tft*MO383Gub\\\"]}'\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"HTTP/1.1 200 OK\",\n      \"language\": \"http\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Additional options\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"considerDependencies\",\n    \"0-1\": \"boolean\",\n    \"0-2\": \"Optional. Whether to include the target task's dependency family (parent and child tasks) in the resulting assignment operation.\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]","excerpt":"","slug":"containers","type":"basic","title":"Containers"}
Containers are an abstraction which describes task assignment. A container is an ordered list of tasks. Tasks always belong to exactly one container -- once created and when reassigned. When a task is started by a worker, it is no longer part of that container's tasks. Organizations, teams and workers all correspond to containers as they can all be assigned tasks. The generic way to perform assignment operations is by using a container endpoint. Conceptually, a container mutation operation allows you to alter the tasks which are in a container, either by setting the list or by inserting new tasks into the list. When setting tasks in a container, newly included tasks will be removed from other containers. When a task is removed from a container implicitly by omission (for example, setting a container to include tasks A and C when it previously included A, B, and C, thus removing B), this task will be appended to the organization container for the task's executor organization. Likewise, when inserting tasks into a container, newly included tasks will be removed from other containers. You can perform advanced assignment operations by interacting with a container's ```tasks``` array property directly. A single endpoint allows for these interactions: ```PUT /containers/:containerType/:entityId```, where `containerType` is either ```organizations```, ```teams``` or ```workers``` and `entityId` is the ID of the entity with the given type against which to perform the assignment operations. The following examples show all of the possible container assignment cases. [block:api-header] { "type": "put", "title": "Insert tasks at index (or append)" } [/block] You may insert one or more tasks at a given index by providing the index as the first element in the array, followed by the task IDs. To append to the end, use ```-1``` as your index. To prepend, use ```0```. For example, if you want to insert two tasks at position 3 for a given worker, such that all currently assigned tasks at ```index >= 3``` are shifted forward, you would make the following request: [block:code] { "codes": [ { "code": "$ curl -X PUT \"https://onfleet.com/api/v2/containers/workers/2Fwp6wS5wLNjDn36r1LJPscA\" \\\n -u \"cd3b3de84cc1ee040bf06512d233719c:\" \\\n -d '{\"tasks\":[3,\"l33lg5WLrja3Tft*MO383Gub\",\"tsc4jFSETlXBIvi8XotH28Wt\"]}'", "language": "shell" } ] } [/block] [block:code] { "codes": [ { "code": "HTTP/1.1 200 OK", "language": "http" } ] } [/block] Note that, had one of the provided IDs been found at an index less than ```3```, this ID would have been removed from its original index and inserted as per the request's insertion order. [block:api-header] { "type": "put", "title": "Update tasks" } [/block] You may also fully replace a container's tasks by omitting the index and providing a complete list of task IDs. [block:code] { "codes": [ { "code": "$ curl -X PUT \"https://onfleet.com/api/v2/containers/workers/2Fwp6wS5wLNjDn36r1LJPscA\" \\\n -u \"cd3b3de84cc1ee040bf06512d233719c:\" \\\n -d '{\"tasks\":[\"b3F~z2sU7H*auNKkM6LoiXzP\",\"1ry863mrjoQaqMNxnrD5YvxH\",\"l33lg5WLrja3Tft*MO383Gub\"]}'", "language": "shell" } ] } [/block] [block:code] { "codes": [ { "code": "HTTP/1.1 200 OK", "language": "http" } ] } [/block] [block:api-header] { "title": "Additional options" } [/block] [block:parameters] { "data": { "h-0": "Name", "h-1": "Type", "h-2": "Description", "0-0": "considerDependencies", "0-1": "boolean", "0-2": "Optional. Whether to include the target task's dependency family (parent and child tasks) in the resulting assignment operation." }, "cols": 3, "rows": 1 } [/block]