Create reference tables using the API

To create a reference table, you first need to generate an authentication token by following the the steps in Obtain a bearer token for local authentication.

Create a reference table using the API

Once you have the authentication token, you can use the following API to create a reference table.

# Create a reference table with name, primary key, and its schema 

curl https://{customerid}.observeinc.com/v1/referencetables \ 
-X POST \
-H 'Authorization: Bearer <customer id> <token>' \
-F 'metadata=\{"label": "<name>", "description":"description", "primaryKey": ["col1", "col2", "col3"], "labelField": "col2"}' \
-F 'upload=@<path to csv>' \
-F 'schema=@<path to schema json>'
FieldRequired?Description
labelYesName of the reference table.
descriptionNoDescription of the reference table.
primaryKeyNoOne or more columns of the CSV to use as primary key of the managed dataset. No primary key will be set if this argument is not passed in.
labelFieldNoOne column of the CSV to be the label field of the reference table.
schemaNoPath to a JSON file specifying the schema of the managed dataset. The following types are supported: array, bool, duration, float64, int64, numeric, object, string, variant. The default is a stringly-typed schema (i.e., every column is of type string), with column names extracted from the header of the CSV file. If the CSV file has no header, then the column names are generated in the form col0, col1, …, coln-1.

Here is an example JSON file specifying a schema.

[  
    {"name": "id", "type": "string"},
    {"name": "name", "type": "string"},
    {"name": "description", "type": "string"},
    {"name": "picture", "type": "string"},
    {"name": "categories", "type":"array"},
    {"name": "priceUsd_currencyCode", "type": "string"},
    {"name": "priceUsd", "type": "float64"}
]

The following example creates a reference table called Products with a primary key, id and a schema in JSON representing the schema of the csv file. Here are a sample CSV file and its schema in JSON converted from the Astronomy Shop’s product catalog.

curl 'https://123456789.observeinc.com/v1/referencetables' \  
-X POST \
-H 'Authorization: Bearer 123456789 sB_pLWTM0ED_redacted' \
-F 'metadata={"label": "Products", "primaryKey": ["id"]}' \
-F '[email protected]' \
-F 'schema=@products_schema.json'

When creating a reference table is successful, you will see a response similar to the following one.

{"id":"41941674","customerId":"123456789","label":"Products","datasetId":"41941673","folderId":"0","createdBy":{"id":2896},"createdAt":"2025-02-07T19:12:36.157153Z","updatedBy":{"id":2896},"updatedAt":"2025-02-07T19:12:36.157153Z","checksum":"b26f8dc7102f33a1ea9dd81723ee53b7"}

Go to the dataset page and search for Products or your reference table name. You will find the reference table under the Reference Tables/ namespace.

Use a reference table for lookup, join, or set_link

Perform the following tasks to use a reference table:

  1. Create a Worksheet from a Dataset, such as the Container Logs Dataset.
  2. Switch to the OPAL editor.
  3. Use Manage inputs to add a reference table, for example, Products Dataset.
  4. Use a lookup, join, or set_link based on the following examples.

lookup example

lookup on (productId = @"Reference Tables/Products".id), productName:@"Reference Tables/Products".name, price:@"Reference Tables/Products".priceUsd

join example

join on (productId = @"Reference Tables/Products".id), productName:@"Reference Tables/Products".name, price:@"Reference Tables/Products".priceUsd

set_link example

set_link "productName", productId:@"Reference Tables/Products with labels".id

Search for a reference table

You can search for reference tables by ID or by substring match on the name.

Search for a reference table by ID

The following example shows how to search for a reference table by its ID:

curl https://{customerid}.observeinc.com/v1/referencetables/{id} -H 'Authorization: Bearer <customer id> <token>'

Search for a reference table by name

Here is an example to search for a reference table by name:

curl https://{customerid}.observeinc.com/v1/referencetables?label=<name> -H 'Authorization: Bearer <customer id> <token>'

When searching for a reference table is successful, you will see a response similar to the following one.

{"totalCount":3,"referenceTables":[{"id":"41819922","customerId":"123456789","label":"Products without keys","datasetId":"41819923","folderId":"41143965","createdBy":{"id":2896},"createdAt":"2024-11-21T22:46:25.21438Z","updatedBy":{"id":2896},"updatedAt":"2024-11-21T22:46:25.21438Z","checksum":""},{"id":"41791338","customerId":"123456789","label":"Products with labels","datasetId":"41791339","folderId":"41143965","createdBy":{"id":2896},"createdAt":"2024-11-05T20:47:59.755023Z","updatedBy":{"id":2896},"updatedAt":"2024-11-05T20:47:59.755023Z","checksum":""},{"id":"41710969","customerId":"123456789","label":"Products","datasetId":"41710970","folderId":"41143965","createdBy":{"id":2896},"createdAt":"2024-08-16T16:40:09.694988Z","updatedBy":{"id":2896},"updatedAt":"2024-08-17T01:01:33.090887Z","checksum":""}]}

Update metadata of a reference table

You can update the metadata of a reference table by id: its name (label), description,
primaryKey, and tags (objectTags). Fields you omit are left unchanged. Use Search for a reference table to find the table ID.

FieldDescription
labelNew name of the reference table.
descriptionNew description.
primaryKeyColumns to use as the primary key. Observe checks that the columns are unique across the current rows and rejects a non-unique key with 409 and error type non_unique_key, listing up to 20 colliding key values. A primary key is required to edit rows.
objectTagsTags that replace all tags on the reference table, as a map from tag key to a list of values, for example {"team": ["ingest"], "env": ["prod"]}. Send {} to remove all tags. Omit the field to leave tags unchanged; null is not accepted.

The following example shows how to update the name and description of a reference table:

# Update the name or the description of the reference table

curl https://{customerid}.observeinc.com/v1/referencetables/{id} \
-X PATCH \
-H 'Authorization: Bearer <customer id> <token>' \
-d '{
"label": "<new name>",
"description": "<new description>"
}'

The following example updates the existing Products reference table with a new name, Products v2.

curl https://123456789.observeinc.com/v1/referencetables/41942573 \
-X PATCH \
-H 'Authorization: Bearer 123456789 sB\_pLWTM0ED\_redacted' \
-d '{
"label": "Products v2"
}'

When updating metadata of a reference table is successful, you will see a response similar to the following one.

{"id":"41942573","customerId":"123456789","label":"Products v2","datasetId":"41942572","folderId":"0","createdBy":{"id":2896},"createdAt":"2025-02-07T21:18:07.416498Z","updatedBy":{"id":2896},"updatedAt":"2025-02-07T21:18:07.416498Z","checksum":"b26f8dc7102f33a1ea9dd81723ee53b7"}

Replace a reference table

You can replace a reference table by id. While replacing the reference table, you can also change the name, the description, primaryKey, or labelField. Use Search for a reference table to find the ID of the reference table you want to update.

curl https://{customerid}.observeinc.com/v1/referencetables/{id} \
-X PUT \
-H 'Authorization: Bearer <customer id> <token>' \
-F 'metadata={"label": "<new name>", "description":"<new description>", "primaryKey": ["col1", "col2", "col3"], "labelField": "col2"}' \
-F '[email protected]'

The following example replaces the existing Products reference table by its ID, 41819922 and reset primary keys.

curl https://123456789.observeinc.com/v1/referencetables/41819922 \
-X PUT \
-H 'Authorization: Bearer 123456789 sB_pLWTM0ED_redacted' \
-F 'metadata={"label": "Products", "primaryKey": ["id", "name"]}' \
-F 'upload=@<path to csv>'

When replacing a reference table is successful, you will see a response similar to the following one.

{"id":"41819922","customerId":"123456789","label":"Products","datasetId":"41942572","folderId":"0","createdBy":\{"id":2896},"createdAt":"2025-02-07T23:03:29.573924Z","updatedBy":\{"id":2896},"updatedAt":"2025-02-07T23:03:29.573924Z","checksum":"b26f8dc7102f33a1ea9dd81723ee53b7"}

Edit rows of a reference table

You can add, update, and delete individual rows of a reference table without replacing the whole CSV file. Send a batch of row changes in one request. Observe applies the whole batch atomically: either every change in the request is applied, or none is.

The reference table must have a primary key, and the token's user needs edit permission on the reference table.

curl https://{customerid}.observeinc.com/v1/referencetables/{id}/rows \
  -X PATCH \
  -H 'Authorization: Bearer <customer id> <token>' \
  -H 'Content-Type: application/json' \
  -d '[
    {"key": {"<pk column>": "<value>"}, "record": {"<column>": "<new value>"}},
    {"key": {"<pk column>": "<value>"}, "record": null}
  ]'

The request body is a JSON array of up to 200 entries. Each entry changes one row:

FieldRequired?Description
keyYesThe row's primary key: an object with exactly the table's primary key columns, no more and no fewer.
recordYesThe columns to set, or null to delete the row. If the row exists, only the columns you include change; columns you leave out keep their values. If the row doesn't exist, it is added, and columns you leave out are empty (null). Set a column to null to clear its value. An empty object {} adds a row that has only its primary key, or leaves an existing row unchanged. Primary key columns can't be changed in record; see Change a row's primary key.
insertIfNotExistsNoSet to true to require that the entry adds a new row. If a row with this key already exists, the whole request is rejected with 409 and error type key_exists, and nothing is changed. Not allowed when record is null. Default false: an existing row is updated.

Each primary key can appear only once in a request.

Values can be sent as JSON values or as strings. Observe converts them to the column's type, for example "42" or 42 for an int64 column, and "true" or true for a bool column. Timestamps and durations are accepted as strings or numbers. An empty string "" is a valid value only for string columns; to clear a value in a column of any other type, send null.

The following example works on the Products reference table (id 41942573, primary key id). It changes the price of one product, adds a new product without risking overwriting an existing one, and deletes a third product:

curl 'https://123456789.observeinc.com/v1/referencetables/41942573/rows' \
  -X PATCH \
  -H 'Authorization: Bearer 123456789 sB_pLWTM0ED_redacted' \
  -H 'Content-Type: application/json' \
  -d '[
    {"key": {"id": "OLJCESPC7Z"}, "record": {"priceUsd": 19.99}},
    {"key": {"id": "NEWPROD001"}, "record": {"name": "Solar Filter", "priceUsd": 49.5}, "insertIfNotExists": true},
    {"key": {"id": "66VCHSJNUP"}, "record": null}
  ]'

When the edit is successful, you will see a response similar to the following one. It contains counts only; the rows are not returned.

{"upsertCount":2,"deleteCount":1}

Change a row's primary key

The primary key of an existing row can't be updated in place. To change it, delete the row under the old key and add it under the new key in the same request, so both happen together. Set insertIfNotExists on the new key so the request fails rather than overwriting a different row that already uses it:

[
  {"key": {"id": "OLD-ID"}, "record": null},
  {"key": {"id": "NEW-ID"}, "record": {"name": "Telescope", "priceUsd": 199}, "insertIfNotExists": true}
]

A table with a composite primary key works the same way; include every primary key column in key, for example {"key": {"region": "us-west", "sku": "A-100"}, "record": {...}}.

Concurrent changes

Only the rows in the request are changed, so requests from different users that touch different rows never overwrite each other. If two requests change the same row, the last one wins for the columns it includes. Replacing the reference table with PUT replaces every row, including rows changed with this endpoint.

After a row edit, the reference table's checksum is empty, because it describes the last uploaded CSV file.

Reference tables managed by Terraform

By default, if the table is managed with the Observe Terraform provider (observe_reference_table), the next terraform apply sees the empty checksum as a change, uploads the configured CSV file again, and replaces the edited rows.

To edit the rows of a Terraform-managed reference table, set allow_row_edits = true on the resource (Observe Terraform provider vX.Y.Z or later):

resource "observe_reference_table" "products" {
  label           = "Products"
  source_file     = "products.csv"
  checksum        = filemd5("products.csv")
  primary_key     = ["id"]
  allow_row_edits = true
}

Terraform then keeps the edited rows and uploads the CSV file only when you change the file or the table's schema, primary_key, or label_field. That upload replaces all rows, including rows edited in Observe. terraform plan doesn't show row edits as changes, so the CSV file in your configuration no longer matches the table's current rows.

Set allow_row_edits before anyone edits the rows. If the table already has row edits (its checksum is empty) when you set it, or when you import the table into Terraform, the next terraform apply uploads the CSV file once and replaces them.

Errors

Errors return a JSON body with a machine-readable type and a message:

{"type":"key_exists","message":"..."}
StatustypeMeaning
400bad_requestThe body isn't a JSON array of entries, or an entry has no record field. Use "record": null to delete a row.
400empty_payloadThe request contained no entries.
400duplicate_keyThe same primary key appears more than once in the request.
400missing_keyAn entry's key doesn't contain exactly the primary key columns: one is missing, or a non-key column is included.
400pk_immutablerecord tries to change a primary key column.
400insert_if_not_exists_on_deleteinsertIfNotExists is set on an entry whose record is null.
400unknown_columnA column isn't in the reference table's schema.
400invalid_valueA value can't be converted to its column's type, for example "" for an int64 column.
400row_limit_exceededThe request has more than 200 entries.
400statement_too_largeThe request is too large to apply in one statement, usually because the table is very wide. Send fewer entries per request.
403failed_authorizationThe user doesn't have edit permission on the reference table.
409no_primary_keyThe reference table has no primary key. Set one with PATCH /v1/referencetables/{id}.
409non_unique_keyThe stored rows contain duplicates for a primary key in the request, for example after a CSV replacement. Remove the duplicates, then retry.
409key_existsAn entry with insertIfNotExists: true uses a key that already exists.
413bad_requestThe request body is larger than 16 MiB.

For changes to more than 200 rows, replace the reference table with PUT instead.

List the row edit history of a reference table

Each successful row edit request is recorded with who made it, when, and which rows it changed. List the records, newest first:

curl 'https://{customerid}.observeinc.com/v1/referencetables/{id}/rows/edits?limit=100&offset=0' \
  -H 'Authorization: Bearer <customer id> <token>'
ParameterDescription
limitMaximum number of records to return. Default 100, maximum 1000; larger values return at most 1000 records.
offsetIndex of the first record to return. Default 0.

A successful request returns a response similar to the following one:

{
  "edits": [
    {
      "id": "1042",
      "createdBy": {"id": 2896},
      "createdAt": "2026-11-10T14:03:11.512Z",
      "upsertCount": 2,
      "deleteCount": 1,
      "changes": [
        {"key": {"id": "OLJCESPC7Z"}, "op": "Upsert"},
        {"key": {"id": "NEWPROD001"}, "op": "Upsert"},
        {"key": {"id": "66VCHSJNUP"}, "op": "Delete"}
      ]
    }
  ],
  "meta": {"totalCount": 1}
}

The history records which rows changed and how (Upsert or Delete), not the values before and after. Failed requests, CSV uploads, and replacements are not included.

Delete a reference table

You can delete a reference table by id. Use Search for a reference table to find the id of the reference table you want to delete.

# Delete a reference table by id

curl https://{customerid}.observeinc.com/v1/referencetables/{id} \
-X DELETE \
-H 'Authorization: Bearer <customer id> <token>'

The following example deletes the existing reference table by its id, 41819922.

curl https://123456789.observeinc.com/v1/referencetables/41819922 \
-X DELETE \
-H 'Authorization: Bearer 123456789 sB\_pLWTM0ED\_redacted'

When deleting a reference table is successful, you will see a response similar to the following one.

{"message":"Reference Table 41819922 successfully deleted."}

Did this page help you?