> For the complete documentation index, see [llms.txt](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/updateassessmentquery.md). Agents can also search and read this documentation through its [MCP server](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/~gitbook/mcp).

# Update a query

Replace a saved query with a full update, or change only its risk profiles, explanation, and remediation with a patch.

Changes a saved query. A full update replaces the query with the request body, so retrieve the query first and send back the whole object with your changes. A patch with an `update_mask` changes only the risk profiles, risk explanation, and risk remediation. To make a saved query filterable by the dashboard **Accounts** filter, see [Add account variables to a saved query](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/account-variables.md).

## Endpoint

```sh
PUT /api/v1/assessments/queries/{id}
PATCH /api/v1/assessments/queries/{id}
```

This endpoint requires one of these built-in [roles](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/administration/administration/users/roles.md): **Administrator**, **Access Reviews Admin**, **Operator**, or **NHI Security Admin**. Requests from other roles return `PermissionDenied`. OAuth2 client-credentials tokens can't call this endpoint.

{% openapi src="/files/Aco9gj4MY2XoNiD4zIjr" path="/api/v1/assessments/queries/{id}" method="put" %}
[openapi.yaml](https://1967633068-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZDkWMxox3pekd0NsZJ%2Fuploads%2Fgit-blob-7be9b9d3020988e9379a0e5e39ed089aa98633f5%2Fopenapi.yaml?alt=media)
{% endopenapi %}

{% openapi src="/files/Aco9gj4MY2XoNiD4zIjr" path="/api/v1/assessments/queries/{id}" method="patch" %}
[openapi.yaml](https://1967633068-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZDkWMxox3pekd0NsZJ%2Fuploads%2Fgit-blob-7be9b9d3020988e9379a0e5e39ed089aa98633f5%2Fopenapi.yaml?alt=media)
{% endopenapi %}

## Request

The path parameter names the query:

| Field | Type   | Required? | Description                          |
| ----- | ------ | --------- | ------------------------------------ |
| `id`  | string | Yes       | The ID of the saved query to change. |

Send every other field as a top-level key of the JSON body. For each field, see [Query Builder parameters](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/parameters.md#query-parameters). Both methods take the same body; what the request changes depends on `update_mask` (see [Update semantics](#update-semantics)):

| Field               | Type   | Required?                                      | Description                                                                                                                                                                                                                       |
| ------------------- | ------ | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `update_mask`       | string | No                                             | A comma-separated list of the fields to change, written in camel case, such as `"riskExplanation,riskRemediation"`. Accepts `riskProfiles`, `riskExplanation`, and `riskRemediation`. When omitted, the request is a full update. |
| `name`              | string | For a full update                              | The query name, 2 to 255 characters.                                                                                                                                                                                              |
| `description`       | string | For a full update                              | The query description, up to 16,383 characters.                                                                                                                                                                                   |
| `source_node_types` | object | For a full update, unless `union_specs` is set | The source entity type. It must match the stored query.                                                                                                                                                                           |

The body has no `risk_level`, `risk_suppressed_constraints`, or `query_type`, so an update keeps the stored values and drops those keys. It also drops read-only fields, such as `owners`, `variables`, and `result_type`, and the path `id` replaces any `id` in the body. You can send back the object that [Get a saved query](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/getassessmentquery.md) returns.

## Examples

Set `VEZA_URL` and `VEZA_TOKEN` as described in [API tokens](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/authentication/api-tokens.md), and set `QUERY_ID` to the query's ID:

```bash
QUERY_ID="<query_id>"
```

To change the description with a full update, retrieve the query and save its `value` object:

```bash
curl -s -X GET "$VEZA_URL/api/v1/assessments/queries/$QUERY_ID" \
  -H "Authorization: Bearer $VEZA_TOKEN" | jq '.value' > query.json
```

Edit the fields to change in `query.json`, for example with `jq`:

```bash
jq '.description = "Okta users who can use the Snowflake BILLING role. Reviewed quarterly."' \
  query.json > query-updated.json
```

Then send the whole object:

```bash
curl -X PUT "$VEZA_URL/api/v1/assessments/queries/$QUERY_ID" \
  -H "Authorization: Bearer $VEZA_TOKEN" \
  -H "Content-Type: application/json" \
  --data @query-updated.json
```

The response returns the updated query in `value`, in the same shape as [Save a query](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/createassessmentquery.md#examples). Example response (constructed from `UpdateAssessmentQueryResponse`), shortened to the changed and identifying fields:

```json
{
  "id": "<query_id>",
  "value": {
    "id": "<query_id>",
    "name": "Okta users with the Snowflake BILLING role",
    "description": "Okta users who can use the Snowflake BILLING role. Reviewed quarterly.",
    "query_type": "SOURCE_TO_DESTINATION",
    "visibility": "PRIVATE",
    "risk_level": "HIGH",
    "updated_at": "2026-11-18T22:40:07.215Z"
  }
}
```

To change only the risk explanation, send a patch with an `update_mask`. No other field changes, so the body needs only the fields in the mask:

```bash
curl -X PATCH "$VEZA_URL/api/v1/assessments/queries/$QUERY_ID" \
  -H "Authorization: Bearer $VEZA_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{
    "update_mask": "riskExplanation",
    "risk_explanation": "These users can read and export billing data in Snowflake."
  }'
```

The response returns the whole query in `value`, with the new `risk_explanation`.

## Update semantics

What the request changes depends on `update_mask`, not on the method. `PATCH` without an `update_mask` is a full update, the same as `PUT`.

**Full update (no `update_mask`).** Each field in the body replaces the stored value, and an omitted field is cleared or reset to its default. For example, an omitted `labels` clears the labels, and an omitted `risk_explanation` clears the explanation.

The update keeps the stored risk level, risk exceptions, query type, owners, and creator, and whether the query is hidden or disabled. It also keeps the stored risk profiles when the body sends none. Updating a Veza-created query marks it as edited; see [Reset a query](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/resetassessmentquery.md).

{% hint style="warning" %}
An omitted `visibility` saves as `PUBLIC`, so a full update without it makes a private query public. No update can make a public query private again.
{% endhint %}

**Patch (with `update_mask`).** Only the fields listed in `update_mask` change, and other keys in the body are ignored. The mask accepts only `riskProfiles`, `riskExplanation`, and `riskRemediation`. The new values are checked against the stored risk level, and an empty `risk_profiles` keeps the stored profiles.

## Errors and limits

The requests in the following table return `InvalidArgument` (HTTP 400), with the reason in `details[].field_violations`:

| Field                           | Cause                                                                                    | Message                                                                              |
| ------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `id`                            | Not a UUID                                                                               | `Must be a valid UUID`                                                               |
| `update_mask`                   | A field other than the risk profiles, explanation, or remediation                        | `field "<field>" cannot be patched; use a full update`                               |
| `name`, `description`           | Empty in a full update                                                                   | `Cannot be empty`                                                                    |
| `name`                          | One character                                                                            | `Must be longer than 1`                                                              |
| `Name`                          | Another saved query has the new name                                                     | `Cannot rename query to <name>. A query with this name already exists.`              |
| `visibility`                    | A public query changed to `PRIVATE`                                                      | `can't change from public to private`                                                |
| `source_node_types`             | A different source entity type                                                           | `can't change node types`                                                            |
| `<entity type>.condition.value` | A condition uses the results of the query being updated                                  | `Condition value has the same ID as the input query (id: <query_id>)`                |
| `source_node_types`             | The query uses its own results through other saved queries                               | `circular dependency found in query`                                                 |
| `relates_to_exp`                | A different structure or different entity types, except on `SEGREGATION_OF_DUTY` queries | `can't change expression structure or node types`                                    |
| `analysis_type`                 | A different analysis type, other than `UNSET` or `QUERY_PIPELINE`                        | `Can't change analysis type`                                                         |
| `save_mode`                     | `QUERY_BUILDER` on a query saved in `VQL_EDITOR` mode                                    | `Cannot switch from VQL Editor to Query Builder mode`                                |
| `risk_explanation`              | Set on a query whose risk level is `NONE`                                                | `Risk explanation cannot be set when RiskLevel is NONE.`                             |
| `risk_remediation`              | Set on a query whose risk level is `NONE`                                                | `Risk remediation cannot be set when RiskLevel is NONE.`                             |
| `risk_profiles`                 | `INFORMATIONAL` on a query whose risk level isn't `NONE`                                 | `INFORMATIONAL risk profile can only be assigned to queries with NONE risk level`    |
| `risk_profiles`                 | Another profile on a query whose risk level is `NONE`                                    | `non-INFORMATIONAL risk profiles cannot be assigned to queries with NONE risk level` |
| `risk_profiles`                 | More than one profile on a user-created query                                            | `List has a max length of 1`                                                         |

An `update_mask` path in snake case, such as `"risk_explanation"`, also returns `InvalidArgument` (HTTP 400), with no field violation. The error's `message` names the path, for example `proto: (line 1:17): google.protobuf.FieldMask.paths contains invalid path: "risk_explanation"`. An `update_mask` sent as an object, such as `{"paths": [...]}`, is rejected the same way.

These requests return other codes:

* An `id` that matches no saved query, or another user's private query, returns `NotFound` (HTTP 404).
* A caller who isn't the query's creator or an owner gets `PermissionDenied` (HTTP 403), unless the caller is an Administrator or the query has no owners.
* A query that Veza marks as not editable, or a query shared with your team from another team, returns `PermissionDenied` (HTTP 403).

For shared status codes and the error body, see [Troubleshooting](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/errors.md).

To create a saved query, see [Save a query](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/createassessmentquery.md). To change its owners, see [Update query owners](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/updateassessmentquerypermissions.md), and to restore a Veza-created query, see [Reset a query](https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/resetassessmentquery.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.veza.com/4yItIzMvkpAvMVFAamTf/developers/api/query-builder/updateassessmentquery.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
