# Validation API

{% hint style="warning" %}
We strongly recommend reviewing [How to: Set data validations](/build-spark-services/set-data-validations.md#prerequisites-for-dynamic-validation) before continuing with this section.
{% endhint %}

Returns: Input validation parameters.

{% code overflow="wrap" %}

```shellscript
## Depending on the desired reference parameter, different URI are available.
POST /{tenant}/api/v3/folders/{folder}/services/{service}/validation
POST /{tenant}/api/v3/service/{serviceId}/validation
POST /{tenant}/api/v3/version/{versionId}/validation
POST /{tenant}/api/v3/public/folders/{folder}/services/{service}/validation
POST /{tenant}/api/v3/public/service/{version}/validation
POST /{tenant}/api/v3/public/version/{versionId}/validation
```

{% endcode %}

### Authorization

* `Bearer {token}` accessible from [Authorization - Bearer token](/spark-apis/authorization-bearer-token.md) or systematically via [Client Credentials](/identity-and-access-management/client-credentials.md).
  * The request headers should include a key for `Authorization` with the value `Bearer {token}`.
* API key created from [Authorization - API keys](/spark-apis/authorization-api-keys.md).
  * The request headers should include the keys `x-synthetic-key` and `x-tenant-name` with the values of the API key and tenant name respectively.
* No Authorization is required for [Authorization - Public APIs](/spark-apis/authorization-public-apis.md).

### Path parameters

<table><thead><tr><th width="374">Key</th><th>Value</th></tr></thead><tbody><tr><td><code>environment</code> *</td><td>Environment is part of your <a data-mention href="/pages/-MboyUpg0GSvjBVkVMcw#log-in-to-spark">/pages/-MboyUpg0GSvjBVkVMcw#log-in-to-spark</a> URL.</td></tr><tr><td><code>tenant</code> *</td><td>Tenant is part of your <a data-mention href="/pages/-MboyUpg0GSvjBVkVMcw#log-in-to-spark">/pages/-MboyUpg0GSvjBVkVMcw#log-in-to-spark</a> URL and also available in the  <a data-mention href="/pages/ylWjjoVBLOcB7JZks4Cp#user-menu">/pages/ylWjjoVBLOcB7JZks4Cp#user-menu</a>.</td></tr><tr><td><code>folder</code> *</td><td>Folder associated with the request.</td></tr><tr><td><code>service</code> *</td><td>Service associated with the request.</td></tr><tr><td><code>serviceId</code> *</td><td><code>service_id</code> of the requested service. The latest service version will be referenced.</td></tr><tr><td><code>versionId</code> *</td><td><code>version_id</code> of the requested service version.</td></tr></tbody></table>

### Request body <a href="#request-body" id="request-body"></a>

`Content-Type: application/json`

Follows from [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md) [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md#request-body).

There is one additional parameter in the [Execute API](/spark-apis/execute-api.md#request_meta) that controls whether the static or dynamic validations are returned. When a service is uploaded to Spark, the validations based upon the default values are saved into a validation file. This eliminates the need for Spark to process the validations on every single API call.

| Key                            | Value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request_meta.validation_type` | <p><code>default\_values</code> returns the pre-processed validations that are <code>static</code> or <code>dynamic</code> (see below for more information). If no parameter is provided, the <code>default\_values</code> will be returned.</p><p><code>dynamic</code> returns the updated validations for the validations identified as <code>dynamic</code> based upon the <code>request\_data</code>. This only returns the validations that are different than those stored in the validation file.</p> |

### Response body <a href="#api-response" id="api-response"></a>

`Content-Type: application/json`

Follows from [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md) [Execute API (v3)](/spark-apis/execute-api/execute-api-v3.md#response-body). For each input the API will also return the properties of the validation as an output.

| Key                | Value                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `validation_type`  | <p><code>dynamic</code> the definition of the validation in this cell changes depending on another input.</p><ul><li>This is not the exactly same as a validation that contains formulas, e.g. if a validation range is linked to static numbers, it would not be considered as <code>dynamic</code>.</li></ul><p><code>static</code> validation in this cell does not depend on another input.</p> |
| `dependent_inputs` | <p>List of input fields that would be impacted by this particular validation. For example, if Age and Gender are used to determine the Products that can be offered, then for the validation of Age and Gender, Products would be included as a dependent input.</p><p><code>null</code> if no dependent inputs.</p>                                                                                |
| `validation_allow` | Relates to Excel Data Validation allow format types, e.g. `Decimal`, `List`, `Date`.                                                                                                                                                                                                                                                                                                                |
| `ignore_blank`     | <p>Shows <code>TRUE</code> or <code>FALSE</code> depending on the value of the Excel Data Validation <code>Ignore blank</code> checkbox.</p><p>Excel <code>Ignore blank</code> is an unusual feature. When this is <code>FALSE</code> it does not mean the value entered of the cell cannot be blank.</p>                                                                                           |
| `min`              | <p>Minimum value for an input, <code>null</code> if no <code>min</code> validation.<br>If this is a dynamic validation field, this will store the initial validation based upon the default values.</p>                                                                                                                                                                                             |
| `max`              | <p>Maximum value for a numeric input, <code>null</code> if no <code>max</code> validation.<br>If this is a dynamic validation field, this will store the initial validation based upon the default values.</p>                                                                                                                                                                                      |
| `options`          | <p>Enumerated list of the validations, <code>null</code> if no enumerated validation.<br>If this is a dynamic validation field, this will store the initial validation based upon the default values.</p>                                                                                                                                                                                           |

### Sample file <a href="#sample-api" id="sample-api"></a>

In this example, the choice of `01_letter` from `list_a` affects the valid list of `02_number` from `list_b`. Note that the choice of default values are important when defining the workbook.

<figure><img src="/files/LV6gmEI31wt9DhHeAJut" alt=""><figcaption></figcaption></figure>

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

To use this example file you will need to do the following:

1. Upload this service to Spark.
2. Call the API externally, for example using [Postman](/integrations/postman.md).
3. Modify the API URI following a valid URI. In most cases, modifying the existing endpoint URI from `/execute` to `/validation` should work.

#### `validation_type` `static`

**Sample request**

* Empty `request_data` and `request_meta` to extract the `default_values` validation.

```json
{
  "request_data": {},
  "request_meta": {}
}
```

**Sample response**

* `01_number` is `validation_type` `static`.
* `02_number` is `validation_type` `dynamic`.
* `02_number` is a `dependent_input` of `01_letter`.

```json
{
    "status": "Success",
    "response_data": {
        "outputs": {
            "01_letter": {
                "validation_allow": "List",
                "validation_type": "static",
                "dependent_inputs": [
                    "02_number"
                ],
                "min": null,
                "max": null,
                "options": [
                    "a",
                    "b"
                ],
                "ignore_blank": true
            },
            "02_number": {
                "validation_allow": "List",
                "validation_type": "dynamic",
                "dependent_inputs": null,
                "min": null,
                "max": null,
                "options": [
                    "1",
                    "2"
                ],
                "ignore_blank": true
            }
        },
        "warnings": null,
        "errors": null,
        "service_chain": null
    },
    "response_meta": {
        "service_id": "f9c4fc11-9112-4abf-b75a-cd0579e313ac",
        "version_id": "70c60d67-590d-4805-8c40-c5870e6161fb",
        "version": "1.0.0",
        "process_time": 0,
        "call_id": "2aebf898-09df-49d9-8a0b-935c7486fb9d",
        "compiler_type": "Type3",
        "compiler_version": "1.0.0",
        "source_hash": null,
        "engine_id": "9AE2AFFB74E404D221C7DDF3AC11CEF7",
        "correlation_id": null,
        "parameterset_version_id": null,
        "system": "SPARK",
        "request_timestamp": "2022-10-03T12:09:14.392Z"
    },
    "error": null
}
```

#### `validation_type` `dynamic` part 1

Please also reference [How to: Set data validations](/build-spark-services/set-data-validations.md#prerequisites-for-dynamic-validation).

**Sample request**

* Set `01_letter` to `b` and `validation_type` to `dynamic`.

```json
{
  "request_data": {
    "inputs": {
      "01_letter": "b"
    }
  },
  "request_meta": {
      "validation_type": "dynamic"
  }
}
```

**Sample response**

* The updated validation for `02_number` is returned.
* Note the response has an error because no value for `02_number` was submitted.
* Therefore the default value in the spreadsheet of `02_number` = `1` was used which led to a validation error.

```json
{
    "status": "Success",
    "response_data": {
        "outputs": {
            "02_number": {
                "validation_allow": "List",
                "validation_type": "dynamic",
                "dependent_inputs": null,
                "min": null,
                "max": null,
                "options": [
                    "23",
                    "24",
                    "25",
                    "26"
                ],
                "ignore_blank": true
            }
        },
        "warnings": null,
        "errors": [
            {
                "error_category": "validation_error",
                "error_type": "error.VALIDATION",
                "additional_details": null,
                "source_path": "$.Input.02_number",
                "message": "Input must be one of: 23, 24, 25, 26"
            }
        ],
        "service_chain": null
    },
    "response_meta": {
        "service_id": "f9c4fc11-9112-4abf-b75a-cd0579e313ac",
        "version_id": "70c60d67-590d-4805-8c40-c5870e6161fb",
        "version": "1.0.0",
        "process_time": 0,
        "call_id": "b392cf0d-8acf-4bf6-9d7b-2c1a15d0b509",
        "compiler_type": "Type3",
        "compiler_version": "1.0.0",
        "source_hash": null,
        "engine_id": "9AE2AFFB74E404D221C7DDF3AC11CEF7",
        "correlation_id": null,
        "parameterset_version_id": null,
        "system": "SPARK",
        "request_timestamp": "2022-10-04T12:50:55.145Z"
    },
    "error": null
}
```

#### `validation_type` `dynamic` part 2

**Sample request**

* Set `01_letter` to `b` and `02_number` to `23` and `validation_type` to `dynamic`.

```json
{
  "request_data": {
    "inputs": {
      "01_letter": "b",
      "02_number": 23
    }
  },
  "request_meta": {
      "validation_type": "dynamic"
  }
}
```

**Sample response**

* The updated validation for `02_number` is returned without errors.

```json
{
    "status": "Success",
    "response_data": {
        "outputs": {
            "02_number": {
                "validation_allow": "List",
                "validation_type": "dynamic",
                "dependent_inputs": null,
                "min": null,
                "max": null,
                "options": [
                    "23",
                    "24",
                    "25",
                    "26"
                ],
                "ignore_blank": true
            }
        },
        "warnings": null,
        "errors": null,
        "service_chain": null
    },
    "response_meta": {
        "service_id": "f9c4fc11-9112-4abf-b75a-cd0579e313ac",
        "version_id": "70c60d67-590d-4805-8c40-c5870e6161fb",
        "version": "1.0.0",
        "process_time": 0,
        "call_id": "c7739cf5-7297-48f9-a3c5-a13b5e7aa1f6",
        "compiler_type": "Type3",
        "compiler_version": "1.0.0",
        "source_hash": null,
        "engine_id": "9AE2AFFB74E404D221C7DDF3AC11CEF7",
        "correlation_id": null,
        "parameterset_version_id": null,
        "system": "SPARK",
        "request_timestamp": "2022-10-04T12:54:08.742Z"
    },
    "error": null
}
```


---

# Agent Instructions: 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:

```
GET https://docs.coherent.global/spark-apis/validation-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
