# Schema options

## Introduction

Schemas aren't mandatory but they make things much simpler when building process flows. If your flow includes endpoints associated with schemas, any field selector options in process flow shapes are populated with the schema structure - all you need to do is choose the required field.&#x20;

For example, the [filter shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/filter-shape/using-regex-for-string-type-filters) below is picking up the schema associated with the Shopify endpoint, configured in the preceding connector shape:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F9FOBsJsHPnzaYAXxDwd9%2Fhow%20are%20schemas%20used.png?alt=media&#x26;token=890f4d78-cc23-4356-92ec-31a5de1c7509" alt=""><figcaption></figcaption></figure>

If a process flow uses an endpoint *without* a schema, any field paths defined in shapes must be defined manually.

{% hint style="info" %}
The required schema for your third-party application should be available in the associated API documentation.&#x20;
{% endhint %}

{% hint style="info" %}
When you add a schema, you can also choose to [apply field tags](https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/endpoint-options/schema-taxonomy/field-tagging).
{% endhint %}

## Adding a schema

To apply a schema for an endpoint, follow the steps below.

{% stepper %}
{% step %}
**Edit the endpoint schema**

Click the `edit schema` button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FYX19R6rjGuQFU3c9Ta0k%2Fschema%202.png?alt=media&#x26;token=70d64545-a566-4c17-be80-3772e01a5b33" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Add the schema for your endpoint**

Paste in the required schema and save changes:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FIizfnLM6TQeWLkRUdAJ5%2Fschema%203.png?alt=media&#x26;token=e780c3d0-8ffe-49a8-b54d-342cfe797b24" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
If you can't find a schema in your API documentation, you can run the API request in Postman, and then copy/paste the response as the schema.
{% endhint %}
{% endstep %}
{% endstepper %}

## Setting a data path

Use the `data path` field to define the hierarchical level to be used for [field tags](https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/endpoint-options/schema-taxonomy/field-tagging) and [filters](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/filter-shape):

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F661RTPHpEb38nGrS3T5m%2Fschema%204.png?alt=media&#x26;token=7386c3a3-3580-41f3-b29b-3c247ae81799" alt=""><figcaption></figcaption></figure></div>

This is particularly important for JSON payloads, where the data structure is nested. Let's take an example below:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FyFAncS1SCRu2Ap0TKJ0I%2Fschema%201.png?alt=media&#x26;token=26bc408f-04e5-42d3-b624-6f7b7198e3b1" alt=""><figcaption></figcaption></figure>

Here, all of our data is nested within one, top-level **customers** array object. If you scan down this example, you'll notice that there are two customer objects, each starting with an id for a customer record:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FNFLCHOZnCi2LJ8D9f7aV%2Fschema%202.png?alt=media&#x26;token=c23cb96e-c298-4410-a545-25cb458a5b4e" alt=""><figcaption></figcaption></figure>

Now let's look at the `data path` field at the bottom of this page:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FC2NXlH2DLDd7X1na5sFz%2Fschema%203.png?alt=media&#x26;token=98b19e0d-5dd0-42c6-a316-9571f42503f4" alt=""><figcaption></figcaption></figure>

If we leave this set to `empty`, any subsequent field tags, mappings and filters will work on the basis that the top-level array object is our target. What we'd be saying in this scenario is 'don't treat the nested objects as separate records'.&#x20;

So, for example, if we went on to apply a filter to match on `first_name` `contains` `bob`, we'd find a match in the second customer object but ALL objects would be returned because we're targeting the top-level array object. This isn't what we want - we need to treat each of the lower-level customer objects as separate records. To do this, we navigate the data path and select the parent object - in this case, its `customers`:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FQvB6azwneNaKH62d2CSQ%2Fschema%204.png?alt=media&#x26;token=12eb3152-9790-4a97-8cd1-0f2eca2c78bb" alt=""><figcaption></figcaption></figure>

When you save your new data path, you won't see any changes to the schema - but the change will be applied in the [field tagging](https://doc.wearepatchworks.com/product-documentation/developer-hub/connector-builder/building-your-own-connector/4-endpoints/endpoint-options/schema-taxonomy/field-tagging) tab. Here, the schema preview shows the structure that applies as per your selected data path in the **schema** tab.&#x20;

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FpLMO12yvTCxi9PorCt53%2Ficons8-film.svg?alt=media&#x26;token=e59864bc-2d97-4f98-966c-a083c18e60db" alt="" data-size="line"> Show me</summary>

![](https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FFWo0DkMdTfPktPx9dwQY%2Fdata%20paths.gif?alt=media\&token=78c867c3-cd89-42bd-a2b4-0b2b909b77cd)

</details>

When you come to use instances of this connector in process flows and apply a [filter shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/filter-shape), you'll see confirmation of the selected `data path` in filter settings - for example:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FaMVd126hZeE37UHqsOLO%2Fschema%205.png?alt=media&#x26;token=68ebf53f-aec8-46df-984c-8bffc9b80f24" alt=""><figcaption></figcaption></figure>
