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

# Sending Conversion Events to TikTok via the API

> Upload offline conversion events to Narrative and send them to a TikTok Offline Event Set over the API

This guide shows you how to build an unattended integration that uploads offline conversion events, such as in-store purchases or phone orders, to Narrative and sends them to TikTok. TikTok matches each event to its users by hashed email or phone number and attributes it to your campaigns.

Before you start, complete the [prerequisites](/guides/connector-apis/tiktok#prerequisites) and [set up API access](/guides/connector-apis/tiktok#set-up-api-access). You need a profile ID and the ID of an [Offline Event Set](/guides/connector-apis/tiktok#an-offline-event-set-id) in TikTok Events Manager.

## 1. Create the dataset

A conversion-event dataset needs two columns:

* `tiktok_conversion_event`, an object holding the event
* at least one identifier TikTok can match on, such as `sha256_hashed_email`

```bash theme={null}
curl -X POST https://api.narrative.io/datasets \
  -H "Authorization: Bearer $NIO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "store_purchases_tiktok",
    "display_name": "Store Purchases (TikTok)",
    "description": "Offline purchases for TikTok",
    "write_mode": "append",
    "schema": {
      "file_config": { "type": "json", "normalize_field_names": false },
      "type": "object",
      "properties": {
        "tiktok_conversion_event": {
          "type": "object",
          "properties": {
            "event_set_id":    { "type": "string" },
            "event_id":        { "type": "string" },
            "event_name":      { "type": "string" },
            "event_timestamp": { "type": "timestamptz" },
            "properties": {
              "type": "object",
              "properties": {
                "value":    { "type": "double" },
                "currency": { "type": "string" },
                "order_id": { "type": "string" }
              }
            }
          }
        },
        "sha256_hashed_email": {
          "type": "object",
          "properties": { "value": { "type": "string" } }
        }
      }
    }
  }'
# → {"id": 12347, "company_id": 1234, "display_name": "Store Purchases (TikTok)", ...}
```

Column names are case sensitive, so keep them lowercase as shown. Activation locks the schema, so add every field you plan to send before you activate.

Record the `id` in the response, then activate the dataset:

```bash theme={null}
curl -X POST https://api.narrative.io/datasets/{dataset_id}/activate \
  -H "Authorization: Bearer $NIO_API_TOKEN"
```

### Required columns

The `tiktok_conversion_event` column is an object with these properties:

| Property | Type | Required | Meaning |
| - | - | :-: | - |
| `event_set_id` | `string` | ✓ | The Offline Event Set that receives the event |
| `event_name` | `string` | ✓ | A TikTok standard event name, such as `Purchase`, `Lead`, or `CompleteRegistration`. Values are case sensitive. See [Event names](/reference/connectors/tiktok-conversions-api#event-names) |
| `event_timestamp` | `timestamptz` | ✓ | When the conversion happened |
| `event_id` | `string` | | Your unique ID for the event, such as an order number |
| `properties` | object | | Order details. See [Properties fields](/reference/connectors/tiktok-conversions-api#properties-fields) |

Every field in `properties` is optional:

| Field | Type |
| - | - |
| `value` | `double` |
| `currency`, `content_type`, `search_string`, `description`, `order_id`, `shop_id` | `string` |
| `num_items` | `long` |
| `content_ids` | An array of strings |
| `contents` | An array of objects, each with `content_id` (`string`, required), `quantity` (`long`, required), `content_name`, `content_category`, `brand` (`string`), and `price` (`double`) |

The dataset also needs at least one of these identifier columns. TikTok matches offline events on email and phone number:

| Column | Shape of each value |
| - | - |
| `sha256_hashed_email` | `{"value": ...}` |
| `hashed_email` | `{"value": ..., "type": "..."}` |
| `narrative_id` | `{"context": "...", "value": ...}` |
| `e164_phone_number` | A string |
| `telephone_number` | A string |

Each identifier column is named after its Rosetta Stone attribute, and the connector matches on that column name. A column holds either a plain string or an object. In the dataset schema, declare a string column with `"type": "string"`, and declare an object column with `"type": "object"` and its properties:

```json theme={null}
{
  "type": "object",
  "properties": {
    "<string_attribute>": { "type": "string" },
    "<object_attribute>": {
      "type": "object",
      "properties": { "<property>": { "type": "<type>" } }
    }
  }
}
```

Send an object column as an object in each row:

```json theme={null}
{"<string_attribute>": "...", "<object_attribute>": {"<property>": "..."}}
```

See your connector's reference page for the attributes it accepts and their exact shapes.

A row with the required properties and one identifier looks like this:

```json theme={null}
{"tiktok_conversion_event": {"event_set_id": "<EVENT_SET_ID>", "event_name": "Purchase", "event_timestamp": "2026-10-03T14:40:00Z"}, "sha256_hashed_email": {"value": "<SHA-256 of the trimmed, lowercased email>"}}
```

## 2. Confirm TikTok accepts the dataset

Before you create a connection, ask Narrative which connector interfaces the dataset satisfies:

```bash theme={null}
curl -s https://api.narrative.io/datasets/{dataset_id}/interfaces \
  -H "Authorization: Bearer $NIO_API_TOKEN"
# → {"dataset_id": 12345,
#    "accepted": [{"app_id": <APP_ID>, "interface_id": "<INTERFACE_ID>"}, ...],
#    "errors": [{"app_id": <APP_ID>, "interface_id": "<INTERFACE_ID>", "details": {...}}, ...]}
```

The response checks the dataset's schema against every interface of the connectors your company has installed, and sorts the results into two lists:

* `accepted` lists each interface you can connect the dataset to, by the connector's `app_id` and the `interface_id`.
* `errors` lists each interface the schema does not satisfy. Its `details` hold the reason, such as `"required property '<column>' not found"`.

Add `?tags=<tag>` to check only the interfaces that carry that tag.

When the interface you want is under `errors`, the dataset's schema doesn't meet what the interface needs, for example a missing column or property. Activation locks the schema, so create a new dataset that fixes what the error names.

For TikTok, add `?tags=capi` and look for the TikTok Connector (`"app_id": 19`) with the `conversion_events` interface in `accepted`.

```json theme={null}
{"app_id": 19, "interface_id": "conversion_events"}
```

## 3. Create the connection

```bash theme={null}
curl -X POST https://api.narrative.io/v2/connections \
  -H "Authorization: Bearer $NIO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "connections_dataset",
    "dataset_id": 12347,
    "profile_id": "<PROFILE_ID>",
    "quick_settings": {
      "type": "conversion_events",
      "historical_data_enabled": true
    }
  }'
# → 201 {"type": "connections_dataset", "id": "<CONNECTION_ID>",
#        "app": {"id": 19, "name": "TikTok Connector"}, "dataset_id": 12347,
#        "quick_settings": {"type": "conversion_events", "historical_data_enabled": true},
#        "profile_id": "<PROFILE_ID>",
#        "profile": {"id": "<PROFILE_ID>", "name": "Example Brand"}, "status": "active", ...}
```

The connection names no advertiser and no event set. Each event names its own Offline Event Set in `event_set_id`, so one connection can send to every event set owned by an advertiser the profile can reach.

[What the connection does](/guides/connector-apis/tiktok#what-the-connection-does) describes `historical_data_enabled` and its default.

Record the connection `id`. You need it to stop the delivery.

## 4. Upload events

Each line of the file is one event, in a row that matches the schema you declared in [step 1](#1-create-the-dataset). For the columns TikTok accepts and their shapes, see [The `tiktok_conversion_event` attribute](/reference/connectors/tiktok-conversions-api#the-tiktok_conversion_event-attribute), [Supported user identifiers](/reference/connectors/tiktok-conversions-api#supported-user-identifiers), and [Required columns](#required-columns).

You can load a file into a dataset over the API in two ways:

* **Signed-URL upload.** Your integration uploads one file of up to 3 GB, then asks Narrative to ingest it.
* **Managed S3 bucket.** You write files to an S3 bucket that Narrative manages, and Narrative ingests each batch on its own. Use a managed bucket for files larger than 3 GB, or for files that another system delivers on a schedule.

### Choose a file format

The dataset's `file_config.type` sets the format of every file you load into it. Parquet and JSON Lines both hold object columns, which nest properties inside one column:

* **Parquet** (`parquet`) is the most compatible format for connector datasets. It stores nested struct columns and their types natively, and Narrative matches columns to the schema by name at every level.
* **JSON Lines** (`json`) holds one JSON object per line. Narrative matches each nested object to the schema by name.

CSV datasets (`flat`) hold only scalar columns, so they can't carry object columns.

### Upload a file with a signed URL

Request an upload URL, then send the file straight to storage:

```bash theme={null}
curl -X POST https://api.narrative.io/uploads/my-file.jsonl \
  -H "Authorization: Bearer $NIO_API_TOKEN"
# → {"path": "<UPLOAD_PATH>", "url": "https://...", "expiry": "..."}

curl -X PUT "<url from the response>" --upload-file ./my-file.jsonl
```

The upload URL is valid for 30 minutes and carries its own signature, so send no authorization header with the `PUT`.

<Warning>
  Keep the `path` from the response. Narrative assigns its own storage path, which does not match the name you requested, and the ingest request needs Narrative's path rather than yours.
</Warning>

Then ingest the file into the dataset, passing that `path` as `source_file`:

```bash theme={null}
curl -X POST https://api.narrative.io/datasets/{dataset_id}/upload \
  -H "Authorization: Bearer $NIO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"source_file": "<UPLOAD_PATH>"}'
```

Ingestion runs in the background. Watch the record count on the dataset to know when it has finished:

```bash theme={null}
curl -s https://api.narrative.io/datasets/{dataset_id} \
  -H "Authorization: Bearer $NIO_API_TOKEN"
# → .stats.active_dataset_stored_records
```

The count moves from zero to your row count, typically within a couple of minutes. Each ingested file adds a new snapshot to the dataset, and every active connection on the dataset delivers that snapshot.

### Write files to a managed S3 bucket

A managed bucket is an S3 bucket that Narrative creates for your company. You write each batch of files into its own folder under the dataset's path in the bucket, then write an empty `_NIO_COMMIT` file into that batch folder. Narrative ingests every file in the batch folder when the commit file appears, so you make no upload or ingest request. A file can be as large as S3 accepts.

See [Ingesting Files from a Managed S3 Bucket](/guides/ingestion/ingesting-files-from-a-managed-s3-bucket) to create the bucket, grant your AWS account access, and lay out the folders.

## 5. Check the results

Subscribe to [delivery notifications](/guides/connector-apis/tiktok#delivery-notifications) to hear about each delivery. The connector sends `conversion.delivery.completed` when a delivery of conversion events finishes, and `conversion.delivery.failed` when one fails.

To read the connection back:

```bash theme={null}
curl -s https://api.narrative.io/v2/connections/{connection_id} \
  -H "Authorization: Bearer $NIO_API_TOKEN"
```

The response shows the connection with `"status": "active"`.

## Keeping events flowing

Write new events to the dataset with the same three calls as in [step 4](#4-upload-events). The connection keeps running, so new rows reach TikTok without further calls.

## Stopping delivery

```bash theme={null}
curl -X DELETE https://api.narrative.io/v2/connections/{connection_id} \
  -H "Authorization: Bearer $NIO_API_TOKEN"
# → 200 {}
```

Deleting the connection archives it and stops further events from reaching TikTok. Events already sent stay in TikTok.

## Troubleshooting

| Symptom | Cause | Fix |
| - | - | - |
| `conversion_events` is missing from `accepted` in step 2 | The dataset has no `tiktok_conversion_event` column, or no hashed email or phone number column | Create a new dataset with the schema in step 1 |
| An event never appears in TikTok Events Manager | The row has no `event_set_id`, an `event_name` that is not a TikTok standard event, no email or phone number, or an `event_timestamp` more than 90 days old | Correct the row and upload it again |

## Getting help

Contact your Narrative relationship manager with your company ID, the dataset ID, the connection ID, and an example `event_id`.

***

## Related content

<CardGroup cols={2}>
  <Card title="Delivering audiences via the API" icon="users" href="/guides/connector-apis/tiktok/audiences-api">
    Deliver hashed identifiers into a TikTok audience
  </Card>

  <Card title="TikTok Conversions API Connector" icon="tiktok" href="/reference/connectors/tiktok-conversions-api">
    Event fields, event names, and identifier matching
  </Card>

  <Card title="Connector Interfaces" icon="plug" href="/concepts/data-activation/connector-interfaces">
    Why a dataset connects to an interface rather than a connector
  </Card>

  <Card title="API Keys" icon="key" href="/account-settings/api-keys">
    Create and rotate keys for programmatic access
  </Card>
</CardGroup>


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