Skip to Content
Heuristic documentation

Make many hierarchy changes at once, previewed first, saved as one change that one undo reverses

POST
/v1/products/{productId}/hierarchy/changes

For restructuring: an ordered list of the single changes (create_category, create_feature, update_category, update_feature, merge_category, merge_feature, delete_category, delete_feature), each step one object with op set to that tool's name and that tool's inputs. Each step runs exactly as its tool would, on the tree as the earlier steps left it, with the same rules: a category holds either subcategories or features, never both; it never goes under itself; moving a category into one holding features puts those features into a new subcategory "Other"; moved items keep their names; sibling order can't be set. Plan the order: create the new categories first (choose each a new uuid as id so later steps can name it), then move features and categories into them, then merge or delete what is left.

Work in two calls. First find the ids with search or a compact get_hierarchy (its version is the same on every page of one read), and send the steps with dryRun: true and its version as expectedVersion: nothing is saved, and the answer lists what each step would change (changes, each edited field with its value before; the value after is the one the step sends), steps that would change nothing and are skipped (skipped: the same text, a move to where it already is, an add of an item a person already added with the same values), every step that would be refused with the rule and the ids of allowed places (problems), and the resulting tree where the steps act (tree: the categories the steps and problems name, each with every category above it, the features the preview names in order and its featureCount; the rest of a category: get_hierarchy with its categoryId; then the named features in no category, withoutCategory), which names those ids (a place a later step removes is left out; read it with get_hierarchy). Show the person the outcome. Then send the same steps without dryRun: every step is saved or none. The first refused step stops it, nothing is saved, and the answer is that step's refusal, its message starting "Step : " and details.step naming it. A save answers the one hierarchy change it stored, listing every step, and the hierarchy's new version; when every step was skipped nothing is stored and change is null. One undo_hierarchy_change on that change reverses all of it, and undoing that undo does it all again.

At most 50 steps and 64 KB per request: split larger work into several bulk changes. expectedVersion refuses the call (conflict) when the hierarchy changed since you read it, by anyone or by a knowledge base read; read get_hierarchy again, check the plan and send the new version. A retry is safe: sending the same save again (after a lost answer) answers the first result and changes nothing, while it is the product's newest change, it is yours and it is not undone. Product Owners and Admins only; Viewers are refused, also for a preview.

Authorization

headerAuthorizationBearer <token>

An OAuth access token for the person who allowed your tool: register a client, then the authorization code flow with PKCE (S256). Send it as Authorization: Bearer <token> on every route that needs a signed-in person. Calls with a token are limited per person, across all their apps, to 120 calls a minute and 10,000 a UTC day; calls that start AI runs or knowledge base reads (creating an organization, starting a knowledge base read, rebuilding categories, retrying topics or rechecking) also to 10 a minute and 200 a UTC day. Over a limit a call answers 429 rate_limited with Retry-After and details.retryAfter in seconds, and changes nothing.

Path Parameters

productId*string

A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 validation_error.

Formatuuid

Request Body

application/json
  1. body

An ordered list of hierarchy changes, previewed with dryRun or saved as one change.

steps*array<|||||||>

The changes to make, in order, 1 to 50. Each is one object: op names the kind of change and the other fields are its inputs. Later steps may name ids earlier steps chose.

Items1 <= items <= 50
dryRun?boolean

true: save nothing and answer the outcome (changes, skipped and refused steps, the resulting tree).

expectedVersion?string

The version from get_hierarchy (or a dry run) you planned from; refused when the hierarchy changed since.

Response Body

The preview, or the saved change

application/json
  1. response
data*
meta*
Example Request
curl -X POST 'https://staging.heuristic.app/v1/products/497f6eca-6276-4993-bfeb-53cbbbba6f08/hierarchy/changes' \  -H 'Authorization: Bearer <access token>' \  -H 'Content-Type: application/json' \  -d '{  "steps": [    {      "title": "string",      "parentId": "70850378-7d3c-4f45-91b7-942d4dfbbd43",      "op": "create_category"    }  ]}'
Example Response
{  "data": {    "dryRun": true,    "version": "string",    "change": {      "id": "string",      "kind": "edit",      "subject": {        "type": "category",        "id": "string",        "title": "string"      },      "details": {        "fields": [          {            "field": "title",            "before": "string",            "after": "string"          }        ],        "from": {          "id": "string",          "title": "string"        },        "to": {          "id": "string",          "title": "string"        },        "into": {          "id": "string",          "title": "string"        },        "categories": 0,        "features": 0,        "parent": {          "id": "string",          "title": "string"        },        "other": {          "id": "string",          "title": "string"        },        "stepCount": 0,        "steps": [          {            "step": 0,            "kind": "edit",            "subject": {              "type": "category",              "id": "string",              "title": "string"            },            "details": {              "fields": [                {                  "field": "title",                  "before": "string",                  "after": "string"                }              ],              "from": {                "id": "string",                "title": "string"              },              "to": {                "id": "string",                "title": "string"              },              "into": {                "id": "string",                "title": "string"              },              "categories": 0,              "features": 0,              "parent": {                "id": "string",                "title": "string"              },              "other": {                "id": "string",                "title": "string"              }            }          }        ]      },      "undoesChangeId": "string",      "undoneAt": "string",      "createdAt": "string",      "createdBy": {        "id": "string",        "name": "string"      },      "via": "web",      "app": {        "clientId": "string",        "name": "string"      }    },    "changes": [      {        "step": 0,        "kind": "edit",        "subject": {          "type": "category",          "id": "string",          "title": "string"        },        "details": {          "fields": [            {              "field": "title",              "before": "string",              "after": "string"            }          ],          "from": {            "id": "string",            "title": "string"          },          "to": {            "id": "string",            "title": "string"          },          "into": {            "id": "string",            "title": "string"          },          "categories": 0,          "features": 0,          "parent": {            "id": "string",            "title": "string"          },          "other": {            "id": "string",            "title": "string"          }        }      }    ],    "skipped": [      {        "step": 0,        "reason": "string"      }    ],    "problems": [      {        "step": 0,        "code": "string",        "message": "string",        "details": {          "property1": null,          "property2": null        }      }    ],    "tree": {      "categories": [        {          "id": "string",          "title": "string",          "parentId": "string",          "features": [            {              "id": "string",              "title": "string"            }          ],          "featureCount": 0        }      ],      "withoutCategory": [        {          "id": "string",          "title": "string"        }      ]    },    "moving": [      {        "step": 0,        "insights": 0,        "to": {          "type": "new_opportunity"        }      }    ]  },  "meta": {    "property1": null,    "property2": null  }}