Types

Register a type

Registers a type under the app.*, user.* or <publisher>.* namespace and returns it. Name a parent to inherit its fields.

POST
/types

Authorization

bearerAuth
headerAuthorizationBearer <token>

Authenticate with an API key (marfa_k1_…) or an OAuth access token (marfa_at_…).

Header parameters

X-Marfa-Instance-Id?string

The ID of the instance you expect, as GET / returns it. If another instance answers at this address, Marfa returns 409 instance_changed and doesn't write. Leave it out to send the request to whichever instance answers.

Match^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$

Request body

application/json
  1. body

A declared item type.

fields*

The type's own fields, by name.

tables?

The type's own tables, by name: at most 32, each named by a lowercase letter, then up to 63 lowercase letters, digits and underscores. A subtype gets its parents' tables and declares only its own.

version?integer

A number for you to track changes to the type. Marfa never changes it. Leave it out for 0.

Range0 <= value
parent?string

The identifier of the type this one inherits from. To set or change it, you need write on it, unless Marfa ships it. Leave it out for a type with no parent.

label?string

A name for people to read, up to 100 characters. Leave it out and Marfa derives one from the last segment of the identifier.

plural?string

The label's plural, up to 100 characters, such as People. Leave it out and Marfa adds s, es or ies to the label by the regular English rule.

description?string

What the type is for.

roles?array<string>

The structural roles the type plays: container. An edge type's role:<name> constraint matches types by role.

required?array<string>

The names of the fields an item of the type must have. It means the same as required: true on each of them.

compatible_with?|array<string>

The types this one is a structural superset of. Marfa checks the claim when you save the type. A bare string names one type.

display_hints?

How clients show the type and its items: the title field, the body field, whether the body names an item, and the icon.

link_field?string

The name of a string field, declared or inherited, that holds each item's own ID at the vendor that writes the type. No two items of the type, in any state, hold the same value. A subtype names its own link. The name has no " or \.

version_policy?

How long Marfa keeps the versions of the type's items.

merge_policy?

How Marfa merges conflicting edits to the type's items.

retention_policy?

How long Marfa keeps the type's items in the feed tier.

id*string

The type's identifier, such as acme.deal or user.recipe.

Response body

About errors

Returns the new type.

application/json
  1. response

A type says which fields the items of that type hold, and what else Marfa does for them.

id*string

Unique identifier for the type.

label?string

The type's name for people to read.

plural*string

The type's plural name for people to read, such as People: the one the type declares, else one made from its label. Never inherited.

description?string

What the type is for.

parent?string

The identifier of the type this one inherits from.

compatible_with?array<string>

The types this one is a structural superset of.

roles?array<>

The structural roles the type plays, including those it inherits.

fields*

The type's own fields, by name. GET /types/{id} adds the fields it inherits.

tables?

The type's own tables, by name. GET /types/{id} adds the tables it inherits.

version*integer

The version number the type was last saved with.

Range0 <= value
display_hints?

How clients show the type and its items: the title field, the body field, whether the body names an item, and the icon.

link_field?string

The name of a string field, declared or inherited, that holds each item's own ID at the vendor that writes the type. No two items of the type, in any state, hold the same value. A subtype names its own link. The name has no " or \.

version_policy?

How long Marfa keeps the versions of the type's items.

merge_policy?

How Marfa merges conflicting edits to the type's items.

retention_policy?

How long Marfa keeps the type's items in the feed tier.

provenance*

The type's recorded origin and creator.

  • missing_required_field: fields is missing.
  • validation_error: id is malformed, or parent isn't registered or makes too deep a chain.
  • invalid_schema: the schema is invalid or has a key it doesn't define (details.errors names each path).
  • property_shadows_field: a field is named like one every item has.
  • inheritance_violation: the type reshapes an inherited field.
application/json
  1. response

An error response.

error*

What went wrong.

unauthorized: the request has no credential, or its credential is not valid. For a key that has expired, details.expired_at says when it expired.

application/json
  1. response

An error response.

error*

What went wrong.

  • forbidden: you don't have metadata.types:write, or the identifier is under core.*, system.* or marfa.*, which no credential can register.
  • type_not_permitted: your type map lacks write on the identifier or a non-platform parent or compatible_with target (details.grant names it).
application/json
  1. response

An error response.

error*

What went wrong.

request_timeout: the request body didn't arrive whole within 180 seconds. Nothing changed, and Marfa closed the connection. Send the request again. A body larger than about 21 MiB can't arrive in that time over a 1 Mbit/s link, so send it in smaller requests.

application/json
  1. response

An error response.

error*

What went wrong.

  • type_exists: a type has this identifier.
  • link_taken: two items that a forced delete left under this identifier hold the same value in the link_field.
application/json
  1. response

An error response.

error*

What went wrong.

contract_mismatch: X-Marfa-Contract names another contract version than this instance speaks, or is not a whole number. Nothing was done.

application/json
  1. response

An error response.

error*

What went wrong.

request_too_large: the request body is larger than this instance accepts.

application/json
  1. response

An error response.

error*

What went wrong.

compatible_with_violation: compatible_with names a type this instance doesn't hold, or one the type doesn't satisfy.

application/json
  1. response

An error response.

error*

What went wrong.

rate_limited: you sent too many requests. Wait for the number of seconds in Retry-After, then try again.

application/json
  1. response

An error response.

error*

What went wrong.

internal_error: Marfa failed in a way it didn't expect, and the request may not have completed. Read what you changed before you repeat a write.

application/json
  1. response

An error response.

error*

What went wrong.

write_contention: the database was busy, and Marfa couldn't complete the request in time. Nothing changed. Try the request again. While a restore runs, details.reason is restore_running.

application/json
  1. response

An error response.

error*

What went wrong.

insufficient_storage: the disk that holds the instance's data has no room for the request, or the request would leave less free than the instance keeps in reserve. Nothing changed, unless details.write_outcome is unknown, which means the write may have landed: read what you changed before you repeat it. Free space on the disk, then try the request again.

application/json
  1. response

An error response.

error*

What went wrong.

curl -X POST 'http://localhost:8600/types' \  -H 'Content-Type: application/json' \  -d '{  "fields": {    "property1": {      "type": "string",      "property1": null,      "property2": null    },    "property2": {      "type": "string",      "property1": null,      "property2": null    }  },  "id": "string"}'
About errors
{  "id": "acme.contact",  "label": "Contact",  "version": 0,  "fields": {    "name": {      "type": "string",      "label": "Name",      "required": true    }  },  "plural": "Contacts",  "display_hints": {    "title_field": "name"  },  "provenance": {    "origin": "user",    "created_by": {      "kind": "key",      "id": "01a1011b-b5e5-7be6-8f3b-77492475b5a4",      "name": "CRM sync"    }  }}