Skip to content

Add items to an existing dataset

client.DatasetItems.BatchNew(ctx, body) (*DatasetItemBatchNewResponse, error)
POST/v5/dataset-items/batch

Add one or more items in a single batch to a dataset that already exists.

Use this to append items to an existing dataset; to create a dataset together with its initial items in one call, use POST /v5/datasets instead (this endpoint does not create datasets). Items are only ever added in a batch — there is no single-item create endpoint. The target dataset is identified by the required dataset_id in the request body, and each entry in data (at least one is required) becomes one item, optionally paired with the files entry at the same list index — when files is supplied it must be the same length as data. Each referenced file must exist and be a supported media format, and item keys may not collide with reserved dataset- or evaluation-item field names. The target dataset must not be archived. The batch is applied as a new dataset version snapshot rather than mutating existing versions, and the created items are returned.

ParametersExpand Collapse
body DatasetItemBatchNewParams
Data param.Field[[]map[string, any]]

Items to be added to the dataset

DatasetID param.Field[string]

Identifier of the target dataset

Files param.Field[[]map[string, string]]Optional

Files to be associated to the dataset

ReturnsExpand Collapse
type DatasetItemBatchNewResponse struct{…}
Items []DatasetItem
ID string

The unique identifier of the entity.

ContentHash string
CreatedAt Time

The date and time when the entity was created in ISO format.

formatdate-time
CreatedBy Identity

The identity that created the entity.

ID string
Type IdentityType
One of the following:
const IdentityTypeUser IdentityType = "user"
const IdentityTypeServiceAccount IdentityType = "service_account"
Object IdentityObjectOptional
Data map[string, any]
UpdatedAt Time

The date and time when the entity was last updated in ISO format.

formatdate-time
ArchivedAt TimeOptional

The date and time when the entity was archived in ISO format.

formatdate-time
DatasetID stringOptional
Files map[string, string]Optional
Object DatasetItemObjectOptional
Object DatasetItemBatchNewResponseObjectOptional

Add items to an existing dataset

package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  response, err := client.DatasetItems.BatchNew(context.TODO(), sgpdev.DatasetItemBatchNewParams{
    Data: []map[string]any{map[string]any{
    "foo": "bar",
    }},
    DatasetID: "dataset_id",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.Items)
}
{
  "items": [
    {
      "id": "id",
      "content_hash": "content_hash",
      "created_at": "2019-12-27T18:11:19.117Z",
      "created_by": {
        "id": "id",
        "type": "user",
        "object": "identity"
      },
      "data": {
        "foo": "bar"
      },
      "updated_at": "2019-12-27T18:11:19.117Z",
      "archived_at": "2019-12-27T18:11:19.117Z",
      "dataset_id": "dataset_id",
      "files": {
        "foo": "string"
      },
      "object": "dataset.item"
    }
  ],
  "object": "list"
}
Returns Examples
{
  "items": [
    {
      "id": "id",
      "content_hash": "content_hash",
      "created_at": "2019-12-27T18:11:19.117Z",
      "created_by": {
        "id": "id",
        "type": "user",
        "object": "identity"
      },
      "data": {
        "foo": "bar"
      },
      "updated_at": "2019-12-27T18:11:19.117Z",
      "archived_at": "2019-12-27T18:11:19.117Z",
      "dataset_id": "dataset_id",
      "files": {
        "foo": "string"
      },
      "object": "dataset.item"
    }
  ],
  "object": "list"
}