> For the complete documentation index, see [llms.txt](https://docs.nected.ai/nected-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nected.ai/nected-docs/management-api/rules/create-rule.md).

# Create rule

Create a new rule in your workspace using `POST /dev/v1/rule`. The request body **must** include `name` and `type`. The `type` determines which other fields are required:

* **`type = simpleRule`** — `customInput`, `conditions` (`startNode` + `nodes`), `action` (`then` / `else`), `settings`, optional `firstCustomInput`. Leave `decisionTable` rows/properties/results empty or null for a pure simple rule.
* **`type = decisionTable`** — `customInput`, `conditions`, `decisionTable` (`firstRow`, `firstProperty`, `firstResult`, `rows`, `properties`, `results`), `action.then.outputData`, `policy`, `settings`. Do not use `ruleSet` / `ruleChain` for the table itself.
* **`type = ruleSet`** — `ruleSet` (array of rule IDs), `ruleSetPolicy`, `firstRuleChain`, `ruleChain`, `settings`. `conditions` / `decisionTable` are typically empty.

A **minimal** stub (only `name`, `type`, `dataSetId`) is **not** sufficient to create a working rule. You need the **full** payload shape Nected expects—the same structure you see when you **get** a rule by id (minus top-level `id` / `checksum` on create).

## Create rule

> Create a new rule. Request body \*\*must\*\* include \`name\` and \`type\` (\`simpleRule\`, \`decisionTable\`, or \`ruleSet\`).\
> \
> Use the \*\*Examples\*\* dropdown for a complete, copy-paste-ready payload per type. Create returns \`data.id\` and \`data.checksum\` (see 201 response example).

```json
{"openapi":"3.0.3","info":{"title":"Nected Rule API (Dev V1)","version":"1.0"},"tags":[{"name":"Rule","description":"List, create, read, update, test, schedule, and publish rules."}],"servers":[{"url":"https://api.nected.ai","description":"Production"}],"security":[{"DevAuth":[]}],"components":{"securitySchemes":{"DevAuth":{"type":"apiKey","in":"header","name":"Nected-API-Key","description":"Dev API key (`Nected-API-Key` header)"}},"schemas":{"CreateRulePayload":{"type":"object","description":"Request body for Create rule. Must include `name` and `type`. `type` is one of `simpleRule`, `decisionTable`, or `ruleSet`.\n\nThe high-level shape is the same for all types, but **which fields you fill vs. leave blank depends on the rule type**.\n\n### Shared fields (all types)\n- `name` (string, required): Rule name.\n- `type` (string, required): One of `simpleRule`, `decisionTable`, `ruleSet`.\n- `description` (string, optional).\n- `dataSetId` (string, optional): ID of the dataset used by the rule (when applicable).\n- `customInput` (object, optional): Map of custom input definitions keyed by input name.\n- `settings` (object, optional): Common runtime settings (isEnabled, api, schedule, cache, dateFormat, timezone, etc.).\n- `dependencyMap` (array, optional): Reserved for advanced use; usually empty on create.\n\n### When `type = simpleRule`\n- **Typically filled**: `conditions`, `action`, `customInput`, `settings`, `firstCustomInput` (optional).\n- **Should be empty / null**: `decisionTable.rows`, `decisionTable.properties`, `decisionTable.results` for pure simple rules.\n- **Rule set fields**: `ruleSet`, `ruleSetPolicy`, `firstRuleChain`, `ruleChain`, `policy` are not used for evaluation of a pure `simpleRule`.\n\n### When `type = decisionTable`\n- **Must be filled**: `decisionTable` (firstRow, firstProperty, firstResult, rows, properties, results), `action.then.outputData`, `policy`.\n- **Usually filled**: `customInput`, `settings`, `firstCustomInput`.\n- **Must be empty / null**: `ruleSet`, `ruleSetPolicy`, `firstRuleChain`, `ruleChain`.\n\n### When `type = ruleSet`\n- **Must be filled**: `ruleSet`, `ruleSetPolicy`, `firstRuleChain`, `ruleChain`.\n- **Usually filled**: `customInput`, `settings`.\n- **Must be empty / null**: `conditions`, `decisionTable`, action output/actionNode fields as appropriate.\n\nCanonical files: `Create/create_SR.json`, `Create/create_decisiontable.json`, `Create/create_ruleset.json`, and `examples/` for GET/PATCH mirrors.","additionalProperties":true,"required":["name","type"],"properties":{"name":{"type":"string","description":"Rule name"},"type":{"type":"string","enum":["simpleRule","decisionTable","ruleSet"],"description":"Rule type; payload shape depends on this."},"description":{"type":"string"},"dataSetId":{"type":"string","nullable":true},"customInput":{"type":"object"},"conditions":{"type":"object"},"action":{"type":"object"},"settings":{"type":"object"},"firstCustomInput":{"type":"string"},"decisionTable":{"type":"object","nullable":true,"description":"Required for type decisionTable"},"ruleSet":{"type":"array","nullable":true,"description":"Required for type ruleSet; null for decisionTable","items":{}},"ruleSetPolicy":{"type":"string"},"firstRuleChain":{"type":"string"},"ruleChain":{"type":"object","nullable":true,"additionalProperties":true},"policy":{"type":"string"},"dependencyMap":{"type":"array"}}},"CreateRuleResponse":{"type":"object","description":"Success response for Create rule (POST). Same for all rule types.","properties":{"data":{"type":"object","properties":{"id":{"type":"string","description":"Entity ID of the created rule"},"checksum":{"type":"string","description":"Checksum for subsequent update/test/publish when required"}}},"code":{"type":"string"},"message":{"type":"string"}}},"Response":{"type":"object","description":"Standard API response wrapper","properties":{"code":{"type":"string"},"data":{"description":"Response payload: rule object, array of rules (list), version rows, or execution result — shape varies by endpoint"},"message":{"type":"string"},"pageNo":{"type":"integer"},"pageSize":{"type":"integer"},"totalCount":{"type":"integer"},"totalPages":{"type":"integer"},"paginationInfo":{"$ref":"#/components/schemas/PaginationInfo"}}},"PaginationInfo":{"type":"object","description":"Pagination metadata returned by GET /dev/v1/rule (list rules)","properties":{"perPage":{"type":"integer","description":"Page size (items per page)"},"totalPage":{"type":"integer","description":"Total number of pages"},"currentPage":{"type":"integer","description":"Current page index"},"totalRecord":{"type":"integer","description":"Total records across all pages"}}}}},"paths":{"/dev/v1/rule":{"post":{"operationId":"createRule","tags":["Rule"],"summary":"Create rule","description":"Create a new rule. Request body **must** include `name` and `type` (`simpleRule`, `decisionTable`, or `ruleSet`).\n\nUse the **Examples** dropdown for a complete, copy-paste-ready payload per type. Create returns `data.id` and `data.checksum` (see 201 response example).","parameters":[{"name":"Nected-Branch","in":"header","required":false,"description":"Branch name (optional)","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateRulePayload"}}}},"responses":{"201":{"description":"Created. Returns data.id (entity ID) and data.checksum.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateRuleResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}}}}}}}}}
```

### Copy‑paste JSON examples

You can copy any of the following payloads, replace IDs/field values with your own, and call `POST /dev/v1/rule` directly.

#### Example payload – `type = simpleRule`

{% file src="/files/AIuNiwnGeDRzdGG9icdy" %}

#### Example payload – `type = decisionTable`

{% file src="/files/90YjYMh6ZXdfX7Wv1Fcr" %}

#### Example payload – `type = ruleSet`

{% file src="/files/xKqLWHUmqPhECAaXcitn" %}

**Response:**\
The response structure is the same for all rule types:

* `data.id` – Entity ID of the created rule
* `data.checksum` – Checksum for updates in the rule.
* `code` – Status code (e.g., `"success"`)
* `message` – Additional status message

See the API reference to try the endpoint and view schema details.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nected.ai/nected-docs/management-api/rules/create-rule.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
