---
title: "Export a completed goal subtree as a portable template"
method: POST
path: "/api/goal/export-template"
tags: ["Goal"]
---

# Export a completed goal subtree as a portable template

`POST /api/goal/export-template`

## Request

- Base URL: `http://localhost:38200`
- URL: `http://localhost:38200/api/goal/export-template`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `token`

T143. Template-local ids (0-based) replace database ids; the template is self-contained. Optionally persisted as a GLOBAL (or tenant) workspace reference context for cross-project reuse.

## Request body

- object
  - `root_node_id` integer, required
  - `save_as_context` boolean
  - `save_global` boolean: Requires write scope; persists to the GLOBAL workspace instead of the caller's tenant.

## Response `200`

Export result.

- object
  - `template` object
    - `schemaVersion` 1
    - `label` string
    - `rootTemplateId` integer
    - `nodes` object[]
    - `edges` object[]
  - `contextId` integer, nullable
  - `externalId` string, nullable
  - `warning` string: Present when save_global=true was used.

## Other responses

- `400`: Request body/query failed Zod validation.
- `401`: Missing or invalid credentials.
- `404`: Resource not found (or not visible to the caller).

---

[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)
