> ## Documentation Index
> Fetch the complete documentation index at: https://developer.vanta.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create and update risk scenarios

> Create risk scenarios in a specific register, set custom fields, and update them via the Manage Vanta API, including the common 400 errors most integrations encounter.

This guide creates and updates risk scenarios via `POST /v1/risk-scenarios` and `PATCH /v1/risk-scenarios/{riskScenarioId}` on the Manage Vanta API. It covers the three areas where most integrations run into errors: targeting a specific **risk register**, setting **custom fields** with the right label and value shape, and modeling attributes (like "source of risk") that aren't in the built-in schema.

Let AI do this for you

Copy the prompt to run this live via the [MCP server](https://developer.vanta.com/docs/vanta-mcp.md) or have AI generate a runnable script.

Code this

Generate a script or app that performs this function using the Vanta API.

You are writing a production-quality Node.js 18+ script that runs on a recurring schedule (cron / GitHub Actions / Cloud Scheduler) to keep risk scenarios in Vanta in sync with a source-of-truth CSV (e.g. exported from a GRC system or spreadsheet). Use the Manage Vanta API (base URL [https://api.vanta.com](https://api.vanta.com)).

Steps:

1. Read VANTA\_CLIENT\_ID, VANTA\_CLIENT\_SECRET, CSV\_PATH, and RISK\_REGISTER\_NAME from env. Also accept STATE\_PATH (default ./.vanta-risk-scenarios-state.json) and DRY\_RUN (default "false"). Fail fast on stderr if any required var is missing.
2. Mint a Vanta API token via POST [https://api.vanta.com/oauth/token](https://api.vanta.com/oauth/token) with Content-Type: application/json and a JSON body containing client\_id, client\_secret, grant\_type="client\_credentials", and scope="vanta-api.all:read vanta-api.all:write". The scope field is required — omitting it returns invalid\_scope. Read access\_token from the response. Re-mint at the start of each run (tokens expire after one hour).
3. Parse CSV\_PATH using a lightweight built-in parser that handles quoted fields and commas inside quotes. Required columns: riskId, description. Optional columns: detailedDescription, likelihood, impact, treatment, owner, categories (semicolon-separated), ciaCategories (semicolon-separated). Every other column header is the literal label of a custom field already defined in Vanta Risk Management settings.
4. Page through GET [https://api.vanta.com/v1/risk-scenarios?pageSize=100](https://api.vanta.com/v1/risk-scenarios?pageSize=100) using the pageCursor request param (read results.pageInfo.endCursor and hasNextPage until hasNextPage is false). Build a Map keyed by riskId. Each value is the full risk scenario object.
5. For each CSV row, look up the scenario by riskId. If it exists, classify as update-candidate. If not, classify as create-candidate. Coerce each custom-field cell to the field's expected JSON shape: empty cell -> skip; picklist -> JSON array of strings split on semicolon; everything else -> string.
6. Diff each update-candidate's coerced values against the scenario's existing fields. Build a `changes` object with only the fields that differ. If empty, classify the row as skipped.
7. Load STATE\_PATH if present — \{ "lastSyncedHash": \{ "\<riskId>": "\<sha-of-fields>" } } — and skip rows whose computed hash already matches (idempotent re-runs).
8. Print the plan: riskId | description | classification (create / update / skipped) | changedFields (count).
9. If DRY\_RUN === "true", print a JSON summary and exit 0 without writing.
10. For create-candidates, POST [https://api.vanta.com/v1/risk-scenarios](https://api.vanta.com/v1/risk-scenarios) with body including description (required), riskRegister=RISK\_REGISTER\_NAME, and any populated fields. For update-candidates, PATCH [https://api.vanta.com/v1/risk-scenarios/\\\{riskScenarioId\\}](https://api.vanta.com/v1/risk-scenarios/\\\{riskScenarioId\\}) with the changed fields only. Send requests sequentially to keep ordering deterministic and stay under rate limits.
11. After each success, record state.lastSyncedHash\[riskId] = sha of fields; write STATE\_PATH atomically (temp file + rename). Log riskId, description, action (CREATE / UPDATE / SKIP), status (SUCCESS / ERROR), and any error message.
12. End with a single JSON summary line on stdout: \{"total": N, "created": C, "updated": U, "skipped": S, "errors": E}.

Sample API response item from GET /v1/risk-scenarios (use these field names exactly):
\{ "riskId": "assets-not-identified-and-protected", "description": "Assets are not identified and protected according to company requirements.", "detailedDescription": null, "likelihood": 4, "impact": 4, "residualLikelihood": 2, "residualImpact": 1, "categories": \["Access control"], "ciaCategories": \["Confidentiality"], "treatment": "Avoid", "owner": null, "note": null, "riskRegister": "Default", "customFields": \[], "reviewStatus": "DRAFT", "type": "Risk Scenario", "identificationDate": "2024-03-07T18:46:05.944Z" }

Missing-field handling: if customFields is null on the scenario, treat as \[]. If the CSV omits an optional column, skip that field in the payload rather than sending null. Never throw on a missing optional field.

Error handling:

* 401: re-mint once and retry the request.
* 400 saying `RiskCustomAttribute with id: \<label\> not found`: the custom-field label isn't defined in Vanta Risk Management settings. Log the label, mark the row ERROR, and continue — the API only fills existing custom fields, it does not create field definitions.
* 400 saying `riskRegister` is required: your tenant has multiple registers. Confirm RISK\_REGISTER\_NAME matches an existing register name exactly (case-sensitive).
* 400 saying the value type is wrong: log the field, expected vs actual type, and the offending value; mark ERROR and continue.
* 404 on PATCH: scenario was deleted between the list and patch. Log and continue.
* 429: respect Retry-After header if present, otherwise sleep 5s; retry up to 3 times.
* 5xx: retry with 2s exponential back-off, max 3 attempts; then log and exit non-zero only if every request failed.

Do not:

* Add external dependencies — use built-in fetch, fs, path, and crypto only. The CSV parser is a small built-in helper, not an npm package.
* Hard-code any riskId, register name, custom-field label, or value — every customer's risk register and field schema is different. Always read CSV\_PATH and RISK\_REGISTER\_NAME.
* Send `type` on PATCH — changing a scenario's type isn't supported via update.
* Apply changes when DRY\_RUN is "true".
* Cache the access token across runs.
* Silently swallow errors.

Done when: a follow-up run with an unchanged CSV reports 0 creates and 0 updates (idempotent). Exit 0 if errors === 0; otherwise exit 1.

Scope required: vanta-api.all:read vanta-api.all:write.

Copy prompt

[Cursor](#)
[Claude](#)
[ChatGPT](#)

## Before you begin

This guide is for Vanta admins managing risk data inside their own Vanta account.

You'll need:

* A Manage Vanta [API token](https://developer.vanta.com/docs/quickstart/manage-vanta.md).
* Scopes `vanta-api.all:read` and `vanta-api.all:write` on the token. There is no risk-specific scope. Risk scenarios are covered by the broad `vanta-api.all:*` scopes. See [API authentication](https://developer.vanta.com/docs/concepts/authentication.md).
* Any custom fields you plan to set must already be defined in **Risk Management → Settings → Custom Fields** in the Vanta UI. The API fills custom field values; it can't create the field definitions.

The `CreateRiskScenarioInput` schema has a fixed set of fields. There is no built-in `source` field, no built-in `jiraTicket` field, and no per-scenario "risk owner group". Anything not in the table below has to be modeled as a **custom field** (see Step 2 below):

| Field | Type | Notes |
| - | - | - |
| `description` | string | **Required.** Short title of the risk. |
| `detailedDescription` | string | Long-form context (max 10,000 chars). |
| `riskId` | string | Stable identifier. Auto-generated if omitted. Reuse it to update. |
| `likelihood` / `impact` | integer | Inherent risk scores, default range 1–5 (customizable in settings). |
| `residualLikelihood` / `residualImpact` | integer | Post-mitigation scores. |
| `categories` | string\[] | New values become new categories automatically. |
| `ciaCategories` | `Confidentiality` / `Integrity` / `Availability` | |
| `treatment` | `Mitigate` / `Transfer` / `Avoid` / `Accept` | |
| `owner` | string | **Email address** of a Vanta user. |
| `note` | string | Justification for the scores. |
| `riskRegister` | string | **Name** of the register (not an id). Required if you have multiple registers. |
| `customFields` | array | Label/value pairs for org-specific attributes — see Step 2 below. |
| `type` | `Risk Scenario` / `Enterprise Risk` | Enterprise risks can't be attached to a register. Defaults to `Risk Scenario`. |
| `identificationDate` | ISO 8601 | Defaults to creation time. |

There's also a deprecated `isSensitive` boolean still accepted by the API; new integrations shouldn't rely on it.

**1. Create a risk scenario in a specific register**

**Your terminal** — `POST /v1/risk-scenarios`. Only `description` is strictly required, but if your tenant has more than one risk register you must pass `riskRegister` **by name** (case-sensitive) or the API returns 400.

```javascript Node.js theme={"system"}
const res = await fetch("https://api.vanta.com/v1/risk-scenarios", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer YOUR_TOKEN",
  },
  body: JSON.stringify({
    description: "Unauthorized access to production database",
    riskRegister: "Default",
    likelihood: 3,
    impact: 4,
    treatment: "Mitigate",
    owner: "risk-owner@example.com",
    ciaCategories: ["Confidentiality"],
  }),
});
const scenario = await res.json();
console.log(scenario.riskId);
```

```python Python theme={"system"}
import requests

r = requests.post(
    "https://api.vanta.com/v1/risk-scenarios",
    headers={"Authorization": "Bearer YOUR_TOKEN"},
    json={
        "description": "Unauthorized access to production database",
        "riskRegister": "Default",
        "likelihood": 3,
        "impact": 4,
        "treatment": "Mitigate",
        "owner": "risk-owner@example.com",
        "ciaCategories": ["Confidentiality"],
    },
)
r.raise_for_status()
print(r.json()["riskId"])
```

```bash Terminal theme={"system"}
curl -X POST 'https://api.vanta.com/v1/risk-scenarios' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -d '{
    "description": "Unauthorized access to production database",
    "riskRegister": "Default",
    "likelihood": 3,
    "impact": 4,
    "treatment": "Mitigate",
    "owner": "risk-owner@example.com",
    "ciaCategories": ["Confidentiality"]
  }'
```

A `200` response returns the full risk scenario, including the `riskId` you'll use for later updates.

> [accordion] Which register name should I send?
>
> `riskRegister` takes the register's **name**, not its id. Open **Risk Management → Registers** in Vanta and copy the exact name (spaces, capitalization, and punctuation all matter). Tenants with a single register can omit the field.

> [accordion] Got `400` saying `owner` is not a valid user?
>
> `owner` must be the email address of an existing Vanta user, not a display name or a person id. Look up the address with `GET /v1/people` filtered to `employmentStatus=CURRENT`.

> [accordion] Creating an Enterprise Risk instead?
>
> Pass `type: "Enterprise Risk"` and omit `riskRegister` — enterprise risks aren't attached to a register. Requires the Enterprise Risk Management SKU.

**2. Set custom fields**

Anything outside the built-in schema — "Source of risk", a Jira ticket URL, an internal risk tier, a business unit — is a **custom field**. Custom fields must be **defined ahead of time** in **Risk Management → Settings → Custom Fields**; the API fills values but never creates field definitions.

Pass them via the `customFields` array. Each entry has a `label` (matches the field name in settings exactly, case-sensitive) and a `value` matching the field's type:

* **Text / date / number / currency** — JSON string: `{ "label": "Source of risk", "value": "Internal audit finding" }`
* **Picklist** — JSON array of strings: `{ "label": "Business unit", "value": ["Engineering", "Security"] }`

```bash Terminal theme={"system"}
curl -X POST 'https://api.vanta.com/v1/risk-scenarios' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -d '{
    "description": "Unauthorized access to production database",
    "riskRegister": "Default",
    "customFields": [
      { "label": "Source of risk", "value": "Internal audit finding" },
      { "label": "Jira ticket", "value": "https://your-org.atlassian.net/browse/SEC-1234" },
      { "label": "Business unit", "value": ["Engineering", "Security"] }
    ]
  }'
```

> [accordion] Got `400 RiskCustomAttribute with id: \<label\> not found`?
>
> The `label` you sent doesn't match any custom field defined in **Risk Management → Settings → Custom Fields**. This includes system-style identifiers like `managed_by_email` — the API does not resolve those. Open the settings page, copy the field name exactly, and retry. Custom field definitions cannot be created through the API.

> [accordion] Got a 400 saying the value type is wrong?
>
> Your JSON value doesn't match the field's declared type. Picklist fields need an array of strings even when you're only setting one option. Text/date/number/currency fields need a plain string.

> [accordion] Where does the built-in Source, Jira, or Ticket field live?
>
> There isn't one. `riskId`, `description`, `detailedDescription`, `note`, `categories`, `ciaCategories`, `treatment`, `owner`, `riskRegister`, `likelihood`, `impact`, `residualLikelihood`, `residualImpact`, `type`, and `identificationDate` (plus the deprecated `isSensitive` flag) are the only non-custom fields on a risk scenario — everything else has to be a custom field.

**3. Update an existing scenario**

**Your terminal** — `PATCH /v1/risk-scenarios/{riskScenarioId}`. Send only the fields you want to change; omitted fields keep their current values. `customFields` follows the same shape as create.

```javascript Node.js theme={"system"}
const RISK_ID = "YOUR_RISK_ID";

const res = await fetch(`https://api.vanta.com/v1/risk-scenarios/${RISK_ID}`, {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer YOUR_TOKEN",
  },
  body: JSON.stringify({
    residualLikelihood: 2,
    residualImpact: 2,
    customFields: [
      { label: "Jira ticket", value: "https://your-org.atlassian.net/browse/SEC-1234" },
    ],
  }),
});
console.log(await res.json());
```

```bash Terminal theme={"system"}
RISK_ID="YOUR_RISK_ID"

curl -X PATCH "https://api.vanta.com/v1/risk-scenarios/$RISK_ID" \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -d '{
    "residualLikelihood": 2,
    "residualImpact": 2,
    "customFields": [
      { "label": "Jira ticket", "value": "https://your-org.atlassian.net/browse/SEC-1234" }
    ]
  }'
```

> [accordion] Need to clear a custom field?
>
> Send the field with `value: ""` (text/date/number/currency) or `value: []` (picklist). The `label` still has to match a defined field.

> [accordion] Can I change `type` on update?
>
> No — changing a scenario's `type` (`Risk Scenario` ↔ `Enterprise Risk`) is not supported via `PATCH`. Requests that include `type` are rejected. Create a new scenario with the desired type and archive the old one.

**4. Link controls to the treatment plan**

**Your terminal** — Vanta tracks a risk's treatment plan as **control associations**, not as separate task records. `POST /v1/risk-scenarios/{riskScenarioId}/controls` links a control. Set `controlType: "TREATMENT_PLAN"` to make it part of the treatment plan, or omit it (or pass `"EXISTING"`) to link the control without the treatment-plan designation.

```bash Terminal theme={"system"}
curl -X POST 'https://api.vanta.com/v1/risk-scenarios/YOUR_RISK_SCENARIO_ID/controls' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -d '{
    "controlId": "A.12.2.1",
    "controlType": "TREATMENT_PLAN"
  }'
```

`controlId` accepts a Vanta control shorthand (like `A.12.2.1`), a custom-control shorthand, or the control's object ID. Verify the plan with [`GET /v1/risk-scenarios/{riskScenarioId}/controls`](https://developer.vanta.com/api-reference/risk-scenarios/list-risk-scenario-controls) — each item returns `{ controlId, controlType }`.

> [accordion] How do I add tasks to a treatment plan?
>
> The API only exposes **control** associations on a risk scenario. There is no endpoint for linking discrete tasks (such as `SecurityTask` resources) to a treatment plan. To track an action item that isn't an existing Vanta control, create a custom control for it and link that control with `controlType: "TREATMENT_PLAN"`.

> [accordion] Got a 422 saying the control is already associated?
>
> The control is already linked with the other `controlType`. Use `PATCH /v1/risk-scenarios/{riskScenarioId}/controls/{controlId}` with the new `controlType` to move it between the treatment-plan and existing-control sets.

> [accordion] Need to remove a control from the plan?
>
> `PATCH` with `{ "controlType": "EXISTING" }` drops the treatment-plan designation but keeps the control linked. `DELETE /v1/risk-scenarios/{riskScenarioId}/controls/{controlId}` unlinks it entirely.

## Congratulations

You can now create risk scenarios in the right register, populate every organization-specific attribute via custom fields, and update scores or metadata idempotently.

## Next steps

> [card] [Assign a control owner](https://developer.vanta.com/docs/guides/add-an-owner-to-a-control.md)
>
> Make a specific user accountable for the controls that mitigate a risk.

> [card] [Set custom fields on vendors](https://developer.vanta.com/docs/guides/use-custom-fields-with-vendors.md)
>
> Same `customFields` pattern applied to the Vendors API.

> [card] [Try it in Postman](https://developer.vanta.com/docs/postman-setup.md)
>
> Import the collection and call `POST /v1/risk-scenarios` against a sandbox.

> [card] [Manage Vanta API reference](https://developer.vanta.com/reference/manage-vanta/overview.md)
>
> Browse every Manage Vanta endpoint — risk scenarios, controls, tests, documents, people.


## Related topics

- [Set custom fields on vendors](https://developer.vanta.com/docs/guides/use-custom-fields-with-vendors.md)
- [Update risk scenario](https://developer.vanta.com/api-reference/risk-scenarios/update-risk-scenario.md)
- [Create risk scenario](https://developer.vanta.com/api-reference/risk-scenarios/create-risk-scenario.md)
- [Vanta API changelog](https://developer.vanta.com/docs/changelog.md)
- [List risk registers](https://developer.vanta.com/api-reference/risk-registers/list-risk-registers.md)
