---
title: "Add task(s) to the Actions collection."
method: POST
path: "/api/actions"
tags: ["Actions"]
---

# Add task(s) to the Actions collection.

`POST /api/actions`

Input to add one or more *Task* items to the *Actions* collection (in other words, enqueue).

## Condition
- requires all items in the list to be valid *Task* items with all required attributes;
  otherwise rejects whole list and returns 422 Conflict.
- requires the *Actions* collection to have free memory slots to enqueue the new items;
  completed, stopped, or failed items in the collection may be removed (oldest first);
  otherwise,
    - if number of items send by client exceeds maximum number of items in collection, rejects whole list and returns 409 Conflict
    - else if not enough items can be freed, rejects whole list and returns 503 Service Unavailable

## On Success
- enqueues the tasks given in the `data` array
- each *Task* item is given a unique `id`
- each *Task* item is given a `status` attribute that is initialized with `pending`
- returns 200 OK listing all items enqueued with ID and status

## On Failure
Returns one of the following:
- 409 Conflict, when the request contains more items than the maximum total number of items for the collection
- 415 Unsupported Media Type, when the request content type is not `application/vnd.api+json`, TODO: allow `application/json` or empty (tolerant server)
- 422 Unprocessable Content, when invalid items are included or required task-specific attributes are missing
- 503 Service Unavailable, when no more items can be enqueued (but the number of items in the request does not exceed the maximum)

## General Background Logic (amended by task-specific background logic)
- when a *Task* item is executed, its `status` attribute changes to `active`
- when a *Task* item completes successfully, its `status` attribute changes to `completed`
- when a *Task* item completes unsuccessfully, its `status` attribute changes to `stopped`
- when a *Task* item fails, its `status` attribute changes to `failed`

## Response `200`

Task accepted and queue for execution.

## Other responses

- `400` — The client sent an invalid request. The client SHOULD perform action(s) to provide valid syntax before retrying the request.
- `408` — The client request took too long to process. The client SHOULD perform action(s) validate correctness of the request and retry the validated request after a longer period of time.
- `409` — The request conflicts with the current state of the target resource; either the request body cannot be applied to the resource state or the resource state cannot satisfy the request. The client SHOULD perform action(s) to re-synchronize application state before retrying the request.
- `415` — The client sent a request body in an unsupported format. The client SHOULD change the request body format before retrying the request.
- `422` — The server understands the content type of the request body correct, but was unable to process the contained information. The client SHOULD perform action(s) to correct the request body before retrying the request.
- `500` — The server encountered an unexpected error. The client SHOULD retry after a longer period of time.
- `503` — The server is not ready to handle the request. The client SHOULD retry after a short period of time.

---

[API](https://skmtc.net/openthread/apis/swagger-openthread-rest-api.md) · [All operations](https://skmtc.net/openthread/apis/swagger-openthread-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/openthread/swagger-openthread-rest-api/revisions/7996e8479177/schema)
