Data Tables

Manage Data Tables inside an Org, including import and download functionality.

Introduction

Data Tables can be used for a variety of tasks, to help automate portions of a project's architecture.

  • They can serve as product information storage, from where catalog item data can be generated.
  • They can be used as lookup tables for attribute and choice ordering purposes for the front-end.
  • They can be used as lookup tables for 3D specific information for material or geometry exceptions.

Creating Data Tables

In order to create new data tables on the platform, the csv content has to be passed as a Blob in addition to the columnInfo definition. The columnInfowill tell ThreeKit how to interpret the contents of each column from the csv file when they get imported. Currently, ThreeKit supports importing the text as either String, Number, or Asset types.

Here is an example of how this would work. Let's say we want to create a data table with two columns, titled Material and Color.:

type DataTableColumn = {
  name: string;
  type: "String" | "Number" | "Asset";
};

const tableName = "ExampleTable";
const tableHeader = ["Material", "Color"];
const columnInfo: DataTableColumn[] = [
  { name: "Material", type: "String" },
  { name: "Color", type: "String" },
];

const csvHeader = tableHeader.join(",") + "\n";
const csvContent = csvHeader + "\n"; //this will create an empty table that has only the column names

const blob = new Blob([csvContent], { type: "text/csv" });
const formData = new FormData();
formData.append("file", blob, `${tableName}.csv`);
formData.append("columnInfo", JSON.stringify(columnInfo));
formData.append("name", tableName);

try {
  const response = await fetch(
    `https://preview.threekit.com/api/datatables`,
    {
      method: "POST",
      headers : {
        accept: "application/json",
        'content-type': 'text/csv',
        authorization: 'Bearer YOUR_PRIVATE_TOKEN',
      },
    }
  );
  const data = await response.json;
  console.log (data);
} catch (error) {
  console.log(error);
}