> For the complete documentation index, see [llms.txt](https://docs.coherent.global/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherent.global/spark-apis/validation-apis.md).

# Validation APIs

{% hint style="warning" %}
Review [Inputs and outputs (Xinput and Xoutput)](/build-spark-services/additional-mappings/inputs-and-outputs-xinput-and-xoutput.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/public-apis.md).

### Path parameters

| Key            | Value                                                                                                                     |
| -------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `tenant` \*    | Tenant is part of your sign-in URL and also available in the [Navigation menu](/navigation/navigation-menu.md#user-menu). |
| `folder` \*    | Folder associated with the request.                                                                                       |
| `service` \*   | Service associated with the request.                                                                                      |
| `serviceId` \* | `service_id` of the requested service. The latest service version will be referenced.                                     |
| `versionId` \* | `version_id` of the requested service version.                                                                            |

### 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 exactly the 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 inpu</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="https://2714190325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fc7fek1ZgAUH5MA3m5pH8%2Fuploads%2FrYLWUCPF8moIg6FTOBmc%2Fimage.png?alt=media&amp;token=5a3ed921-3b17-4671-808a-8ebad6bc0625" alt=""><figcaption></figcaption></figure>

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

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

1. Upload this service to Spark.
2. Call the API externally.
3. Modify the API URL following a valid URL. In most cases, modifying the existing endpoint URL from `/execute` to `/validation` should work.

#### `validation_type` `static`

{% tabs %}
{% tab title="Sample request body" %}

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

<details>

<summary></summary>

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

</details>
{% endtab %}

{% tab title="Sample response" %}

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

<details>

<summary></summary>

`HTTP 200 OK` `Content-Type: application/json`

```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": {
        ...
    },
    "error": null
}
```

</details>
{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Sample request body" %}

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

<details>

<summary></summary>

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

</details>
{% endtab %}

{% tab title="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.

<details>

<summary></summary>

`HTTP 200 OK` `Content-Type: application/json`

```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": {
        ...
    },
    "error": null
}
```

</details>
{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Sample request body" %}

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

<details>

<summary></summary>

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

</details>
{% endtab %}

{% tab title="Sample response" %}

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

<details>

<summary></summary>

`HTTP 200 OK` `Content-Type: application/json`

```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": {
        ...
    },
    "error": null
}
```

</details>
{% endtab %}
{% endtabs %}
