Skip to main content
PATCH
/
collections
/
{collection_id}
/
fields
/
{id}
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.update('id', {
  collection_id: 'collection_id',
  field: { type: 'field/text/single_line' },
});

console.log(field);
{
  "id": "1CLJt2v5aNd8G5SGzEaeVU",
  "type": "field/text/single_line",
  "created_at": "2025-02-17T16:00:00.000Z",
  "updated_at": "2025-02-17T16:00:00.000Z",
  "default_values": [],
  "name": "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 the field belongs to.

id
string
required

The ID or ref of the Field to update.

Body

application/json

The field values to update.

Important: The type property is required on every update request — it acts as a discriminator to select the correct schema and must match the existing field's type.

All fields support updating name, description, cardinality, required, and unique.

Complex types use mutation operations for sub-resources:

  • field/choiceoptions array with add/update/remove ops
  • field/stagestages array with add/update/remove ops
  • field/relationallowed_collections array with add/remove ops

Parameters for updating 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

The new name for the field.

description
null | string

An updated description, or null to clear it.

cardinality
enum<string>

Updated cardinality: one or many.

Available options:
one,
many
required
boolean

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

unique
boolean

If true, values must be unique across all items.

default_values
null | Single Line Text · object[]

Response

Successful response.

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.