# Duplicate a task and its subtasks

`POST /api/task/{taskId}/duplicate`

URL: https://repsona.com/api/post-task-taskid-duplicate

Recursively duplicates a task and its subtasks. Comments and attachments are not duplicated.

## Parameters

| name | in | type | required | description |
| --- | --- | --- | --- | --- |
| `taskId` | path | integer | required | ID of the task. |

## Request body

| name | in | type | required | description |
| --- | --- | --- | --- | --- |
| `copyToProjectId` | body | integer \| null |  | ID of the project to copy into. Omit or `null` to copy within the same project. Statuses and milestones are not inherited when copying to another project. |
| `prefix` | body | string |  | Text added before each copied task name, for example `Copy of `. Defaults to an empty string. |
| `suffix` | body | string |  | Text added after each copied task name. Defaults to an empty string. |
| `startDate` | body | integer \| null |  | New start date as a Unix timestamp in milliseconds. The earliest date in the copied tree moves to this day and all other dates shift by the same amount. Only applies when `inherit.dueDate` is `true`. |
| `inherit` | body | object |  | Which properties of the original task the copies inherit. Anything not set to `true` is left empty. |

## Request

```sh
curl -X POST "https://<space>.repsona.com/api/task/{taskId}/duplicate" \
  -H "Authorization: Bearer $REPSONA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "copyToProjectId": null,
    "prefix": "Copy of ",
    "suffix": "",
    "startDate": 1796083200000,
    "inherit": {
      "priority": true,
      "tag": true,
      "responsibleUser": true,
      "ballHoldingUser": true,
      "status": true,
      "dueDate": true,
      "milestone": true
    }
  }'
```

## Responses

- 200: Duplicated tasks
- 400: Invalid body
- 401: Authentication is required
- 403: Not a project member
- 404: Task not found

## Example response

```json
{
  "tasks": [
    {
      "id": 100450,
      "parentId": null,
      "projectId": 296,
      "responsibleUserId": 1127,
      "ballHoldingUserId": null,
      "statusId": 195,
      "milestoneId": null,
      "sortOrder": 1024,
      "statusBoardSortOrder": null,
      "priorityBoardSortOrder": null,
      "responsibleUserBoardSortOrder": null,
      "ballHoldingUserBoardSortOrder": null,
      "milestoneBoardSortOrder": null,
      "name": "Copy of Publish the new homepage",
      "planned": null,
      "actual": null,
      "priority": null,
      "extra": null,
      "startDate": null,
      "dueDate": 1796083200000,
      "createdAt": 1793662651372,
      "updatedAt": 1793662651372,
      "deletedAt": null,
      "tagIds": [
        90,
        91
      ]
    }
  ]
}
```
