> ## Documentation Index
> Fetch the complete documentation index at: https://docs.unifygtm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send records via API

> Send form submissions to Unify and use them in plays.

## Overview

Use the Data API to bring data from your application into Unify. This guide
creates a `website_form_fill` object, sends a form submission with its related
person, and uses that relationship to find people for a play.

Each form fill belongs to one person. A person can have many form fills, so
repeat submissions remain separate records.

## Before you begin

[Generate an API key](https://docs.unifygtm.com/developers/api/data/overview.md#authentication)
and set it as the `UNIFY_API_KEY` environment variable.

> [!WARNING]
>
> This guide uses a sensitive API key. Use it only in backend or server-side
> applications. Never expose it in frontend or client-side code.

## Create the object and attributes

Create the object and attributes once, either in Unify or through the Data API:

| Attribute | Purpose |
| - | - |
| `submission_id` | A unique ID from your form system, used to match retries to the same submission. |
| `form_name` | The submitted form, such as “Request a demo.” |
| `person` | A reference to the person who submitted it. |

**1. Create the object**

> [tab] In Unify
>
> Open [**Settings → Data management**](https://app.unifygtm.com/dashboard/settings/data/data-management)
> and click **New object**. Enter `Website form fills` as the object name and
> `website_form_fill` as the API name, then click **Create object**.
>
> The New object dialog with Website form fills as the name and website\_form\_fill as the API name.

> [tab] Via API
>
> Use [Create object](https://docs.unifygtm.com/developers/api/data/objects/create.md) to define
> `website_form_fill`.
>
> ```bash theme={null}
> curl --request POST \
>   --url "https://api.unifygtm.com/data/v1/objects" \
>   --header "X-Api-Key: $UNIFY_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{
>   "api_name": "website_form_fill",
>   "display_name": "Website form fills",
>   "description": "Submissions from website forms."
> }'
> ```

**2. Add the submission attributes**

> [tab] In Unify
>
> In the object's **Attributes** tab, click **Create attribute** and choose
> **Text**. Create these two attributes:
>
> | Attribute name | Attribute API name |
> | - | - |
> | Submission ID | `submission_id` |
> | Form name | `form_name` |
>
> For Submission ID, select **Make attribute required** and **Make attribute unique**.
> Leave both options off for Form name. Click **Create attribute** to save each attribute.
>
> A text attribute named Submission ID with required and unique enabled.

> [tab] Via API
>
> Use [Create attribute](https://docs.unifygtm.com/developers/api/data/attributes/create.md) for the
> submission ID and form name. Making `submission_id` unique lets you upsert
> the same submission again without creating a duplicate.
>
> ```bash title="Create submission_id" theme={null}
> curl --request POST \
>   --url "https://api.unifygtm.com/data/v1/objects/website_form_fill/attributes" \
>   --header "X-Api-Key: $UNIFY_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{
>   "api_name": "submission_id",
>   "display_name": "Submission ID",
>   "type": "TEXT",
>   "description": "Unique identifier from the form submission.",
>   "is_required": true,
>   "is_unique": true
> }'
> ```
>
> ```bash title="Create form_name" theme={null}
> curl --request POST \
>   --url "https://api.unifygtm.com/data/v1/objects/website_form_fill/attributes" \
>   --header "X-Api-Key: $UNIFY_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{
>   "api_name": "form_name",
>   "display_name": "Form name",
>   "type": "TEXT",
>   "description": "The form that was submitted.",
>   "is_required": false,
>   "is_unique": false
> }'
> ```

**3. Reference the person**

> [tab] In Unify
>
> Click **Create attribute**, choose **Relationship**, and select **Person**
> as the related object. Configure the two sides as follows:
>
> * On Website form fills, name the attribute `Person` with API name `person`.
>   Set it to reference **one** person.
> * On Person, name the attribute `Website form fills` with API name
>   `website_form_fills`. Set it to reference **many** form fills.
>
> Click **Create attribute**. The reverse reference lets you filter people by
> their submissions.
>
> A relationship connecting each website form fill to one person and each person to many website form fills.

> [tab] Via API
>
> Create a `person` reference with cardinality `ONE`. The `related_attribute`
> also creates `website_form_fills` on the person object with cardinality
> `MANY`. This reverse reference lets you filter people by their submissions.
>
> ```bash theme={null}
> curl --request POST \
>   --url "https://api.unifygtm.com/data/v1/objects/website_form_fill/attributes" \
>   --header "X-Api-Key: $UNIFY_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{
>   "api_name": "person",
>   "display_name": "Person",
>   "type": "REFERENCE",
>   "description": "The person who submitted the form.",
>   "is_unique": false,
>   "cardinality": "ONE",
>   "related_object": "person",
>   "related_attribute": {
>     "api_name": "website_form_fills",
>     "display_name": "Website form fills",
>     "cardinality": "MANY"
>   }
> }'
> ```

## Upsert a form fill and its person

Use [Upsert record](https://docs.unifygtm.com/developers/api/data/records/upsert.md) each time your server
receives a submission. This request matches the form fill by `submission_id`
and the person by email. It creates either record if needed and connects them
through the `person` reference.

```bash theme={null}
curl --request POST \
  --url "https://api.unifygtm.com/data/v1/objects/website_form_fill/records/upsert" \
  --header "X-Api-Key: $UNIFY_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "match": {
    "submission_id": "form-fill-001"
  },
  "create_or_update": {
    "submission_id": "form-fill-001",
    "form_name": "Request a demo",
    "person": {
      "match": {
        "email": "bob.smith@example.com"
      },
      "create_or_update_if_empty": {
        "email": "bob.smith@example.com",
        "first_name": "Bob",
        "last_name": "Smith"
      }
    }
  }
}'
```

`create_or_update` replaces the form fill’s values when the submission already
exists. The nested `create_or_update_if_empty` preserves the person's existing
name while filling missing values. You do not need to look up the person's
Unify ID first.

Reuse the submission ID when retrying a request. Use a new ID for each new
submission, even when the same person submits the form again.

## Trigger a play for matching people

Create a play with a **Record matches criteria** trigger and choose **People**.
Use the **Website form fills** reference to filter for people with a related
record whose **Form name** is “Request a demo”.

A play trigger finds people with a related website form fill whose form name is Request a demo.

The trigger returns people, so you can connect it directly to a person action,
such as enrolling them in a sequence. See [play triggers](https://docs.unifygtm.com/reference/plays/triggers.md#record-matches-criteria)
for the full setup.

By default, a person runs through a play once, even if they submit multiple
forms. [Play settings](https://docs.unifygtm.com/reference/plays/play-settings.md) control when they
can run again. Matching people can enter when you publish the play and on
subsequent scheduled checks.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.