HomeGuidesAPI ReferenceRelease notes
Log In
Guides

Ingest data via REST API

Superwise now supports data ingestion into our datasets via REST API, in addition to GCP/AWS buckets.

Here’s what you need to do:

  1. Create a Dataset: The first step is to create a dataset for data ingestion. Learn more about creating datasets here.
  2. Ingest a Data Record: Use the following code to log a data record to your dataset:

SDK:

sw.dataset.log_record_to_dataset(
    dataset_id="YOUR DATASET ID",
    data={
        "some_data_key": "some_data_value",
        "another_data_key": "another_data_value"
    })

Here is an example on how to send data via our SDK that include image:

from superwise_api.superwise_client import SuperwiseClient
 
client = SuperwiseClient(
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET",
)
 
# 1. Read the image file
with open("photo.jpg", "rb") as f:
    image_bytes = f.read()
 
# 2. Create a dataset with a string field and an image field
dataset = client.dataset.create(
    name="my-image-dataset",
    schema={
        "fields": {
            "user_id": {"type": "string"},
            "photo": {"type": "image"},
        }
    },
)
 
# 3. Log a record with the image attached
client.dataset.log_record_to_dataset(
    dataset_id=dataset.id,
    data={"user_id": "user-1"},
    images={"photo": (image_bytes, "image/jpeg")},
)
 
 

API:

import requests
import json

url = "https://api.superwise.ai/v1/datasets/INSERT_DATASET_ID_HERE/log"

payload = json.dumps({
  "record": {
    "numeric_field": 1,
    "word_field": "value1"
  }
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer INSERT_TOKEN_HERE'
}

response = requests.request("POST", url, headers=headers, data=payload)
📘

Note

You can send only one data record at a time.