⌘K

Import data

Sending a CSV to a department as a new table, or replacing a table's data.

Overview

Import sends a CSV file to a department. Mira turns it into a table that people in that department can ask about, just like a file uploaded in the app. Send a table's id as well, and the file replaces that table's data instead of making a new table.

POST https://searchmira.com/api/v1.0/data/import

The request is a multipart form upload, the same kind a web form with a file field sends. Most HTTP tools build it for you. Don't set the Content-Type header of the request yourself; your tool adds it with the right boundary.

What to send

Header

NameValue
X-API-KeyYour API key. See API keys.

Form fields

FieldRequiredWhat it is
ProjectIDYesThe id of the department the table goes into. Find it under Your IDs on the API Access page.
FileYesThe CSV file.
CardIDNoThe id of an existing table in that department. Send it to replace that table's data. Leave it out to make a new table.

The file

  • CSV only. The file name must end in .csv.
  • Mark the file as CSV. Send the file part with the type text/csv. Some tools label a file application/octet-stream unless told otherwise, and Mira refuses that. The examples below set it.
  • Headings in the first row. Mira reads the first row as column names. A blank heading is named for you, and a repeated one gets a number added.
  • Any common separator. Commas, semicolons, tabs and pipes are all recognised. You don't say which one you used.
  • Up to 300 columns and 512MB.

What you get back

A successful upload returns 200 and the new table's id:

{
  "Msg": "OK",
  "ExecTime": 2.456,
  "Success": true,
  "CardID": "CRD-550e8400-e29b-41d4-a716-446655440000"
}

Keep the CardID. It is how you replace this table's data later, or delete it.

The table isn't ready the moment the upload finishes. Mira reads the file first, which can take a little while for a large one. Tables shows how to check: a table is ready when its Processed field is true.

Each upload uses one of your organisation's credits. If something goes wrong, the response says why in Msg. Limits and errors lists every case.

Example: a new table

cURL

curl -X POST https://searchmira.com/api/v1.0/data/import \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "ProjectID=YOUR_PROJECT_ID" \
  -F "File=@/path/to/your-data.csv;type=text/csv"

Python

import requests

response = requests.post(
    "https://searchmira.com/api/v1.0/data/import",
    headers={"X-API-Key": "YOUR_API_KEY"},
    data={
        "ProjectID": "YOUR_PROJECT_ID",
    },
    files={"File": ("your-data.csv", open("your-data.csv", "rb"), "text/csv")},
)

print(response.json())

JavaScript

const file = fileInput.files[0];

const form = new FormData();
form.append("ProjectID", "YOUR_PROJECT_ID");
form.append("File", new Blob([file], { type: "text/csv" }), file.name);

const response = await fetch(
  "https://searchmira.com/api/v1.0/data/import",
  {
    method: "POST",
    headers: { "X-API-Key": "YOUR_API_KEY" },
    body: form,
  }
);

const data = await response.json();
console.log(data);

Example: replacing a table's data

Add CardID. The new file takes the place of the old data, and the table keeps its id.

A table can't be replaced while Mira is still reading an earlier file for it. Wait until it is ready, then try again.

cURL

curl -X POST https://searchmira.com/api/v1.0/data/import \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "ProjectID=YOUR_PROJECT_ID" \
  -F "CardID=YOUR_CARD_ID" \
  -F "File=@/path/to/your-data.csv;type=text/csv"

Python

import requests

response = requests.post(
    "https://searchmira.com/api/v1.0/data/import",
    headers={"X-API-Key": "YOUR_API_KEY"},
    data={
        "ProjectID": "YOUR_PROJECT_ID",
        "CardID": "YOUR_CARD_ID",
    },
    files={"File": ("your-data.csv", open("your-data.csv", "rb"), "text/csv")},
)

print(response.json())

JavaScript

const file = fileInput.files[0];

const form = new FormData();
form.append("ProjectID", "YOUR_PROJECT_ID");
form.append("CardID", "YOUR_CARD_ID");
form.append("File", new Blob([file], { type: "text/csv" }), file.name);

const response = await fetch(
  "https://searchmira.com/api/v1.0/data/import",
  {
    method: "POST",
    headers: { "X-API-Key": "YOUR_API_KEY" },
    body: form,
  }
);

const data = await response.json();
console.log(data);