Skip to main content
POST
/
collections
/
{collection_id}
/
fields
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 field = await client.collections.fields.create('collection_id', {
  field: { name: 'Lead Source', type: 'field/text/single_line' },
});

console.log(field);
{
  "id": "1CLJt2v5pkpkAnvdgXfEcF",
  "type": "field/text/single_line",
  "created_at": "2025-02-17T16:00:00.000Z",
  "updated_at": "2025-02-17T16:00:00.000Z",
  "default_values": [],
  "name": "Lead Source",
  "ref": "lead_source",
  "cardinality": "one",
  "required": false,
  "unique": false,
  "readonly": false,
  "kind": "custom"
}

Documentation Index

Fetch the complete documentation index at: https://docs.moonbase.ai/llms.txt

Use this file to discover all available pages before exploring further.

Authorizations

Authorization
string
header
required

Your Moonbase API key.

Path Parameters

collection_id
string
required

The ID or ref of the Collection to create the field in.

Body

application/json

The field to create. Set type to select the field type.

Simple types — require only name and type: field/text/single_line, field/text/multi_line, field/boolean, field/email, field/uri/url, field/uri/domain, field/uri/social_x, field/uri/social_linked_in, field/telephone_number, field/geo, field/date, field/datetime

Number types — also require only name and type; field/number/monetary additionally supports default_unit: field/number/unitless_integer, field/number/unitless_float, field/number/percentage, field/number/monetary

Complex types — require additional properties:

  • field/choice — needs options (array of option names)
  • field/stage — needs stages (array with name and step_type)
  • field/relation — needs relation_type and allowed_collections

Parameters for creating a field, discriminated by type.

type
string
required

The field type. Must be field/text/single_line.

Allowed value: "field/text/single_line"
name
string
required

The human-readable name for the field.

description
string

An optional description of the field's purpose.

cardinality
enum<string>

Whether the field holds a single value (one) or multiple values (many). Defaults to one.

Available options:
one,
many
required
boolean

If true, items must have a value for this field. Defaults to false.

unique
boolean

If true, values must be unique across all items. Defaults to false.

default_values
Single Line Text · object[]

Response

Creation succeeded.

A field definition, which varies by type

type
string
required

The data type of the field. Always field/text/single_line for this field.

Allowed value: "field/text/single_line"
id
string
required

Unique identifier for the object.

name
string
required

The human-readable name of the field (e.g., "Company Name").

ref
string
required

A unique, stable, machine-readable identifier for the field within its collection (e.g., company_name).

cardinality
enum<string>
required

Specifies whether the field can hold a single value (one) or multiple values (many).

Available options:
one,
many
required
boolean
required

If true, this field must have a value.

unique
boolean
required

If true, values for this field must be unique across all items in the collection.

readonly
boolean
required

If true, the value of this field is system-managed and cannot be updated via the API.

kind
enum<string>
required

system fields are managed by Moonbase, inverse fields are the reverse side of a two-way relation, and custom fields are user-created.

Available options:
system,
inverse,
custom
created_at
string<date-time>
required

Time at which the object was created, as an ISO 8601 timestamp in UTC.

updated_at
string<date-time>
required

Time at which the object was last updated, as an ISO 8601 timestamp in UTC.

default_values
(Single Line Text · object | Multi Line Text · object | Identifier · object | Integer · object | Float · object | Monetary · object | Percentage · object | Boolean · object | Email · object | URL · object | Domain · object | X · object | LinkedIn · object | Telephone Number · object | Geo · object | Date · object | CurrentDate · object | Date Time · object | CurrentDatetime · object | Choice · object | Funnel Step · object | Relation · object | CurrentMember · object)[]
required

A default value for a field. Can be a static value (e.g., value/date) or a server-resolved value (e.g., current_date). Static values use the same shape as item values. Server-resolved values are computed when an item is created.

description
string

An optional, longer-form description of the field's purpose.