# API basics

The parts of Mojimoto a developer meets - projects, the base URL, the read, preview and write APIs, the MCP server, tokens and the shape of an entry.

Mojimoto is a headless CMS. You define content types, editors fill in entries, and your site or app reads those entries as JSON over HTTP. This page is the map: what each part is called, where it lives and what it returns.

The app calls a piece of content an **entry**. The API calls it a **document**. They are the same thing.

## Projects and the base URL

Everything belongs to a **project**: its content types, entries, media, locales and API tokens. One project is usually one website or app.

Every API URL starts with the project.

```text
https://mojimoto.com/api/v1/{project}
```

`{project}` is the project's ID, a 16-character handle such as `3f9c2a7d41b8e065`. The URLs on the project's **API keys** page already contain it. The project's slug works in the same place, and these docs use the slug `acme`.

## The four ways in

| Part | Where | Token ability | What it is for |
| --- | --- | --- | --- |
| Read API | `GET /api/v1/{project}/...` | `read` | Published entries, the content model and the media library. |
| Preview | The read API with `?ref=preview` | `read` and `preview` | The newest version of each entry, drafts included. |
| Write API | `/api/v1/{project}/manage/...` | `write` | Create, edit, publish, unpublish and delete entries, change content types, upload media. |
| MCP server | `https://mojimoto.com/mcp/{project}` | `read` or `write` | The same operations as tools for an AI agent. |

Responses are JSON. An error is JSON too, with a `message`. A failed validation is a `422` and adds an `errors` object keyed by field. See [Errors](/docs/api/errors).

## Tokens

Every request carries a project token in the `Authorization` header, written `Bearer mjmt_your_read_token`. Tokens start with `mjmt_`, belong to one project and are never accepted in the query string. A token has abilities: `read` for published content, `preview` for drafts and `write` for the write API. Every project has a public read token, always visible on the **API keys** page and safe to ship in a website. You create other tokens on the same page, and a write token can be limited to certain operations and content types. A missing or unknown token is a `401`. A token from another project, or without the ability the request needs, is a `403`. See [Authentication](/docs/api/authentication).

## Read published content

The read API has seven endpoints. All are `GET` and all sit under the base URL.

| Endpoint | Returns |
| --- | --- |
| `/documents` | A page of published entries. Filter, sort and trim it with query parameters. |
| `/documents/{id}` | One entry by id. |
| `/content-types` | The content model: every content type and its fields. |
| `/content-types/{type}` | One content type. |
| `/assets` | The media library, a page at a time. |
| `/assets/{id}` | One file. |
| `/types` | TypeScript types generated from the content model. |

Ask for one post by its content type and slug:

```bash
curl "https://mojimoto.com/api/v1/acme/documents?type=post&uid=hello-world" \
  -H "Authorization: Bearer mjmt_your_read_token"
```

```json response
{
  "results": [
    {
      "id": 42,
      "uid": "hello-world",
      "type": "post",
      "lang": "en-gb",
      "status": "published",
      "published_at": "2026-06-12T14:30:45+00:00",
      "updated_at": "2026-06-12T14:30:45+00:00",
      "data": {
        "title": "Hello world",
        "slug": "hello-world",
        "body": [
          { "type": "paragraph", "text": "Our first post.", "spans": [] }
        ],
        "cover": {
          "id": 7,
          "url": "https://.../cover.jpg",
          "alt": "A loaf of bread",
          "width": 2400,
          "height": 1200,
          "content_type": "image/jpeg",
          "fit": "cover"
        }
      }
    }
  ],
  "page": 1,
  "per_page": 20,
  "total_results": 1,
  "total_pages": 1,
  "lang": "en-gb",
  "ref": "published"
}
```

A list holds 20 entries a page unless you set `per_page`, which goes up to 100. The [delivery API reference](/docs/api/delivery) covers every parameter, and [HTTP details](/docs/api/http-details) covers caching.

## What an entry looks like

Every entry comes back in the same envelope, in a list or on its own.

| Field | Type | Description |
| --- | --- | --- |
| `id` | integer | The entry's permanent id. Use it to fetch one entry and to link entries together. |
| `uid` | string or null | The entry's slug, unique within its content type. `null` for single and component types. |
| `type` | string | The API id of the entry's content type. |
| `lang` | string | The locale this version is written in, such as `en-gb`. |
| `status` | string | `published`. Under preview it is `draft` when the newest version is a draft. |
| `published_at` | string or null | When this version was published, as an ISO 8601 date and time. `null` for a draft. |
| `updated_at` | string | When this version was saved. |
| `data` | object | The entry's fields, keyed by field id. |

`data` is flat: one key per field, whatever group the field sits in. The shape of each value depends on its field type. Text is a string, rich text is an array of text nodes, media is an object describing the file and a link to another entry is that entry. [Field types](/docs/concepts/field-types) lists every shape.

## Preview drafts

Add `?ref=preview` to a read request and use a token with the `preview` ability. You get the newest version of each entry, published or not, and the response is never cached. A token without `preview` gets published content and an `X-Mojimoto-Preview` response header saying preview was denied. See [Preview](/docs/concepts/preview).

## Write content

The write API lives under `/manage` and needs a token with the `write` ability. Creating an entry and publishing it are separate calls.

```bash
curl -X POST https://mojimoto.com/api/v1/acme/manage/documents \
  -H "Authorization: Bearer mjmt_your_write_token" \
  -H "Content-Type: application/json" \
  -d '{"type": "post", "uid": "hello-world", "data": {"title": "Hello world"}}'
```

```json 201 Created
{ "id": 42, "uid": "hello-world", "version_id": 118 }
```

The entry now exists as a draft. Publish it to put it on the read API:

```bash
curl -X POST https://mojimoto.com/api/v1/acme/manage/documents/42/publish \
  -H "Authorization: Bearer mjmt_your_write_token"
```

The response is the published entry in the envelope above. Every write is recorded in the project's audit log under the token's name. [Entries and publishing](/docs/concepts/entries-and-publishing) explains drafts and validation, and the [management API reference](/docs/api/management) lists every endpoint.

## The MCP server

Each project has an MCP server at `https://mojimoto.com/mcp/{project}`, authenticated with the same bearer tokens. It gives an AI agent tools to list content types and entries, create, edit, publish, unpublish and delete entries, upload media and change content types, plus a `mojimoto://content-model` resource describing the model. A read token gets the two list tools only. A write token gets the tools its scopes allow. The public read token is refused. See [MCP server](/docs/ai/mcp).

## Where to go next

- [Quickstart](/docs/get-started/quickstart) - a first API call.
- [Content model](/docs/concepts/content-model) and [Field types](/docs/concepts/field-types) - how content is structured and what each field returns.
- [Links between entries](/docs/concepts/links) and [Blocks](/docs/concepts/blocks) - how entries are composed.
- [Media](/docs/concepts/media), [Locales](/docs/concepts/locales) and [Webhooks](/docs/concepts/webhooks).
- [JavaScript client](/docs/frameworks/javascript) - the client package for the read API.
