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

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

// Automatically fetches more pages as needed.
for await (const itemSearchResponse of client.collections.items.search('collection_id', {
  filter: {
    op: 'and',
    filters: [
      {
        op: 'starts_with',
        field: 'name',
        value: 'C',
      },
      {
        op: 'ends_with',
        field: 'name',
        value: 'e',
      },
    ],
  },
})) {
  console.log(itemSearchResponse.data);
}
{
  "type": "list",
  "data": [
    {
      "type": "search_result",
      "data": {
        "id": "1CLJt2v5aNd8G5SGzEaeVU",
        "type": "item",
        "collection": {
          "id": "1CLJt2ubZ7zAZFBxUxeBHo",
          "type": "collection",
          "ref": "people"
        },
        "values": {
          "name": {
            "type": "value/text/single_line",
            "data": "Carmene"
          },
          "email": [
            {
              "type": "value/email",
              "data": "person-296@example-296.com"
            }
          ],
          "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": "search_result",
      "data": {
        "id": "1CLJt2v7opRhSWqVEtHwYT",
        "type": "item",
        "collection": {
          "id": "1CLJt2ubZ7zAZFBxUxeBHo",
          "type": "collection",
          "ref": "people"
        },
        "values": {
          "name": {
            "type": "value/text/single_line",
            "data": "Cerise"
          },
          "email": [
            {
              "type": "value/email",
              "data": "person-297@example-297.com"
            }
          ],
          "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": "search_result",
      "data": {
        "id": "1CLJt2vA3GEGcxEhVY1EbS",
        "type": "item",
        "collection": {
          "id": "1CLJt2ubZ7zAZFBxUxeBHo",
          "type": "collection",
          "ref": "people"
        },
        "values": {
          "name": {
            "type": "value/text/single_line",
            "data": "Charlie"
          },
          "email": [
            {
              "type": "value/email",
              "data": "person-298@example-298.com"
            }
          ],
          "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": "search_result",
      "data": {
        "id": "1CLJt2vCGi2qoPdukBiXeR",
        "type": "item",
        "collection": {
          "id": "1CLJt2ubZ7zAZFBxUxeBHo",
          "type": "collection",
          "ref": "people"
        },
        "values": {
          "name": {
            "type": "value/text/single_line",
            "data": "Corinne"
          },
          "email": [
            {
              "type": "value/email",
              "data": "person-299@example-299.com"
            }
          ],
          "created_at": {
            "type": "value/datetime",
            "data": "2025-02-17T16:00:00.000Z"
          },
          "updated_at": {
            "type": "value/datetime",
            "data": "2025-02-17T16:00:00.000Z"
          }
        }
      }
    }
  ],
  "meta": {
    "cursors": {}
  }
}

Authorizations

Authorization
string
header
required

Your Moonbase API key.

Path Parameters

collection_id
string
required

Query Parameters

before
string

When specified, returns results starting immediately before the item identified by this cursor. Use the cursor value from the response's metadata to fetch the previous page of results.

after
string

When specified, returns results starting immediately after the item identified by this cursor. Use the cursor value from the previous response's metadata to fetch the next page of results.

limit
integer
default:20

Maximum number of items to return per page. Must be between 1 and 100. Defaults to 20 if not specified.

Required range: 1 <= x <= 100

Body

application/json

Options to limit the item fields returned, sort the results, and filter which items are returned.

include
string[]

Include only specific fields in the returned items. Specify fields by id or key.

filter
Match Value · object

Return only items that match the filter conditions. Complex filters can be created by nesting filters inside of AND, OR, and NOT filters.

sort
string[]

Sort items by the specified field ids or keys. Prefix a field with a hyphen/minus (-) to sort in descending order by that field.

Response

Successful response.

A set of results using cursor-based pagination.

type
string
required
Allowed value: "list"
data
object[]
required

An array of SearchResult items.

meta
object
required

Metadata about the pagination, including the cursors pointing to the previous and next pages.