Skip to main content
POST
/
collections
/
{collection_id}
/
items
JavaScript
import Moonbase from '@moonbaseai/sdk';

const client = new Moonbase({
  apiKey: process.env['MOONBASE_API_KEY'], // This is the default and can be omitted
});

const item = await client.collections.items.create('collection_id', {
  values: {
    name: { type: 'value/text/single_line', data: 'Aperture Science' },
    ceo: {
      type: 'value/relation',
      data: { type: 'item', id: '1CLJt2v3bK2AzMXRRswwZG' },
    },
  },
});

console.log(item.id);
{
  "id": "1CLJt2v5pkpkAnvdgXfEcF",
  "type": "item",
  "collection": {
    "id": "1CLJt2uco2zG6pdjxS37sg",
    "type": "collection",
    "ref": "organizations"
  },
  "values": {
    "name": {
      "type": "value/text/single_line",
      "data": "Aperture Science"
    },
    "ceo": {
      "type": "value/relation",
      "data": {
        "id": "1CLJt2v3bK2AzMXRRswwZG",
        "type": "item",
        "collection": {
          "id": "1CLJt2ubZ7zAZFBxUxeBHo",
          "type": "collection",
          "ref": "people"
        }
      }
    },
    "created_at": {
      "type": "value/datetime",
      "data": "2025-02-17T16:00:00.000Z"
    },
    "updated_at": {
      "type": "value/datetime",
      "data": "2025-02-17T16:00:00.000Z"
    }
  }
}

Authorizations

Authorization
string
header
required

Your Moonbase API key.

Path Parameters

collection_id
string
required

Body

application/json

The Item object to be created.

Parameters for creating an Item.

values
object
required

A hash where keys are the ref of a Field and values are the data to be set.

Response

Creation succeeded.

An Item represents a single record or row within a Collection. It holds a set of values corresponding to the Collection's fields.

type
string
required

String representing the object’s type. Always item for this object.

Allowed value: "item"
id
string
required

Unique identifier for the object.

collection
CollectionPointer · object
required

A lightweight reference to a Collection, containing the minimal information needed to identify it.

values
object
required

A hash where keys are the ref of a Field and values are the data stored for that field.