# Make many feedback changes at once, previewed first, saved as one change that one undo reverses (/api/feedback/apply_feedback_changes)

`POST /v1/products/{productId}/feedback-changes/bulk`

Operation name: `apply_feedback_changes`

For sorting feedback: an ordered list of the single changes (`update_insight`, `move_insight`, `rename_topic`, `merge_topic`), each step one object with `op` set to that tool's name and that tool's inputs, its insight or topic id included. Each step runs exactly as its tool would, on the feedback as the earlier steps left it, with the same rules: only insights linked to a feature (or New opportunity) of processed records can move; a topic merges only into another under the same feature, or both under New opportunity; a moved insight leaves its topic and the AI groups it at its new place after the save (so a later step does not find it in a topic there), unless the step moves it into a chosen topic. A topic can't move as a whole: move its insights, one step each; a topic of more than 50 insights takes several bulk changes, each with its own undo.

Work in two calls. Find the ids with `search`, `list_feature_topics`, `list_topic_insights` or `list_source_records`, keeping the read's `meta.feedbackVersion`, and send the steps with `dryRun: true` and that 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`: a move to where the insight already is, the type, sentiment or name it already has), every step that would be refused with the reason and rule (`problems`), and each topic the steps name as it would be after them (`topics`: name, feature, how many insights it shows, the topic it was merged into). 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 <n>: " and `details.step` naming it. A save answers the one feedback change it stored, listing every step, and the feedback's new `version`; when every step was skipped nothing is stored and `change` is null. The save checks every step again: background work (grouping, linking, new feedback) does not change the version, so topic counts and the AI's topics may differ from the preview by then. One `undo_feedback_change` on that change reverses all of it; it can't be redone.

At most 50 steps per request: split larger work into several bulk changes. `expectedVersion` refuses the call (`conflict`) when anyone stored a feedback change since you read it; read 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 feedback change, it is yours and it is not undone; after someone else's change it is a new save, where moves and edits already made are skipped and merges already made are refused as not found. Product Owners and Admins only; Viewers are refused, also for a preview.

## Authentication

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.

Or: An API key, sent as `Authorization: Bearer ha_…` (keys made before the rename to Heuristic start `fsa_` and keep working). Keys are created only in the Heuristic web app and shown once. A personal key (Settings → Personal → My API keys) acts as its person in one of their organizations, with exactly their access there, checked on every call; its calls count toward the person's limits on calls through apps and agents, as described for OAuth tokens, and it can't change the person's account (their profile, organizations, invitations or connected apps). An organization key (Settings → Organization → API keys, created by Admins) acts for the organization, not a person: it can see and change every product and its feedback as an Admin can, but not people, product access, CRM connections or the organization's settings, and it can't delete a product; each organization key has its own limits, with the same numbers. Either kind is Full access or Read only (a change with a read-only key answers 403 `read_only_key`), reaches only its own organization (others answer 404), works on /v1 only, not on the MCP server, and can't create keys or manage the organization's API keys. Other refused calls answer 403 `api_key_not_allowed`. A wrong, expired or revoked key, or a disabled member's personal key, answers 401 `unauthorized`. A full-access key sends feedback: a personal key as its person, to the products they own; an organization key to any product of its organization; the record's `sentBy` names the key.

## Path parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `productId` | path | string | yes | A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`. |

## Request body

Content type: `application/json` (required)

```json
{
  "type": "object",
  "properties": {
    "steps": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "op": {
                "type": "string",
                "enum": [
                  "update_insight"
                ],
                "description": "`update_insight`: change an insight's type or sentiment."
              },
              "insightId": {
                "type": "string",
                "format": "uuid",
                "description": "The insight to change. A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`.",
                "x-feedstack-id": true
              },
              "type": {
                "type": "string",
                "enum": [
                  "feature_request",
                  "bug",
                  "praise",
                  "complaint",
                  "question"
                ],
                "description": "What kind of feedback it is: feature_request, bug, praise, complaint or question."
              },
              "sentiment": {
                "type": "string",
                "enum": [
                  "positive",
                  "neutral",
                  "negative"
                ],
                "description": "How the customer feels: positive, neutral or negative."
              }
            },
            "required": [
              "op",
              "insightId"
            ]
          },
          {
            "type": "object",
            "properties": {
              "op": {
                "type": "string",
                "enum": [
                  "move_insight"
                ],
                "description": "`move_insight`: move an insight to a feature, New opportunity or a topic."
              },
              "insightId": {
                "type": "string",
                "format": "uuid",
                "description": "The insight to change. A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`.",
                "x-feedstack-id": true
              },
              "featureId": {
                "type": "string",
                "format": "uuid",
                "description": "Move it to this feature; the AI then groups it into a topic there. A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`.",
                "x-feedstack-id": true
              },
              "newOpportunity": {
                "type": "boolean",
                "enum": [
                  true
                ],
                "description": "true: move it to New opportunity, for feedback that matches no feature."
              },
              "topicId": {
                "type": "string",
                "format": "uuid",
                "description": "Move it into this topic, and so to the topic's feature. A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`.",
                "x-feedstack-id": true
              }
            },
            "required": [
              "op",
              "insightId"
            ]
          },
          {
            "type": "object",
            "properties": {
              "op": {
                "type": "string",
                "enum": [
                  "rename_topic"
                ],
                "description": "`rename_topic`: rename a topic."
              },
              "topicId": {
                "type": "string",
                "format": "uuid",
                "description": "The topic to change. A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`.",
                "x-feedstack-id": true
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 50,
                "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029]*$",
                "description": "The topic's new name, 1 to 50 characters on one line."
              }
            },
            "required": [
              "op",
              "topicId",
              "name"
            ]
          },
          {
            "type": "object",
            "properties": {
              "op": {
                "type": "string",
                "enum": [
                  "merge_topic"
                ],
                "description": "`merge_topic`: merge a topic into another under the same feature."
              },
              "topicId": {
                "type": "string",
                "format": "uuid",
                "description": "The topic to merge away. A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`.",
                "x-feedstack-id": true
              },
              "intoId": {
                "type": "string",
                "format": "uuid",
                "description": "The topic to merge into. A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`.",
                "x-feedstack-id": true
              }
            },
            "required": [
              "op",
              "topicId",
              "intoId"
            ]
          }
        ]
      },
      "minItems": 1,
      "maxItems": 50,
      "description": "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, its insight or topic id included."
    },
    "dryRun": {
      "type": "boolean",
      "description": "true: save nothing and answer the outcome (changes, skipped and refused steps, the topics touched)."
    },
    "expectedVersion": {
      "type": "string",
      "description": "The `meta.feedbackVersion` from the read you planned from (or a dry run's `version`); refused when the feedback changed since."
    }
  },
  "required": [
    "steps"
  ],
  "description": "An ordered list of feedback changes, previewed with `dryRun` or saved as one change."
}
```

## Responses

### 200

The preview, or the saved change

```json
{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "properties": {
        "dryRun": {
          "type": "boolean"
        },
        "version": {
          "type": "string"
        },
        "change": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "id": {
              "type": "string"
            },
            "kind": {
              "type": "string",
              "enum": [
                "edit",
                "move",
                "rename",
                "merge",
                "undo",
                "bulk"
              ]
            },
            "subject": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "insight",
                    "topic",
                    "product"
                  ]
                },
                "id": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                }
              },
              "required": [
                "type",
                "id",
                "label"
              ]
            },
            "details": {
              "type": "object",
              "properties": {
                "fields": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "field": {
                        "type": "string",
                        "enum": [
                          "type",
                          "sentiment",
                          "name"
                        ]
                      },
                      "before": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "after": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "field",
                      "before"
                    ]
                  }
                },
                "from": {
                  "type": "object",
                  "properties": {
                    "feature": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "title": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "id",
                        "title"
                      ]
                    },
                    "topic": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ]
                    }
                  },
                  "required": [
                    "feature",
                    "topic"
                  ]
                },
                "to": {
                  "type": "object",
                  "properties": {
                    "feature": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "title": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "id",
                        "title"
                      ]
                    },
                    "topic": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ]
                    }
                  },
                  "required": [
                    "feature",
                    "topic"
                  ]
                },
                "into": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "insights": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "insights"
                  ]
                },
                "stepCount": {
                  "type": "integer"
                },
                "steps": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "step": {
                        "type": "integer"
                      },
                      "kind": {
                        "type": "string",
                        "enum": [
                          "edit",
                          "move",
                          "rename",
                          "merge"
                        ]
                      },
                      "subject": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "enum": [
                              "insight",
                              "topic"
                            ]
                          },
                          "id": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "type",
                          "id",
                          "label"
                        ]
                      },
                      "details": {
                        "type": "object",
                        "properties": {
                          "fields": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "field": {
                                  "type": "string",
                                  "enum": [
                                    "type",
                                    "sentiment",
                                    "name"
                                  ]
                                },
                                "before": {
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                },
                                "after": {
                                  "type": [
                                    "string",
                                    "null"
                                  ]
                                }
                              },
                              "required": [
                                "field",
                                "before"
                              ]
                            }
                          },
                          "from": {
                            "type": "object",
                            "properties": {
                              "feature": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "properties": {
                                  "id": {
                                    "type": "string"
                                  },
                                  "title": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "id",
                                  "title"
                                ]
                              },
                              "topic": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "properties": {
                                  "id": {
                                    "type": "string"
                                  },
                                  "name": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "id",
                                  "name"
                                ]
                              }
                            },
                            "required": [
                              "feature",
                              "topic"
                            ]
                          },
                          "to": {
                            "type": "object",
                            "properties": {
                              "feature": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "properties": {
                                  "id": {
                                    "type": "string"
                                  },
                                  "title": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "id",
                                  "title"
                                ]
                              },
                              "topic": {
                                "type": [
                                  "object",
                                  "null"
                                ],
                                "properties": {
                                  "id": {
                                    "type": "string"
                                  },
                                  "name": {
                                    "type": "string"
                                  }
                                },
                                "required": [
                                  "id",
                                  "name"
                                ]
                              }
                            },
                            "required": [
                              "feature",
                              "topic"
                            ]
                          },
                          "into": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string"
                              },
                              "name": {
                                "type": "string"
                              },
                              "insights": {
                                "type": "integer"
                              }
                            },
                            "required": [
                              "id",
                              "name",
                              "insights"
                            ]
                          }
                        }
                      }
                    },
                    "required": [
                      "step",
                      "kind",
                      "subject",
                      "details"
                    ]
                  }
                }
              }
            },
            "undoesChangeId": {
              "type": [
                "string",
                "null"
              ]
            },
            "undoneAt": {
              "type": [
                "string",
                "null"
              ]
            },
            "createdAt": {
              "type": "string"
            },
            "createdBy": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "name"
              ]
            },
            "via": {
              "type": "string",
              "enum": [
                "web",
                "app",
                "not_recorded"
              ]
            },
            "app": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "clientId": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              },
              "required": [
                "clientId",
                "name"
              ]
            }
          },
          "required": [
            "id",
            "kind",
            "subject",
            "details",
            "undoesChangeId",
            "undoneAt",
            "createdAt",
            "createdBy",
            "via",
            "app"
          ]
        },
        "changes": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "properties": {
              "step": {
                "type": "integer"
              },
              "kind": {
                "type": "string",
                "enum": [
                  "edit",
                  "move",
                  "rename",
                  "merge"
                ]
              },
              "subject": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "insight",
                      "topic"
                    ]
                  },
                  "id": {
                    "type": "string"
                  },
                  "label": {
                    "type": "string"
                  }
                },
                "required": [
                  "type",
                  "id",
                  "label"
                ]
              },
              "details": {
                "type": "object",
                "properties": {
                  "fields": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "field": {
                          "type": "string",
                          "enum": [
                            "type",
                            "sentiment",
                            "name"
                          ]
                        },
                        "before": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "after": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      },
                      "required": [
                        "field",
                        "before"
                      ]
                    }
                  },
                  "from": {
                    "type": "object",
                    "properties": {
                      "feature": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "title"
                        ]
                      },
                      "topic": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "name"
                        ]
                      }
                    },
                    "required": [
                      "feature",
                      "topic"
                    ]
                  },
                  "to": {
                    "type": "object",
                    "properties": {
                      "feature": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "title"
                        ]
                      },
                      "topic": {
                        "type": [
                          "object",
                          "null"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "name"
                        ]
                      }
                    },
                    "required": [
                      "feature",
                      "topic"
                    ]
                  },
                  "into": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      },
                      "insights": {
                        "type": "integer"
                      }
                    },
                    "required": [
                      "id",
                      "name",
                      "insights"
                    ]
                  }
                }
              }
            },
            "required": [
              "step",
              "kind",
              "subject",
              "details"
            ]
          }
        },
        "skipped": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "step": {
                "type": "integer"
              },
              "reason": {
                "type": "string"
              }
            },
            "required": [
              "step",
              "reason"
            ]
          }
        },
        "problems": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "step": {
                "type": "integer"
              },
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object",
                "additionalProperties": {}
              }
            },
            "required": [
              "step",
              "code",
              "message"
            ]
          }
        },
        "topics": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "feature": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  }
                },
                "required": [
                  "id",
                  "title"
                ]
              },
              "insights": {
                "type": "integer"
              },
              "mergedIntoId": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "name",
              "feature",
              "insights",
              "mergedIntoId"
            ]
          }
        }
      },
      "required": [
        "dryRun",
        "version",
        "change",
        "changes",
        "skipped",
        "problems",
        "topics"
      ]
    },
    "meta": {
      "type": "object",
      "additionalProperties": {}
    }
  },
  "required": [
    "data",
    "meta"
  ]
}
```

### 400

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 401

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 403

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 404

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 409

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

## Example request

```bash
curl -X POST "https://staging.heuristic.app/v1/products/{productId}/feedback-changes/bulk" \
  -H "Authorization: Bearer <access token>" \
  -H "Content-Type: application/json" \
  -d '{"steps":[{"op":"update_insight","insightId":"00000000-0000-4000-8000-000000000000","type":"feature_request","sentiment":"positive"}],"dryRun":false,"expectedVersion":"string"}'
```
