---
title: "Upsert a task (create when task_id is omitted, else update)"
method: POST
path: "/api/agent/sessions/{id}/tasks"
tags: ["Agent"]
---

# Upsert a task (create when task_id is omitted, else update)

`POST /api/agent/sessions/{id}/tasks`

## Request

- Base URL: `http://localhost:38200`
- URL: `http://localhost:38200/api/agent/sessions/{id}/tasks`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `token`

## Path parameters

- `id` integer, required

## Request body

- object
  - `task_id` integer: Omit to create; include to update.
  - `parent_task_id` integer
  - `title` string
  - `status` 'pending' | 'in_progress' | 'verified' | 'blocked' | 'skipped'
  - `verify_cmd` string
  - `order_index` integer
  - `context_id` integer
  - `goal_node_id` integer

## Response `200`

Updated task (task_id was supplied).

- AgentTask: The `agent_tasks` row — a hierarchical, verifiable checklist item for a session.
  - `id` integer
  - `tenantId` integer
  - `sessionId` integer
  - `parentTaskId` integer, nullable
  - `title` string
  - `status` 'pending' | 'in_progress' | 'verified' | 'blocked' | 'skipped'
  - `verifyCmd` string, nullable
  - `evidence` string, nullable
  - `orderIndex` integer
  - `contextId` integer, nullable
  - `goalNodeId` integer, nullable: Team-mode rollup to the project goal graph.
  - `createdAt` string, date-time
  - `updatedAt` string, date-time

## Other responses

- `201`: Created task (task_id was omitted).
- `400`: Request body/query failed Zod validation.
- `401`: Missing or invalid credentials.

---

[API](https://skmtc.dev/contextq/apis/contextq-api.md) · [All operations](https://skmtc.dev/contextq/apis/contextq-api/llms.txt) · [OpenAPI document](https://skmtc.dev/contextq/apis/contextq-api/revisions/7afc44056a22?raw)
