Skip to main content
POST
/
collections
/
{collection_id}
/
items
/
upsert
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.upsert('collection_id', {
  identifiers: { domain: [{ type: 'value/uri/domain', data: 'aperturescience.com' }] },
  values: {
    name: { type: 'value/text/single_line', data: 'Aperture Science' },
    domain: [{ type: 'value/uri/domain', data: 'aperturescience.com' }],
    linked_in: {
      type: 'value/uri/social_linked_in',
      data: { url: 'https://linkedin.com/company/aperturescience' },
    },
  },
});

console.log(item.id);
{
  "id": "1CLJt2v17V1yuCdrUwA4PW",
  "type": "item",
  "collection": {
    "id": "1CLJt2uco2zG6pdjxS37sg",
    "type": "collection",
    "ref": "organizations"
  },
  "values": {
    "name": {
      "type": "value/text/single_line",
      "data": "Aperture Science"
    },
    "domain": [
      {
        "type": "value/uri/domain",
        "data": "aperturescience.com"
      }
    ],
    "linked_in": {
      "type": "value/uri/social_linked_in",
      "data": {
        "username": "company/aperturescience",
        "url": "https://linkedin.com/company/aperturescience"
      }
    },
    "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.

Headers

update-one-strategy
enum<string>

Specifies how to update fields that have a single value. Use replace (default) to overwrite the existing value with the new value. Use preserve to leave the existing value unchanged if one is already present.

Available options:
replace,
preserve
update-many-strategy
enum<string>

Specifies how to update fields that allow multiple values. Use replace (default) to overwrite all existing values with the new values. Use preserve to leave the existing values unchanged when already present. Use merge to merge the new values with existing values.

Available options:
replace,
preserve,
merge

Path Parameters

collection_id
string
required

Body

application/json

The Item object to be created or updated.

Parameters for creating or updating an Item.

identifiers
object
required

A hash where keys are the ref of a Field and values are used to identify the item to update. When multiple identifiers are provided, the update will find items that match any of the identifiers.

values
object
required

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

Response

Successful response.

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.