<!-- https://staircase.co/platform/data/rule -->
# Rule

# Rule

A declarative rules engine underneath eligibility and validation across products, including model-assisted rule authoring.

Rules are data. A rule names the fields it reads, the condition it tests and the result it produces, and the engine evaluates it against a canonical record — which is what lets an eligibility rule change without a deployment of the product that runs it.

The same engine backs the conditional requirements in the model's semantic validation and the eligibility logic in the mortgage products.

## How it works

Rule authoring is assisted rather than automated. A model drafts a rule from a stated requirement, and the draft is validated against the model's own schema before it is accepted — so a generated rule that references a field that does not exist fails at authoring time rather than at evaluation time.

## Operations

<!--source:api-specifications-->

### Engine
<!--/source-->

`POST` `/engine/data/jobs`

<!--source:api-specifications-->

#### Invoke Ruleset
<!--/source-->

`invokeRuleset`

<!--source:api-specifications-->
Invoke Ruleset: processes the input collection(s) according to the Ruleset operation as below:

- SELECTIVE_DATA_MERGE: merge collections in a new collection.
- Input: Staircase Collection(s).
- Process: Create new collection by running the ruleset on the input collections.
- Output: A new collection generated from running the ruleset.
- DATA_INFERRING: modify existing collection.
- Input: Staircase Collection.
- Process: Modify the collection by running the Ruleset.
- Output: Modified collection.

Callback URL: The callback is an POST HTTP call with a JSON request body with the following schema:

Show the rest
```
{
"type": "object",
"$schema": "",
"required": [
"job_id",
"job_status"
],
"properties": {
"job_id": {
"type": "string",
"format": "ulid"
},
"job_status": {
"type": "string",
"enum": [
"COMPLETED",
"FAILED"
]
},
"output": {
"type": "object",
"required": [
"data",
"metadata"
],
"properties": {
"data": {
"type": "object"
},
"metadata": {
"type": "object",
"description": "Metadata about output data",
"properties": {
"status": {
"type": "string",
"description": "Status of the data validity",
"enum": [
"HAS_VALIDATION_ERRORS"
]
},
"status_message": {
"type": "string",
"description": "Status description"
}
}
}
}
},
"failure_reason": {
"type": "string"
}
}
}
```

Example for completed job:

```
{
"job_id": "01FMPQ735YKJ0TFBXX3YKVWK7P",
"job_status": "COMPLETED",
"output": {
"metadata": {
"status": "HAS_VALIDATION_ERRORS",
"status_message": "Data has at least 1 object in $.data_validation_metadata with a has_validation_code >= 400"
},
"data": {
"documents": [
{
"@id": "01FKYN27FT44KKTAEC58S6Y6FY",
"@type": "closing_disclosure",
"has_document_date": {
"has_value": "2021-01-29"
},
"has_document_misclassified_indicator": {
"has_value": "false"
}
}
],
"loan_terms": [
{
"@id": "01FKYN27FH8P2WS39Z5KSV7CEA",
"@type": "loan_terms",
"has_hazard_insurance_escrow_required_indicator": {
"has_value": "true"
},
"has_initial_principal_and_interest_payment_amount": {
"has_value": 98.3
},
"has_prepaid_taxes_months_count": {
"has_value": "7"
},
"has_tax_escrow_required_indicator": {
"has_value": "true"
}
}
],
"payments": [
{
"@id": "01FKYN27FJN6M8MMFMH4PDSG5E",
"@type": "loan_payment",
"has_late_charge_rate_percent": {
"has_data_extraction_confidence_score": 95,
"has_value": "5"
}
}
]
}
}
}
```

Example for failed job:

```
{
"job_id": "01FMQCF7QW6BHZC7NC7XRRHRPN",
"job_status": "FAILED",
"failure_reason": "Unexpected error."
}
```

Example callback for running Ruleset Invocation:

The endpoint returns the job_id that can be tracked here

<!--/source-->

##### Request

<!--source:api-specifications-->
application/json Copy
```
{
 "ruleset_name": "selective_merge_ruleset",
 "input": {
 "data_objects": [
 {
 "data": {
 "loans": [
 {
 "@id": "01FKYN27FFCBT3GHGNGWQ9S6CK",
 "@type": "loan",
 "with_insurance": [
 "01FKYN27FHSK0MFKHD9WXC819J"
 ],
 "with_loan_terms": [
 "01FKYN27FH8P2WS39Z5KSV7CEB"
 ],
 "with_payment": [
 "01FKYN27FJN6M8MMFMH4PDSG5E"
 ]
 }
 ],
 "insurance": [
 {
 "@id": "01FKYN27FHSK0MFKHD9WXC819J",
 "@type": "mortgage_insurance",
 "has_insurance_escrowed_indicator": {
 "has_value": "true"
 }
 }
 ],
 "loan_terms": [
 {
 "@id": "01FKYN27FH8P2WS39Z5KSV7CEB",
 "@type": "loan_terms",
 "has_hazard_insurance_escrow_required_indicator": {
 "has_value": "true"
 },
 "has_initial_principal_and_interest_payment_amount": {
 "has_value": 91.5
 },
 "has_loan_amortization_type": {
 "has_value": null
 },
 "has_prepaid_taxes_months_count": {
 "has_value": "7"
 },
 "has_tax_escrow_required_indicator": {
 "has_value": "true"
 }
 }
 ],
 "payments": [
 {
 "@id": "01FKYN27FJN6M8MMFMH4PDSG5E",
 "@type": "loan_payment",
 "has_late_charge_rate_percent": {
 "has_value": "5",
 "has_data_extraction_confidence_score": 95
 }
 }
 ],
 "documents": [
 {
 "@id": "01FKYN27FT44KKTAEC58S6Y6FY",
 "@type": "closing_disclosure",
 "has_document_date": {
 "has_value": "2021-01-29"
 },
 "has_document_misclassified_indicator": {
 "has_value": "false"
 }
 }
 ],
 "mortgage_products": [
 {
 "@id": "01FKYN27FX3A94JY49JYCW7RG0",
 "@type": "ide"
 }
 ]
 }
 }
 ],
 "collections": [
 {
 "transaction_id": "01FJC4DRGV5KNWWJZ9Y3D4X3KG",
 "collection_id": "01FJC4E5E6M9ZJ5TRMJPRQ99C9"
 },
 {
 "transaction_id": "01FJC4DRGV5KNWWJZ9Y3D4X3KG",
 "collection_id": "01FJC4E9BXJZA254VTENY1RW9H"
 },
 {
 "transaction_id": "01FJC4DRGV5KNWWJZ9Y3D4X3KG",
 "collection_id": "01FJC4EGKZMA6T659B9XP64G4W"
 }
 ]
 },
 "callback_url": "https://notify.me/please"
}
```

<!--/source-->

##### Response

<!--source:api-specifications-->
201400
<!--/source-->

<!--source:api-specifications-->
application/json Copy Created.

```
{
 "ruleset_name": "selective_merge_ruleset",
 "job_id": "01FJC4JGKFX3VYB0EZ75JNY4J6",
 "job_status": "STARTED",
 "input": {
 "data_objects": [
 {
 "data": {
 "loans": [
 {
 "@id": "01FKYN27FFCBT3GHGNGWQ9S6CK",
 "@type": "loan",
 "with_insurance": [
 "01FKYN27FHSK0MFKHD9WXC819J"
 ],
 "with_loan_terms": [
 "01FKYN27FH8P2WS39Z5KSV7CEB"
 ],
 "with_payment": [
 "01FKYN27FJN6M8MMFMH4PDSG5E"
 ]
 }
 ],
 "insurance": [
 {
 "@id": "01FKYN27FHSK0MFKHD9WXC819J",
 "@type": "mortgage_insurance",
 "has_insurance_escrowed_indicator": {
 "has_value": "true"
 }
 }
 ],
 "loan_terms": [
 {
 "@id": "01FKYN27FH8P2WS39Z5KSV7CEB",
 "@type": "loan_terms",
 "has_hazard_insurance_escrow_required_indicator": {
 "has_value": "true"
 },
 "has_initial_principal_and_interest_payment_amount": {
 "has_value": 91.5
 },
 "has_loan_amortization_type": {
 "has_value": null
 },
 "has_prepaid_taxes_months_count": {
 "has_value": "7"
 },
 "has_tax_escrow_required_indicator": {
 "has_value": "true"
 }
 }
 ],
 "payments": [
 {
 "@id": "01FKYN27FJN6M8MMFMH4PDSG5E",
 "@type": "loan_payment",
 "has_late_charge_rate_percent": {
 "has_value": "5",
 "has_data_extraction_confidence_score": 95
 }
 }
 ],
 "documents": [
 {
 "@id": "01FKYN27FT44KKTAEC58S6Y6FY",
 "@type": "closing_disclosure",
 "has_document_date": {
 "has_value": "2021-01-29"
 },
 "has_document_misclassified_indicator": {
 "has_value": "false"
 }
 }
 ],
 "mortgage_products": [
 {
 "@id": "01FKYN27FX3A94JY49JYCW7RG0",
 "@type": "ide"
 }
 ]
 }
 }
 ],
 "collections": [
 {
 "transaction_id": "01FJC4DRGV5KNWWJZ9Y3D4X3KG",
 "collection_id": "01FJC4E5E6M9ZJ5TRMJPRQ99C9"
 },
 {
 "transaction_id": "01FJC4DRGV5KNWWJZ9Y3D4X3KG",
 "collection_id": "01FJC4E9BXJZA254VTENY1RW9H"
 },
 {
 "transaction_id": "01FJC4DRGV5KNWWJZ9Y3D4X3KG",
 "collection_id": "01FJC4EGKZMA6T659B9XP64G4W"
 }
 ]
 }
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Request body`application/json`

<!--source:api-specifications-->
4 fields
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `transaction_id` | `string` | <!--source:api-specifications-->Transaction ID<!--/source-->Example `01GKMKNNBG21DZ5GZXAQVS7AQC` |
| `ruleset_name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `input`required | `object` | <!--source:api-specifications-->Data for the processing<!--/source--> |
| `data_objects` | `object[]` | <!--source:api-specifications-->The array of data objects that need to be processed<!--/source--> |
| `data`required | `object` | <!--source:api-specifications-->The data in staircase v2 format<!--/source--> |
| `collections` | `object[]` | <!--source:api-specifications-->The array of collection IDs that need to be processed<!--/source--> |
| `transaction_id`required | `string (ulid)` | <!--source:api-specifications-->Transaction ID<!--/source--> |
| `collection_id`required | `string (ulid)` | <!--source:api-specifications-->Collection ID<!--/source--> |
| `callback_url` | `string (uri)` | <!--source:api-specifications-->The URL which is used to send the result of the job.<!--/source--> |

##### Response `201``application/json`

<!--source:api-specifications-->
5 fields
<!--/source-->
<!--source:api-specifications-->
Created.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `ruleset_name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `input`required | `object` | <!--source:api-specifications-->Data for the processing<!--/source--> |
| `data_objects` | `object[]` | <!--source:api-specifications-->The array of data objects that need to be processed<!--/source--> |
| `data`required | `object` | <!--source:api-specifications-->The data in staircase v2 format<!--/source--> |
| `collections` | `object[]` | <!--source:api-specifications-->The array of collection IDs that need to be processed<!--/source--> |
| `transaction_id`required | `string (ulid)` | <!--source:api-specifications-->Transaction ID<!--/source--> |
| `collection_id`required | `string (ulid)` | <!--source:api-specifications-->Collection ID<!--/source--> |
| `callback_url` | `string (uri)` | <!--source:api-specifications-->The URL which is used to send the result of the job.<!--/source--> |
| `job_id`required | `string (ulid)` | <!--source:api-specifications-->Identifier of the job<!--/source--> |
| `job_status`required | `string` | <!--source:api-specifications-->The status of the job<!--/source-->`STARTED` |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400``422`

`GET` `/engine/data/jobs/{job_id}`

<!--source:api-specifications-->

#### Get Ruleset Invocation Status
<!--/source-->

`getRulesetInvocationStatus`

<!--source:api-specifications-->
Returns the status of invoking Ruleset associated with the input collection(s) and output collection.

<!--/source-->

##### Response

<!--source:api-specifications-->
200400
<!--/source-->

<!--source:api-specifications-->
application/json Copy Created.

```
{
 "job_id": "01FM2G606MNKG8YKD62EB64DDR",
 "job_status": "COMPLETED",
 "ruleset_name": "test4",
 "callback_url": "https://webhook.site/efc96f90-7e76-41bc-986f-5bcfaf1df8e3",
 "input": {
 "data_objects": [
 {
 "data": {
 "loans": [
 {
 "@id": "01FKYN27FFCBT3GHGNGWQ9S6CK",
 "@type": "loan",
 "with_insurance": [
 "01FKYN27FHSK0MFKHD9WXC819J"
 ],
 "with_loan_terms": [
 "01FKYN27FH8P2WS39Z5KSV7CEB"
 ],
 "with_payment": [
 "01FKYN27FJN6M8MMFMH4PDSG5E"
 ]
 }
 ],
 "insurance": [
 {
 "@id": "01FKYN27FHSK0MFKHD9WXC819J",
 "@type": "mortgage_insurance",
 "has_insurance_escrowed_indicator": {
 "has_value": "true"
 }
 }
 ],
 "loan_terms": [
 {
 "@id": "01FKYN27FH8P2WS39Z5KSV7CEB",
 "@type": "loan_terms",
 "has_hazard_insurance_escrow_required_indicator": {
 "has_value": "true"
 },
 "has_initial_principal_and_interest_payment_amount": {
 "has_value": 91.5
 },
 "has_loan_amortization_type": {
 "has_value": null
 },
 "has_prepaid_taxes_months_count": {
 "has_value": "7"
 },
 "has_tax_escrow_required_indicator": {
 "has_value": "true"
 }
 }
 ],
 "payments": [
 {
 "@id": "01FKYN27FJN6M8MMFMH4PDSG5E",
 "@type": "loan_payment",
 "has_late_charge_rate_percent": {
 "has_value": "5",
 "has_data_extraction_confidence_score": 95
 }
 }
 ],
 "documents": [
 {
 "@id": "01FKYN27FT44KKTAEC58S6Y6FY",
 "@type": "closing_disclosure",
 "has_document_date": {
 "has_value": "2021-01-29"
 },
 "has_document_misclassified_indicator": {
 "has_value": "false"
 }
 }
 ],
 "mortgage_products": [
 {
 "@id": "01FKYN27FX3A94JY49JYCW7RG0",
 "@type": "ide"
 }
 ]
 }
 }
 ],
 "collections": [
 {
 "collection_id": "01FM1Z95YK35V2V5MYBV52V1H0",
 "transaction_id": "01FM1Z7CAEHMA21C0GX78HGGSW"
 }
 ]
 },
 "output": {
 "data": {
 "assets": [
 {
 "@id": "01FFSP6DRCFJEHQK8ZH38HAH6X",
 "@type": "savings_account",
 "owned_by": [
 "01FFSP6DRCYYGGY9AER4H7GZXZ"
 ]
 },
 {
 "@id": "01FFSP6DRCFJEHQK8ZH38HAH6Z",
 "@type": "savings_account",
 "owned_by": [
 "01FFSP6DRCYYGGY9AER4H7GZXY",
 "01FFSP6DRCYYGGY9AER4H7GZXX"
 ]
 },
 {
 "@id": "01FFSP6DRCFJEHQK8ZH38HAH6Y",
 "@type": "savings_account",
 "owned_by": [
 "01FFSP6DRCYYGGY9AER4H7GZXY - 01FFSP6DRCYYGGY9AER4H7GZXZ"
 ]
 }
 ],
 "people": [
 {
 "@id": "01FFSP6DRCYYGGY9AER4H7GZXY",
 "@type": "borrower",
 "has_first_name": {
 "has_value": "John"
 },
 "has_last_name": {
 "has_value": "Snow"
 },
 "owns_asset": [
 "01FFSP6DRCFJEHQK8ZH38HAH6Z",
 "01FFSP6DRCFJEHQK8ZH38HAH6Y"
 ]
 },
 {
 "@id": "01FFSP6DRCYYGGY9AER4H7GZXZ",
 "@type": "borrower",
 "has_first_name": {
 "has_value": "Jane"
 },
 "has_last_name": {
 "has_value": "Snow"
 },
 "owns_asset": [
 "01FFSP6DRCFJEHQK8ZH38HAH6X",
 "01FFSP6DRCFJEHQK8ZH38HAH6Y"
 ]
 },
 {
 "@id": "01FFSP6DRCYYGGY9AER4H7GZXX",
 "@type": "borrower",
 "has_first_name": {
 "has_value": "Jack"
 },
 "has_last_name": {
 "has_value": "Snow"
 },
 "owns_asset": [
 "01FFSP6DRCFJEHQK8ZH38HAH6Z"
 ]
 }
 ],
 "relationships": [
 {
 "@type": "relationship",
 "link_from": [
 "01FFSP6DRCFJEHQK8ZH38HAH6Z"
 ],
 "link_to": [
 "01FFSP6DRCYYGGY9AER4H7GZXY"
 ],
 "relationship_link": "ASSET_ROLE"
 },
 {
 "@type": "relationship",
 "link_from": [
 "01FFSP6DRCFJEHQK8ZH38HAH6Y"
 ],
 "link_to": [
 "01FFSP6DRCYYGGY9AER4H7GZXY"
 ],
 "relationship_link": "ASSET_ROLE"
 },
 {
 "@type": "relationship",
 "link_from": [
 "01FFSP6DRCFJEHQK8ZH38HAH6Z"
 ],
 "link_to": [
 "01FFSP6DRCYYGGY9AER4H7GZXX"
 ],
 "relationship_link": "ASSET_ROLE"
 },
 {
 "@type": "relationship",
 "link_from": [
 "01FFSP6DRCFJEHQK8ZH38HAH6Y"
 ],
 "link_to": [
 "01FFSP6DRCYYGGY9AER4H7GZXZ"
 ],
 "relationship_link": "ASSET_ROLE"
 },
 {
 "@type": "relationship",
 "link_from": [
 "01FFSP6DRCFJEHQK8ZH38HAH6X"
 ],
 "link_to": [
 "01FFSP6DRCYYGGY9AER4H7GZXZ"
 ],
 "relationship_link": "ASSET_ROLE"
 }
 ]
 }
 }
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
1
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `job_id` required | `string` path | `01FJC4JGKFX3VYB0EZ75JNY4J6` | <!--source:api-specifications-->Identifier of the data processing job.<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
8 fields
<!--/source-->
<!--source:api-specifications-->
Created.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `job_id`required | `string (ulid)` | <!--source:api-specifications-->Identifier of the job<!--/source--> |
| `job_status`required | `string` | <!--source:api-specifications-->The status of the job<!--/source-->`COMPLETED``FAILED``IN_PROGRESS` |
| `failure_reason` | `string` | <!--source:api-specifications-->The reason of a failing for jobs with status FAILED<!--/source--> |
| `ruleset_name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `transaction_id`required | `string (ulid)` | <!--source:api-specifications-->Transaction ID<!--/source--> |
| `input`required | `object` | <!--source:api-specifications-->Data for the processing<!--/source--> |
| `data_objects` | `object[]` | <!--source:api-specifications-->The array of data objects that need to be processed<!--/source--> |
| `data`required | `object` | <!--source:api-specifications-->The data in staircase v2 format<!--/source--> |
| `collections` | `object[]` | <!--source:api-specifications-->The array of collection IDs that need to be processed<!--/source--> |
| `transaction_id`required | `string (ulid)` | <!--source:api-specifications-->Transaction ID<!--/source--> |
| `collection_id`required | `string (ulid)` | <!--source:api-specifications-->Collection ID<!--/source--> |
| `callback_url` | `string (uri)` | <!--source:api-specifications-->The URL which is used to send the result of the job<!--/source--> |
| `output`required | `object` | <!--source:api-specifications-->The data from rules applying<!--/source--> |
| `data` | `object` | <!--source:api-specifications-->Raw result data<!--/source--> |
| `metadata` | `object` | <!--source:api-specifications-->Metadata about output data<!--/source--> |
| `status` | `string` | <!--source:api-specifications-->Status of the data validity<!--/source-->`HAS_VALIDATION_ERRORS` |
| `status_message` | `string` | <!--source:api-specifications-->Status description<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

`GET` `/send-envelop`

<!--source:api-specifications-->

#### Get Ruleset Invocation Status
<!--/source-->

`getRulesetInvocationStatus`

<!--source:api-specifications-->
Returns the status of invoking Ruleset associated with the input collection(s) and output collection.

<!--/source-->

##### Response

<!--source:api-specifications-->
application/json Copy Created.

```
{
 "job_id": "01FM2G606MNKG8YKD62EB64DDR"
}
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
1
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `job_id` required | `string` path | `01FJC4JGKFX3VYB0EZ75JNY4J6` | <!--source:api-specifications-->Identifier of the data processing job.<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Created.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `job_id`required | `string (ulid)` | <!--source:api-specifications-->Identifier of the job<!--/source--> |

<!--source:api-specifications-->

### Rulesets
<!--/source-->

`GET` `/rulesets`

<!--source:api-specifications-->

#### Get Rulesets
<!--/source-->

`getRulesets`

<!--source:api-specifications-->
Get Rulesets returns a list of all the Rulesets.

<!--/source-->

##### Response

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "count": 2,
 "rulesets": [
 {
 "name": "selective_merge",
 "description": "The ruleset for smart selecting data.",
 "operation": "SELECTIVE_DATA_MERGE"
 },
 {
 "name": "aus_relationships",
 "description": "The ruleset for setting relationships between entities in v2 to the separated object to be able to map it to v0.",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ],
 "operation": "DATA_INFERRING"
 }
 ]
}
```

<!--/source-->

##### Response `200``application/json`

<!--source:api-specifications-->
2 fields
<!--/source-->
<!--source:api-specifications-->
OK.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `count`required | `integer` | <!--source:api-specifications-->The number of returned rulesets<!--/source--> |
| `rulesets`required | `object[]` | <!--source:api-specifications-->Rulesets list<!--/source--> |
| `ruleset` | `object` | <!--source:api-specifications-->Ruleset.<!--/source--> |
| `name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `description` | `string` | <!--source:api-specifications-->Ruleset description<!--/source-->Example `This ruleset can be used to select data from different collections.` |
| `operation`required | `string` | <!--source:api-specifications-->The purpose of the ruleset usage<!--/source-->`DATA_INFERRING``SELECTIVE_DATA_MERGE` |
| `global_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes<!--/source--> |
| `prefix` | `string` | <!--source:api-specifications-->Prefix that can be used in rules definitions<!--/source--> |
| `IRI` | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rules definitions<!--/source--> |
| `_links` | `object` | <!--source:api-specifications-->Links to endpoints related to the ruleset<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

`GET` `/rulesets/{ruleset_name}`

<!--source:api-specifications-->

#### Get Ruleset
<!--/source-->

`getRuleset`

<!--source:api-specifications-->
Get Ruleset returns the Ruleset information.

<!--/source-->

##### Response

<!--source:api-specifications-->
200 Selective Merge Ruleset200 Data Inferring Ruleset400
<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "name": "selective_merge",
 "description": "The ruleset for smart selecting data.",
 "operation": "SELECTIVE_DATA_MERGE",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "name": "validation_ruleset",
 "description": "The ruleset for validating if date of document is 2021 year.",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ],
 "operation": "DATA_INFERRING"
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
1
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `ruleset_name` required | `string` path | `my_ruleset` | <!--source:api-specifications-->Ruleset name<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
2 fields
<!--/source-->
<!--source:api-specifications-->
OK.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `ruleset` | `object` | <!--source:api-specifications-->Ruleset.<!--/source--> |
| `name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `description` | `string` | <!--source:api-specifications-->Ruleset description<!--/source-->Example `This ruleset can be used to select data from different collections.` |
| `operation`required | `string` | <!--source:api-specifications-->The purpose of the ruleset usage<!--/source-->`DATA_INFERRING``SELECTIVE_DATA_MERGE` |
| `global_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes<!--/source--> |
| `prefix` | `string` | <!--source:api-specifications-->Prefix that can be used in rules definitions<!--/source--> |
| `IRI` | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rules definitions<!--/source--> |
| `_links` | `object` | <!--source:api-specifications-->Links to endpoints related to the ruleset<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

`POST` `/rulesets`

<!--source:api-specifications-->

#### Create Ruleset
<!--/source-->

`createRuleset`

<!--source:api-specifications-->
Creates Ruleset enable creation of Ruleset with the below attributes:

- name: Name of the Ruleset.
- description: Description of the Ruleset.
- operation: Type of the operation that will be executed when Invoking the Ruleset, supported operations:
- SELECTIVE_DATA_MERGE: merge collections in a new collection.
- Input: Staircase Collection(s).
- Process: Create new collection by running the ruleset on the input collections.
- Output: A new collection generated from running the ruleset.
- DATA_INFERRING: modify existing collection.
- Input: Staircase Collection.
- Process: Modify the collection by running the Ruleset.
- Output: Modified collection.

<!--/source-->

##### Request

<!--source:api-specifications-->
Selective Merge RulesetData Inferring Ruleset
<!--/source-->

<!--source:api-specifications-->
application/json Copy
```
{
 "name": "selective_merge",
 "description": "The ruleset for smart selecting data.",
 "operation": "SELECTIVE_DATA_MERGE",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy
```
{
 "name": "validation_ruleset",
 "description": "The ruleset for validating if date of document is 2021 year.",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ],
 "operation": "DATA_INFERRING"
}
```

<!--/source-->

##### Response

<!--source:api-specifications-->
201 Selective Merge Ruleset201 Data Inferring Ruleset400
<!--/source-->

<!--source:api-specifications-->
application/json Copy Created.

```
{
 "name": "selective_merge",
 "description": "The ruleset for smart selecting data.",
 "operation": "SELECTIVE_DATA_MERGE",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy Created.

```
{
 "name": "validation_ruleset",
 "description": "The ruleset for validating if date of document is 2021 year.",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ],
 "operation": "DATA_INFERRING"
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Request body`application/json`

<!--source:api-specifications-->
4 fields
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `description` | `string` | <!--source:api-specifications-->Ruleset description<!--/source-->Example `This ruleset can be used to select data from different collections.` |
| `operation`required | `string` | <!--source:api-specifications-->The purpose of the ruleset usage<!--/source-->`DATA_INFERRING``SELECTIVE_DATA_MERGE` |
| `global_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes<!--/source--> |
| `prefix` | `string` | <!--source:api-specifications-->Prefix that can be used in rules definitions<!--/source--> |
| `IRI` | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rules definitions<!--/source--> |

##### Response `201``application/json`

<!--source:api-specifications-->
4 fields
<!--/source-->
<!--source:api-specifications-->
Created.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `description` | `string` | <!--source:api-specifications-->Ruleset description<!--/source-->Example `This ruleset can be used to select data from different collections.` |
| `operation`required | `string` | <!--source:api-specifications-->The purpose of the ruleset usage<!--/source-->`DATA_INFERRING``SELECTIVE_DATA_MERGE` |
| `global_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes<!--/source--> |
| `prefix` | `string` | <!--source:api-specifications-->Prefix that can be used in rules definitions<!--/source--> |
| `IRI` | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rules definitions<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `409``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource already exists.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

`PATCH` `/rulesets/{ruleset_name}`

<!--source:api-specifications-->

#### Update Ruleset
<!--/source-->

`updateRuleset`

<!--source:api-specifications-->
Update Ruleset updates specific Ruleset, method shall update:

- Description;
- Operation;
- Global RDF Prefixes.

<!--/source-->

##### Request

<!--source:api-specifications-->
Selective Merge RulesetData Inferring Ruleset
<!--/source-->

<!--source:api-specifications-->
application/json Copy
```
{
 "description": "The ruleset for smart selecting data.",
 "operation": "SELECTIVE_DATA_MERGE",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy
```
{
 "description": "The ruleset for validating if date of document is 2021 year.",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ],
 "operation": "DATA_INFERRING"
}
```

<!--/source-->

##### Response

<!--source:api-specifications-->
200 Selective Merge Ruleset200 Data Inferring Ruleset400
<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "description": "The ruleset for smart selecting data.",
 "operation": "SELECTIVE_DATA_MERGE",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "description": "The ruleset for validating if date of document is 2021 year.",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ],
 "operation": "DATA_INFERRING"
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
1
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `ruleset_name` required | `string` path | `my_ruleset` | <!--source:api-specifications-->Ruleset name<!--/source--> |

##### Request body`application/json`

<!--source:api-specifications-->
3 fields
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `description` | `string` | <!--source:api-specifications-->Ruleset description<!--/source-->Example `This ruleset can be used to select data from different collections.` |
| `operation` | `string` | <!--source:api-specifications-->The purpose of the ruleset usage<!--/source-->`DATA_INFERRING``SELECTIVE_DATA_MERGE` |
| `global_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes<!--/source--> |
| `prefix` | `string` | <!--source:api-specifications-->Prefix that can be used in rules definitions<!--/source--> |
| `IRI` | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rules definitions<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
3 fields
<!--/source-->
<!--source:api-specifications-->
OK.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `description` | `string` | <!--source:api-specifications-->Ruleset description<!--/source-->Example `This ruleset can be used to select data from different collections.` |
| `operation` | `string` | <!--source:api-specifications-->The purpose of the ruleset usage<!--/source-->`DATA_INFERRING``SELECTIVE_DATA_MERGE` |
| `global_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes<!--/source--> |
| `prefix` | `string` | <!--source:api-specifications-->Prefix that can be used in rules definitions<!--/source--> |
| `IRI` | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rules definitions<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

`DELETE` `/rulesets/{ruleset_name}`

<!--source:api-specifications-->

#### Delete Ruleset
<!--/source-->

`deleteRuleset`

<!--source:api-specifications-->
Delete Ruleset deletes a specific Ruleset.

<!--/source-->

##### Response

<!--source:api-specifications-->
200 Selective Merge Ruleset200 Data Inferring Ruleset400
<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "name": "selective_merge",
 "description": "The ruleset for smart selecting data.",
 "operation": "SELECTIVE_DATA_MERGE",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "name": "validation_ruleset",
 "description": "The ruleset for validating if date of document is 2021 year.",
 "global_rdf_prefixes": [
 {
 "prefix": "rdf",
 "IRI": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 },
 {
 "prefix": "",
 "IRI": "https://www.staircase.co/ontology/"
 },
 {
 "prefix": "reserved",
 "IRI": "https://www.staircase.co/reserved/"
 }
 ],
 "operation": "DATA_INFERRING"
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
1
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `ruleset_name` required | `string` path | `my_ruleset` | <!--source:api-specifications-->Ruleset name<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
4 fields
<!--/source-->
<!--source:api-specifications-->
OK.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `name`required | `string` | <!--source:api-specifications-->Ruleset name<!--/source-->Example `Some Ruleset` |
| `description` | `string` | <!--source:api-specifications-->Ruleset description<!--/source-->Example `This ruleset can be used to select data from different collections.` |
| `operation`required | `string` | <!--source:api-specifications-->The purpose of the ruleset usage<!--/source-->`DATA_INFERRING``SELECTIVE_DATA_MERGE` |
| `global_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes<!--/source--> |
| `prefix` | `string` | <!--source:api-specifications-->Prefix that can be used in rules definitions<!--/source--> |
| `IRI` | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rules definitions<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

<!--source:api-specifications-->

### Rules
<!--/source-->

`GET` `/rulesets/{ruleset_name}/rules`

<!--source:api-specifications-->

#### Get Rules
<!--/source-->

`getRules`

<!--source:api-specifications-->
Get Rules Return all the rules associated with a Ruleset. If Rules count > 200, response body will contain pagination link(s).

<!--/source-->

##### Response

<!--source:api-specifications-->
200 Selective Merge Rules200 Data Inferring Rules (Validation)400
<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "count": 2,
 "rules": [
 {
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :documents ?document .\n ?document ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MIN(?document_date_value) as ?earliest_date_value)\n WHERE\n {\n ?document :has_document_date / :has_value ?document_date_value .\n }\n }\n ?document :has_document_date / :has_value ?earliest_date_value .\n ?document ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
 },
 {
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :loan_terms ?loan_term .\n ?loan_term ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MAX(?payment_amount_value) as ?max_payment_amount_value)\n WHERE\n {\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?payment_amount_value .\n }\n }\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?max_payment_amount_value .\n ?loan_term ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "count": 4,
 "rules": [
 {
 "id": "PERCENT_IS_INTEGER_CONVERTABLE",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_DATA_FORMAT\" ;\n :has_validation_description \"Value is not integer.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n FILTER NOT EXISTS\n {\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value))\n }\n}\n"
 }
 },
 {
 "id": "NOT_LATER_THAN_TODAY",
 "definition": {
 "raw_sparql": "INSERT\n{\n\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Date is later than date of rule applying date.\"\n ]\n}\nWHERE\n{\n [] :documents / :has_document_date ?target_node .\n ?target_node :has_value ?document_date_value .\n BIND (NOW() as ?now)\n FILTER(\n ?document_date_value > CONCAT(\n STR(YEAR(?now)), \"-\", STR(MONTH(?now)), \"-\", STR(DAY(?now))\n )\n )\n}\n"
 }
 },
 {
 "id": "LOAN_AMORTIZATION_TYPE_IS_MISSING",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 404 ;\n :has_validation_code_type \"MISSING_DATA\" ;\n :has_validation_description \"Data is missing.\"\n ]\n}\nWHERE\n{\n [] :loan_terms / :has_loan_amortization_type ?target_node .\n FILTER NOT EXISTS { ?target_node :has_value ?value }\n}\n"
 }
 },
 {
 "id": "PERCENT_IS_GREATER_THAN_100",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Value is greater than 100.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value) > 100)\n}\n"
 }
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
3
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `ruleset_name` required | `string` path | `my_ruleset` | <!--source:api-specifications-->Ruleset name<!--/source--> |
| `sort` | `string` query | `asc` | <!--source:api-specifications-->Sorting direction<!--/source--> |
| `after_id` | `string` query | `a0533c96-937e-42cg-83b8-b63efe3cac8a` | <!--source:api-specifications-->Pagination marker. ID of the last rule from previous response.<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
3 fields
<!--/source-->
<!--source:api-specifications-->
OK.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `count`required | `integer` | <!--source:api-specifications-->The number of returned rules<!--/source--> |
| `_links`required | `object` | <!--source:api-specifications-->Pagination links<!--/source--> |
| `next` | `string` | <!--source:api-specifications-->Next page<!--/source--> |
| `previous` | `string` | <!--source:api-specifications-->Previous page<!--/source--> |
| `rules`required | `array` | <!--source:api-specifications-->Rules list<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

`GET` `/rulesets/{ruleset_name}/rules/{rule_id}`

<!--source:api-specifications-->

#### Get Rule
<!--/source-->

`getRule`

<!--source:api-specifications-->
Get Rule returns a specific Rule by ID and associated Ruleset name.

<!--/source-->

##### Response

<!--source:api-specifications-->
200 Selective Merge Rule 1200 Selective Merge Rule 2200 Constructing Entity Rule200 Data Validation Rule 1200 Data Validation Rule 2200 Data Validation Rule 3200 Data Validation Rule 4400
<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :documents ?document .\n ?document ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MIN(?document_date_value) as ?earliest_date_value)\n WHERE\n {\n ?document :has_document_date / :has_value ?document_date_value .\n }\n }\n ?document :has_document_date / :has_value ?earliest_date_value .\n ?document ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "id": "loan_terms_selection_rule",
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :loan_terms ?loan_term .\n ?loan_term ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MAX(?payment_amount_value) as ?max_payment_amount_value)\n WHERE\n {\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?payment_amount_value .\n }\n }\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?max_payment_amount_value .\n ?loan_term ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "definition": {
 "raw_sparql": "PREFIX: <https://www.staircase.co/ontology/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX reserved: <https://www.staircase.co/reserved/>\n\nCONSTRUCT\n{\n reserved:root :documents [\n :has_document_date [\n :has_value ?document_date_value ;\n :has_data_extraction_confidence_score ?max_document_date_confidence_score\n ] ;\n :has_document_misclassified_indicator [\n :has_value ?document_misclassified_indicator_value ;\n :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score\n ]\n ]\n}\nWHERE\n{\n # GET DOCUMENT DATE DATA BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score) as ?max_document_date_confidence_score)\n WHERE\n {\n ?any_document :has_document_date / :has_data_extraction_confidence_score ?confidence_score .\n }\n }\n ?any_document :has_document_date ?end_node .\n ?end_node :has_data_extraction_confidence_score ?max_document_date_confidence_score .\n ?end_node :has_value ?document_date_value .\n\n\n # GET MISCLASSIFIED INDICATOR BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score_2) as ?max_document_misclassified_indicator_confidence_score)\n WHERE\n {\n ?any_document_2 :has_document_misclassified_indicator / :has_data_extraction_confidence_score ?confidence_score_2 .\n }\n }\n ?any_document_2 :has_document_misclassified_indicator ?end_node_2 .\n ?end_node_2 :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score .\n ?end_node_2 :has_value ?document_misclassified_indicator_value .\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "id": "PERCENT_IS_INTEGER_CONVERTABLE",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_DATA_FORMAT\" ;\n :has_validation_description \"Value is not integer.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n FILTER NOT EXISTS\n {\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value))\n }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "id": "NOT_LATER_THAN_TODAY",
 "definition": {
 "raw_sparql": "INSERT\n{\n\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Date is later than date of rule applying date.\"\n ]\n}\nWHERE\n{\n [] :documents / :has_document_date ?target_node .\n ?target_node :has_value ?document_date_value .\n BIND (NOW() as ?now)\n FILTER(\n ?document_date_value > CONCAT(\n STR(YEAR(?now)), \"-\", STR(MONTH(?now)), \"-\", STR(DAY(?now))\n )\n )\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "id": "LOAN_AMORTIZATION_TYPE_IS_MISSING",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 404 ;\n :has_validation_code_type \"MISSING_DATA\" ;\n :has_validation_description \"Data is missing.\"\n ]\n}\nWHERE\n{\n [] :loan_terms / :has_loan_amortization_type ?target_node .\n FILTER NOT EXISTS { ?target_node :has_value ?value }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK.

```
{
 "id": "PERCENT_IS_GREATER_THAN_100",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Value is greater than 100.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value) > 100)\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
2
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `ruleset_name` required | `string` path | `my_ruleset` | <!--source:api-specifications-->Ruleset name<!--/source--> |
| `rule_id` required | `string` path | `my_rule` | <!--source:api-specifications-->Rule id (name)<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
4 fields
<!--/source-->
<!--source:api-specifications-->
OK.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | <!--source:api-specifications-->Rule ID. Can be specified to identify it later. Otherwise, it will be set automatically.<!--/source--> |
| `description` | `string` | <!--source:api-specifications-->Description of rule.<!--/source--> |
| `local_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes.<!--/source--> |
| `prefix`required | `string` | <!--source:api-specifications-->Prefix that can be used in rule definition.<!--/source--> |
| `IRI`required | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rule definition.<!--/source--> |
| `definition`required | `object` | <!--source:api-specifications-->Definition of rule.<!--/source--> |
| `raw_sparql`required | `string` | <!--source:api-specifications-->Raw SPARQL query (or insert) expression.<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

`POST` `/rulesets/{ruleset_name}/rules`

<!--source:api-specifications-->

#### Create Or Update Rules
<!--/source-->

`createOrUpdateRules`

<!--source:api-specifications-->
Create or Update Rules
<!--/source-->

<!--source:api-specifications-->
Create Or Update Rules enables creating or updating multiple Rules using the same request. The endpoint shall check the pre-existence of Rule by ID. If the id doesn't exist, the rule will be created.

<!--/source-->

##### Request

<!--source:api-specifications-->
Selective Merge RulesConstructing Entity RulesData Validation Rules
<!--/source-->

<!--source:api-specifications-->
application/json Copy
```
{
 "rules": [
 {
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :documents ?document .\n ?document ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MIN(?document_date_value) as ?earliest_date_value)\n WHERE\n {\n ?document :has_document_date / :has_value ?document_date_value .\n }\n }\n ?document :has_document_date / :has_value ?earliest_date_value .\n ?document ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
 },
 {
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :loan_terms ?loan_term .\n ?loan_term ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MAX(?payment_amount_value) as ?max_payment_amount_value)\n WHERE\n {\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?payment_amount_value .\n }\n }\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?max_payment_amount_value .\n ?loan_term ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy
```
{
 "rules": [
 {
 "definition": {
 "raw_sparql": "PREFIX: <https://www.staircase.co/ontology/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX reserved: <https://www.staircase.co/reserved/>\n\nCONSTRUCT\n{\n reserved:root :documents [\n :has_document_date [\n :has_value ?document_date_value ;\n :has_data_extraction_confidence_score ?max_document_date_confidence_score\n ] ;\n :has_document_misclassified_indicator [\n :has_value ?document_misclassified_indicator_value ;\n :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score\n ]\n ]\n}\nWHERE\n{\n # GET DOCUMENT DATE DATA BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score) as ?max_document_date_confidence_score)\n WHERE\n {\n ?any_document :has_document_date / :has_data_extraction_confidence_score ?confidence_score .\n }\n }\n ?any_document :has_document_date ?end_node .\n ?end_node :has_data_extraction_confidence_score ?max_document_date_confidence_score .\n ?end_node :has_value ?document_date_value .\n\n\n # GET MISCLASSIFIED INDICATOR BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score_2) as ?max_document_misclassified_indicator_confidence_score)\n WHERE\n {\n ?any_document_2 :has_document_misclassified_indicator / :has_data_extraction_confidence_score ?confidence_score_2 .\n }\n }\n ?any_document_2 :has_document_misclassified_indicator ?end_node_2 .\n ?end_node_2 :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score .\n ?end_node_2 :has_value ?document_misclassified_indicator_value .\n}\n"
 }
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy
```
{
 "rules": [
 {
 "id": "PERCENT_IS_INTEGER_CONVERTABLE",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_DATA_FORMAT\" ;\n :has_validation_description \"Value is not integer.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n FILTER NOT EXISTS\n {\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value))\n }\n}\n"
 }
 },
 {
 "id": "NOT_LATER_THAN_TODAY",
 "definition": {
 "raw_sparql": "INSERT\n{\n\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Date is later than date of rule applying date.\"\n ]\n}\nWHERE\n{\n [] :documents / :has_document_date ?target_node .\n ?target_node :has_value ?document_date_value .\n BIND (NOW() as ?now)\n FILTER(\n ?document_date_value > CONCAT(\n STR(YEAR(?now)), \"-\", STR(MONTH(?now)), \"-\", STR(DAY(?now))\n )\n )\n}\n"
 }
 },
 {
 "id": "LOAN_AMORTIZATION_TYPE_IS_MISSING",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 404 ;\n :has_validation_code_type \"MISSING_DATA\" ;\n :has_validation_description \"Data is missing.\"\n ]\n}\nWHERE\n{\n [] :loan_terms / :has_loan_amortization_type ?target_node .\n FILTER NOT EXISTS { ?target_node :has_value ?value }\n}\n"
 }
 },
 {
 "id": "PERCENT_IS_GREATER_THAN_100",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Value is greater than 100.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value) > 100)\n}\n"
 }
 }
 ]
}
```

<!--/source-->

##### Response

<!--source:api-specifications-->
200 Selective Merge Rules200 Constructing Entity Rules200 Data Validation Rules400
<!--/source-->

<!--source:api-specifications-->
application/json Copy OK. Created or updated.

```
{
 "rules": [
 {
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :documents ?document .\n ?document ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MIN(?document_date_value) as ?earliest_date_value)\n WHERE\n {\n ?document :has_document_date / :has_value ?document_date_value .\n }\n }\n ?document :has_document_date / :has_value ?earliest_date_value .\n ?document ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
 },
 {
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :loan_terms ?loan_term .\n ?loan_term ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MAX(?payment_amount_value) as ?max_payment_amount_value)\n WHERE\n {\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?payment_amount_value .\n }\n }\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?max_payment_amount_value .\n ?loan_term ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK. Created or updated.

```
{
 "rules": [
 {
 "definition": {
 "raw_sparql": "PREFIX: <https://www.staircase.co/ontology/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX reserved: <https://www.staircase.co/reserved/>\n\nCONSTRUCT\n{\n reserved:root :documents [\n :has_document_date [\n :has_value ?document_date_value ;\n :has_data_extraction_confidence_score ?max_document_date_confidence_score\n ] ;\n :has_document_misclassified_indicator [\n :has_value ?document_misclassified_indicator_value ;\n :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score\n ]\n ]\n}\nWHERE\n{\n # GET DOCUMENT DATE DATA BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score) as ?max_document_date_confidence_score)\n WHERE\n {\n ?any_document :has_document_date / :has_data_extraction_confidence_score ?confidence_score .\n }\n }\n ?any_document :has_document_date ?end_node .\n ?end_node :has_data_extraction_confidence_score ?max_document_date_confidence_score .\n ?end_node :has_value ?document_date_value .\n\n\n # GET MISCLASSIFIED INDICATOR BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score_2) as ?max_document_misclassified_indicator_confidence_score)\n WHERE\n {\n ?any_document_2 :has_document_misclassified_indicator / :has_data_extraction_confidence_score ?confidence_score_2 .\n }\n }\n ?any_document_2 :has_document_misclassified_indicator ?end_node_2 .\n ?end_node_2 :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score .\n ?end_node_2 :has_value ?document_misclassified_indicator_value .\n}\n"
 }
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy OK. Created or updated.

```
{
 "rules": [
 {
 "id": "PERCENT_IS_INTEGER_CONVERTABLE",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_DATA_FORMAT\" ;\n :has_validation_description \"Value is not integer.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n FILTER NOT EXISTS\n {\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value))\n }\n}\n"
 }
 },
 {
 "id": "NOT_LATER_THAN_TODAY",
 "definition": {
 "raw_sparql": "INSERT\n{\n\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Date is later than date of rule applying date.\"\n ]\n}\nWHERE\n{\n [] :documents / :has_document_date ?target_node .\n ?target_node :has_value ?document_date_value .\n BIND (NOW() as ?now)\n FILTER(\n ?document_date_value > CONCAT(\n STR(YEAR(?now)), \"-\", STR(MONTH(?now)), \"-\", STR(DAY(?now))\n )\n )\n}\n"
 }
 },
 {
 "id": "LOAN_AMORTIZATION_TYPE_IS_MISSING",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 404 ;\n :has_validation_code_type \"MISSING_DATA\" ;\n :has_validation_description \"Data is missing.\"\n ]\n}\nWHERE\n{\n [] :loan_terms / :has_loan_amortization_type ?target_node .\n FILTER NOT EXISTS { ?target_node :has_value ?value }\n}\n"
 }
 },
 {
 "id": "PERCENT_IS_GREATER_THAN_100",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Value is greater than 100.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value) > 100)\n}\n"
 }
 }
 ]
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
1
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `ruleset_name` required | `string` path | `my_ruleset` | <!--source:api-specifications-->Ruleset name<!--/source--> |

##### Request body`application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `rules`required | `array` | <!--source:api-specifications-->Rules list<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
OK. Created or updated.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `rules`required | `array` | <!--source:api-specifications-->Rules list<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `409``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource already exists.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

`DELETE` `/rulesets/{ruleset_name}/rules/{rule_id}`

<!--source:api-specifications-->

#### Delete Rule
<!--/source-->

`deleteRule`

<!--source:api-specifications-->
Delete Rules
<!--/source-->

<!--source:api-specifications-->
Delete Rule deletes a specific Rule using Rule ID and Ruleset name.

<!--/source-->

##### Response

<!--source:api-specifications-->
200 Selective Merge Rule 1200 Selective Merge Rule 2200 Constructing Entity Rule200 Data Validation Rule 1200 Data Validation Rule 2200 Data Validation Rule 3200 Data Validation Rule 4400
<!--/source-->

<!--source:api-specifications-->
application/json Copy Deleted.

```
{
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :documents ?document .\n ?document ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MIN(?document_date_value) as ?earliest_date_value)\n WHERE\n {\n ?document :has_document_date / :has_value ?document_date_value .\n }\n }\n ?document :has_document_date / :has_value ?earliest_date_value .\n ?document ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy Deleted.

```
{
 "id": "loan_terms_selection_rule",
 "definition": {
 "raw_sparql": "CONSTRUCT\n{\n reserved:root :loan_terms ?loan_term .\n ?loan_term ?p ?o .\n ?o ?po ?oo .\n}\nWHERE\n{\n {\n SELECT (MAX(?payment_amount_value) as ?max_payment_amount_value)\n WHERE\n {\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?payment_amount_value .\n }\n }\n ?loan_term :has_initial_principal_and_interest_payment_amount / :has_value ?max_payment_amount_value .\n ?loan_term ?p ?o .\n OPTIONAL { ?o ?po ?oo . }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy Deleted.

```
{
 "definition": {
 "raw_sparql": "PREFIX: <https://www.staircase.co/ontology/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX reserved: <https://www.staircase.co/reserved/>\n\nCONSTRUCT\n{\n reserved:root :documents [\n :has_document_date [\n :has_value ?document_date_value ;\n :has_data_extraction_confidence_score ?max_document_date_confidence_score\n ] ;\n :has_document_misclassified_indicator [\n :has_value ?document_misclassified_indicator_value ;\n :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score\n ]\n ]\n}\nWHERE\n{\n # GET DOCUMENT DATE DATA BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score) as ?max_document_date_confidence_score)\n WHERE\n {\n ?any_document :has_document_date / :has_data_extraction_confidence_score ?confidence_score .\n }\n }\n ?any_document :has_document_date ?end_node .\n ?end_node :has_data_extraction_confidence_score ?max_document_date_confidence_score .\n ?end_node :has_value ?document_date_value .\n\n\n # GET MISCLASSIFIED INDICATOR BY MAX CONFIDENCE SCORE\n {\n SELECT (MAX(?confidence_score_2) as ?max_document_misclassified_indicator_confidence_score)\n WHERE\n {\n ?any_document_2 :has_document_misclassified_indicator / :has_data_extraction_confidence_score ?confidence_score_2 .\n }\n }\n ?any_document_2 :has_document_misclassified_indicator ?end_node_2 .\n ?end_node_2 :has_data_extraction_confidence_score ?max_document_misclassified_indicator_confidence_score .\n ?end_node_2 :has_value ?document_misclassified_indicator_value .\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy Deleted.

```
{
 "id": "PERCENT_IS_INTEGER_CONVERTABLE",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_DATA_FORMAT\" ;\n :has_validation_description \"Value is not integer.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n FILTER NOT EXISTS\n {\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value))\n }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy Deleted.

```
{
 "id": "NOT_LATER_THAN_TODAY",
 "definition": {
 "raw_sparql": "INSERT\n{\n\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Date is later than date of rule applying date.\"\n ]\n}\nWHERE\n{\n [] :documents / :has_document_date ?target_node .\n ?target_node :has_value ?document_date_value .\n BIND (NOW() as ?now)\n FILTER(\n ?document_date_value > CONCAT(\n STR(YEAR(?now)), \"-\", STR(MONTH(?now)), \"-\", STR(DAY(?now))\n )\n )\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy Deleted.

```
{
 "id": "LOAN_AMORTIZATION_TYPE_IS_MISSING",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 404 ;\n :has_validation_code_type \"MISSING_DATA\" ;\n :has_validation_description \"Data is missing.\"\n ]\n}\nWHERE\n{\n [] :loan_terms / :has_loan_amortization_type ?target_node .\n FILTER NOT EXISTS { ?target_node :has_value ?value }\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
application/json Copy Deleted.

```
{
 "id": "PERCENT_IS_GREATER_THAN_100",
 "definition": {
 "raw_sparql": "INSERT\n{\n ?target_node :with_data_validation_metadata [\n rdf:type :data_validation_metadata ;\n :has_validation_code 400 ;\n :has_validation_code_type \"INVALID_BUSINESS_SENSE\" ;\n :has_validation_description \"Value is greater than 100.\"\n ]\n}\nWHERE\n{\n [] :payments / :has_late_charge_rate_percent ?target_node .\n ?target_node :has_value ?value .\n FILTER (xsd:integer(?value) > 100)\n}\n"
 }
}
```

<!--/source-->

<!--source:api-specifications-->
text/html Copy Bad request

```
<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n</body>\r\n</html>\r\n
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
2
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `ruleset_name` required | `string` path | `my_ruleset` | <!--source:api-specifications-->Ruleset name<!--/source--> |
| `rule_id` required | `string` path | `my_rule` | <!--source:api-specifications-->Rule id (name)<!--/source--> |

##### Response `200``application/json`

<!--source:api-specifications-->
4 fields
<!--/source-->
<!--source:api-specifications-->
Deleted.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | <!--source:api-specifications-->Rule ID. Can be specified to identify it later. Otherwise, it will be set automatically.<!--/source--> |
| `description` | `string` | <!--source:api-specifications-->Description of rule.<!--/source--> |
| `local_rdf_prefixes` | `object[]` | <!--source:api-specifications-->Array of RDF prefixes.<!--/source--> |
| `prefix`required | `string` | <!--source:api-specifications-->Prefix that can be used in rule definition.<!--/source--> |
| `IRI`required | `string` | <!--source:api-specifications-->IRI that will be used instead of prefix in rule definition.<!--/source--> |
| `definition`required | `object` | <!--source:api-specifications-->Definition of rule.<!--/source--> |
| `raw_sparql`required | `string` | <!--source:api-specifications-->Raw SPARQL query (or insert) expression.<!--/source--> |

##### Response `403``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Forbidden.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Response `404``application/json`

<!--source:api-specifications-->
1 fields
<!--/source-->
<!--source:api-specifications-->
Resource is not found.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `message`required | `string` | <!--source:api-specifications-->Message<!--/source--> |

##### Other responses

`400`

<!--source:api-specifications-->

### Operations
<!--/source-->

`POST` `/rule-engine`

<!--source:api-specifications-->

#### Create Rule Engine
<!--/source-->

`post-rule-engine`

<!--source:api-specifications-->
Create Rule Engine creates views of products, risk factors and other business intelligence that have been evaluated by a set of rules affecting the decisioning process.

<!--/source-->

##### Request

<!--source:api-specifications-->
application/json Copy
```
{
 "transaction_id": "uhz6t54e-9d74-g17e-99ca-a36b30vdfd35",
 "collection_id": "hg62e49f-9d74-g17e-99ca-a36b30vdfd35",
 "partner_name": "PartnerName"
}
```

<!--/source-->

##### Response

<!--source:api-specifications-->
application/json Copy Rule Engine request created successfully.

```
{
 "collection_id": "e4502ed2-8df8-4b8f-84bd-a1097e999a77",
 "message": "When ready, data will be available under the following collection_id. Use this new collection_id to get the execution status."
}
```

<!--/source-->

##### Parameters

<!--source:api-specifications-->
1
<!--/source-->

| Parameter | Type | Example | Description |
| --- | --- | --- | --- |
| `x-api-key` required | `string` header | `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` | <!--source:api-specifications-->Authorization key<!--/source--> |

##### Request body`application/json`

<!--source:api-specifications-->
3 fields
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `transaction_id`required | `string` | <!--source:api-specifications-->Transaction ID<!--/source--> |
| `collection_id`required | `string` | <!--source:api-specifications-->Collection ID<!--/source--> |
| `partner_name`required | `string` | — |

##### Response `200``application/json`

<!--source:api-specifications-->
2 fields
<!--/source-->
<!--source:api-specifications-->
Rule Engine request created successfully.
<!--/source-->

| Field | Type | Description |
| --- | --- | --- |
| `collection_id` | `string` | <!--source:api-specifications-->Collection ID<!--/source--> |
| `message` | `string` | <!--source:api-specifications-->Message<!--/source--> |

## Errors

`400``403``404``409``422`

## More in Data

- Previous product: Persistence
- Next product: Site
