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: '1CLJt2v84CdKMEKqwBNXfE' },
},
},
});
console.log(item.id);require "moonbase"
moonbase = Moonbase::Client.new(api_key: "My API Key")
item = moonbase.collections.items.create(
"collection_id",
values: {
name: {data: "Aperture Science", type: :"value/text/single_line"},
ceo: {data: {id: "1CLJt2v84CdKMEKqwBNXfE", type: :item}, type: :"value/relation"}
}
)
puts(item)import os
from moonbase import Moonbase
client = Moonbase(
api_key=os.environ.get("MOONBASE_API_KEY"), # This is the default and can be omitted
)
item = client.collections.items.create(
collection_id="collection_id",
values={
"name": {
"type": "value/text/single_line",
"data": "Aperture Science",
},
"ceo": {
"type": "value/relation",
"data": {
"type": "item",
"id": "1CLJt2v84CdKMEKqwBNXfE",
},
},
},
)
print(item.id)package main
import (
"context"
"fmt"
"github.com/moonbaseai/moonbase-sdk-go"
"github.com/moonbaseai/moonbase-sdk-go/option"
)
func main() {
client := moonbase.NewClient(
option.WithAPIKey("My API Key"),
)
item, err := client.Collections.Items.New(
context.TODO(),
"collection_id",
moonbase.CollectionItemNewParams{
Values: map[string]moonbase.FieldValueParamUnion{
"name": {
OfSingleLineText: &moonbase.SingleLineTextValueParam{
Data: "Aperture Science",
},
},
"ceo": {
OfRelation: &moonbase.RelationValueParam{
Data: moonbase.ItemPointerParam{
ID: "1CLJt2v84CdKMEKqwBNXfE",
},
},
},
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", item.ID)
}
curl --request POST \
--url https://api.moonbase.ai/v0/collections/{collection_id}/items \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"values": {
"name": {
"type": "value/text/single_line",
"data": "Aperture Science"
},
"ceo": {
"type": "value/relation",
"data": {
"type": "item",
"id": "1CLJt2v84CdKMEKqwBNXfE"
}
}
}
}
'{
"id": "1CLJt2vAY2dWSPDQt8AQpz",
"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": "1CLJt2v84CdKMEKqwBNXfE",
"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"
}
}
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "400",
"title": "Bad Request",
"detail": "The request could not be understood due to malformed syntax or invalid parameters."
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "401",
"title": "Unauthorized",
"detail": "Invalid or missing API key or JWT. You should provide your Moonbase API Key or JWT in the authorization header, in the format: \"Authorization: Bearer MOONBASE_API_KEY\""
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "403",
"title": "Forbidden"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "409",
"title": "Conflict",
"detail": "Email has already been taken",
"source": {
"pointer": "/values/email"
}
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "422",
"title": "Unprocessable Entity",
"detail": "Phone is not a valid E.164 formatted telephone number",
"source": {
"pointer": "/values/phone"
}
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "429",
"title": "Too Many Requests"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "500",
"title": "Internal Server Error"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "503",
"title": "Service Unavailable",
"detail": "The service is temporarily unavailable, please try again later."
}
]
}Items
Create an Item
Creates a new item in a collection.
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: '1CLJt2v84CdKMEKqwBNXfE' },
},
},
});
console.log(item.id);require "moonbase"
moonbase = Moonbase::Client.new(api_key: "My API Key")
item = moonbase.collections.items.create(
"collection_id",
values: {
name: {data: "Aperture Science", type: :"value/text/single_line"},
ceo: {data: {id: "1CLJt2v84CdKMEKqwBNXfE", type: :item}, type: :"value/relation"}
}
)
puts(item)import os
from moonbase import Moonbase
client = Moonbase(
api_key=os.environ.get("MOONBASE_API_KEY"), # This is the default and can be omitted
)
item = client.collections.items.create(
collection_id="collection_id",
values={
"name": {
"type": "value/text/single_line",
"data": "Aperture Science",
},
"ceo": {
"type": "value/relation",
"data": {
"type": "item",
"id": "1CLJt2v84CdKMEKqwBNXfE",
},
},
},
)
print(item.id)package main
import (
"context"
"fmt"
"github.com/moonbaseai/moonbase-sdk-go"
"github.com/moonbaseai/moonbase-sdk-go/option"
)
func main() {
client := moonbase.NewClient(
option.WithAPIKey("My API Key"),
)
item, err := client.Collections.Items.New(
context.TODO(),
"collection_id",
moonbase.CollectionItemNewParams{
Values: map[string]moonbase.FieldValueParamUnion{
"name": {
OfSingleLineText: &moonbase.SingleLineTextValueParam{
Data: "Aperture Science",
},
},
"ceo": {
OfRelation: &moonbase.RelationValueParam{
Data: moonbase.ItemPointerParam{
ID: "1CLJt2v84CdKMEKqwBNXfE",
},
},
},
},
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", item.ID)
}
curl --request POST \
--url https://api.moonbase.ai/v0/collections/{collection_id}/items \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"values": {
"name": {
"type": "value/text/single_line",
"data": "Aperture Science"
},
"ceo": {
"type": "value/relation",
"data": {
"type": "item",
"id": "1CLJt2v84CdKMEKqwBNXfE"
}
}
}
}
'{
"id": "1CLJt2vAY2dWSPDQt8AQpz",
"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": "1CLJt2v84CdKMEKqwBNXfE",
"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"
}
}
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "400",
"title": "Bad Request",
"detail": "The request could not be understood due to malformed syntax or invalid parameters."
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "401",
"title": "Unauthorized",
"detail": "Invalid or missing API key or JWT. You should provide your Moonbase API Key or JWT in the authorization header, in the format: \"Authorization: Bearer MOONBASE_API_KEY\""
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "403",
"title": "Forbidden"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "409",
"title": "Conflict",
"detail": "Email has already been taken",
"source": {
"pointer": "/values/email"
}
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "422",
"title": "Unprocessable Entity",
"detail": "Phone is not a valid E.164 formatted telephone number",
"source": {
"pointer": "/values/phone"
}
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "429",
"title": "Too Many Requests"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "500",
"title": "Internal Server Error"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "503",
"title": "Service Unavailable",
"detail": "The service is temporarily unavailable, please try again later."
}
]
}Authorizations
Your Moonbase API key.
Path Parameters
Body
application/json
The Item object to be created.
Parameters for creating an Item.
A hash where keys are the ref of a Field and values are the data to be set.
Show child attributes
Show child attributes
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.
String representing the object’s type. Always item for this object.
Allowed value:
"item"Unique identifier for the object.
A lightweight reference to a Collection, containing the minimal information needed to identify it.
Show child attributes
Show child attributes
A hash where keys are the ref of a Field and values are the data stored for that field.
Show child attributes
Show child attributes
⌘I

